diff --git a/assets/controllers/share_dropdown_controller.js b/assets/controllers/share_dropdown_controller.js new file mode 100644 index 0000000..60ff2f3 --- /dev/null +++ b/assets/controllers/share_dropdown_controller.js @@ -0,0 +1,33 @@ +// assets/controllers/share_dropdown_controller.js +import { Controller } from '@hotwired/stimulus'; + +export default class extends Controller { + static targets = ['menu', 'button']; + + connect() { + document.addEventListener('click', this.closeMenu); + } + + disconnect() { + document.removeEventListener('click', this.closeMenu); + } + + toggle(event) { + event.stopPropagation(); + this.menuTarget.style.display = this.menuTarget.style.display === 'block' ? 'none' : 'block'; + } + + closeMenu = () => { + this.menuTarget.style.display = 'none'; + } + + copy(event) { + const el = event.currentTarget; + const text = el.dataset.copy; + navigator.clipboard.writeText(text).then(() => { + const orig = el.innerHTML; + el.innerHTML = 'Copied!'; + setTimeout(() => { el.innerHTML = orig; }, 1200); + }); + } +} diff --git a/assets/styles/03-components/image-upload.css b/assets/styles/03-components/image-upload.css index 3123cb5..79a0abb 100644 --- a/assets/styles/03-components/image-upload.css +++ b/assets/styles/03-components/image-upload.css @@ -23,7 +23,6 @@ left: 50%; transform: translate(-50%, -50%); background-color: var(--color-bg, #fff); - border-radius: 0.5rem; box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.3); max-width: 90%; width: 500px; diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 556fb22..e4b4db8 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -3,7 +3,6 @@ twig: globals: project_npub: 'npub1ez09adke4vy8udk3y2skwst8q5chjgqzym9lpq4u58zf96zcl7kqyry2lz' dev_npub: 'npub1636uujeewag8zv8593lcvdrwlymgqre6uax4anuq3y5qehqey05sl8qpl4' - feature_flag_share_btn: false mercure_public_hub_url: '%mercure_public_hub_url%' when@test: diff --git a/src/Controller/ArticleController.php b/src/Controller/ArticleController.php index ff33523..d97e626 100644 --- a/src/Controller/ArticleController.php +++ b/src/Controller/ArticleController.php @@ -160,11 +160,19 @@ class ArticleController extends AbstractController $article = array_shift($articles); } - if ($article->getPubkey() === null) { - $user = $this->getUser(); + $recentArticles = []; + $drafts = []; + + $user = $this->getUser(); + if (!!$user) { $key = new Key(); - if (!!$user) { - $currentPubkey = $key->convertToHex($user->getUserIdentifier()); + $currentPubkey = $key->convertToHex($user->getUserIdentifier()); + $recentArticles = $entityManager->getRepository(Article::class) + ->findBy(['pubkey' => $currentPubkey, 'kind' => KindsEnum::LONGFORM], ['createdAt' => 'DESC'], 5); + $drafts = $entityManager->getRepository(Article::class) + ->findBy(['pubkey' => $currentPubkey, 'kind' => KindsEnum::LONGFORM_DRAFT], ['createdAt' => 'DESC'], 5); + + if ($article->getPubkey() === null) { $article->setPubkey($currentPubkey); } } @@ -176,6 +184,8 @@ class ArticleController extends AbstractController return $this->render('pages/editor.html.twig', [ 'article' => $article, 'form' => $form->createView(), + 'recentArticles' => $recentArticles, + 'drafts' => $drafts, ]); } diff --git a/src/Entity/Article.php b/src/Entity/Article.php index 8a6889f..27e2a4a 100644 --- a/src/Entity/Article.php +++ b/src/Entity/Article.php @@ -328,7 +328,7 @@ class Article return $this->eventStatus === EventStatusEnum::PREVIEW; } - public function getRaw() + public function getRaw(): ?array { return $this->raw; } diff --git a/src/Twig/Filters.php b/src/Twig/Filters.php index 8f653a4..d0d229a 100644 --- a/src/Twig/Filters.php +++ b/src/Twig/Filters.php @@ -4,8 +4,16 @@ declare(strict_types=1); namespace App\Twig; +use App\Entity\Article; +use App\Entity\Event as EventEntity; use BitWasp\Bech32\Exception\Bech32Exception; +use Exception; +use swentel\nostr\Event\Event; use swentel\nostr\Nip19\Nip19Helper; +use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; +use Symfony\Component\Serializer\Serializer; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; @@ -18,6 +26,7 @@ class Filters extends AbstractExtension new TwigFilter('linkify', [$this, 'linkify'], ['is_safe' => ['html']]), new TwigFilter('mentionify', [$this, 'mentionify'], ['is_safe' => ['html']]), new TwigFilter('nEncode', [$this, 'nEncode']), + new TwigFilter('naddrEncode', [$this, 'naddrEncode']), ]; } @@ -71,4 +80,19 @@ class Filters extends AbstractExtension return $eventId; // Return original if encoding fails } } + + /** + * @throws Bech32Exception + * @throws Exception + */ + public function naddrEncode(Article $article): string + { + $nip19 = new Nip19Helper(); + if ($article->getRaw() !== null) { + $event = Event::fromVerified((object)$article->getRaw() ?? ''); + return $nip19->encodeAddr($event, $article->getSlug(), $article->getKind()->value); + } else { + return $nip19->encodeNote($article->getEventId()); + } + } } diff --git a/templates/feedback/form.html.twig b/templates/feedback/form.html.twig index 78386e3..5bd1e03 100644 --- a/templates/feedback/form.html.twig +++ b/templates/feedback/form.html.twig @@ -3,7 +3,7 @@ {% block body %}