From 2929d4ab159ae5f0b336f3aa2fe6a9a15217439a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Sat, 15 Mar 2025 17:05:30 +0100 Subject: [PATCH] Search and miscelanea --- config/packages/security.yaml | 3 +- src/Controller/NzineController.php | 9 +++++- src/Service/NostrClient.php | 2 +- src/Twig/Components/IndexTabs.php | 20 +++++++------ .../components/SearchComponent.html.twig | 4 ++- templates/components/UserMenu.html.twig | 29 ++++++++++--------- templates/home.html.twig | 4 +-- templates/pages/author.html.twig | 2 +- templates/pages/nzine.html.twig | 3 +- templates/pages/search.html.twig | 4 +-- translations/messages.en.yaml | 1 + 11 files changed, 47 insertions(+), 34 deletions(-) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index e65f640..906bf00 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -26,5 +26,6 @@ security: # Note: Only the *first* access control that matches will be used access_control: - { path: ^/admin, roles: ROLE_USER } - - { path: ^/nzine, roles: ROLE_USER } + - { path: ^/search, roles: ROLE_USER } + # - { path: ^/nzine, roles: ROLE_USER } # - { path: ^/profile, roles: ROLE_USER } diff --git a/src/Controller/NzineController.php b/src/Controller/NzineController.php index 3aeb27f..370b5dc 100644 --- a/src/Controller/NzineController.php +++ b/src/Controller/NzineController.php @@ -154,7 +154,12 @@ class NzineController extends AbstractController // add the new and updated indices to the main index foreach ($catIndices as $idx) { - $mainIndex->addTag(['e' => $idx->getId() ]); + //remove e tags and add new + // $tags = array_splice($mainIndex->getTags(), -3); + // $mainIndex->setTags($tags); + // TODO add relay hints + $mainIndex->addTag(['a' => KindsEnum::PUBLICATION_INDEX->value .':'. $idx->getPublicKey() .':'. $idx->getSlug()]); + // $mainIndex->addTag(['e' => $idx->getId() ]); } // re-sign main index and save to relays @@ -204,6 +209,8 @@ class NzineController extends AbstractController return $index->getSlug() == $nzine->getSlug(); }); + dump($indices);die(); + $mainIndex = array_pop($mainIndexCandidates); return $this->render('pages/nzine.html.twig', [ diff --git a/src/Service/NostrClient.php b/src/Service/NostrClient.php index a8925bc..ec52ea5 100644 --- a/src/Service/NostrClient.php +++ b/src/Service/NostrClient.php @@ -176,7 +176,7 @@ class NostrClient $filter = new Filter(); $filter->setKinds([KindsEnum::LONGFORM]); // TODO make filters configurable - $filter->setSince(strtotime('-8 weeks')); // + $filter->setSince(strtotime('-1 week')); // $requestMessage = new RequestMessage($subscriptionId, [$filter]); // if user is logged in, use their settings diff --git a/src/Twig/Components/IndexTabs.php b/src/Twig/Components/IndexTabs.php index 3b88cbd..a9f6cce 100644 --- a/src/Twig/Components/IndexTabs.php +++ b/src/Twig/Components/IndexTabs.php @@ -20,7 +20,7 @@ class IndexTabs public int $activeTab = 1; // Default active tab #[LiveProp] - /** ['id' => 1, 'label' => 'Tab 1'] */ + /** ['id' => 1, 'label' => 'Tab 1', 'i' => ] */ public array $tabs = []; #[LiveAction] @@ -39,24 +39,26 @@ class IndexTabs // TODO extract categories from index and feed into tabs foreach ($index->getTags() as $tag) { if (array_key_first($tag) === 'a') { - $ref = $tag['a']; + $ref = $tag[1]; + $relayHint = $tag[2] ?? null; list($kind,$npub,$slug) = explode(':',$ref); $cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['slug' => $slug]); - } elseif (array_key_first($tag) === 'e') { - $cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['id' => $tag['e']]); $next = count($this->tabs) + 1; - $this->tabs[] = ['id' => $next, 'label' => $cat->getTitle()]; + $this->tabs[] = ['id' => $next, 'label' => $cat->getTitle(), 'i' => $cat]; + } elseif (array_key_first($tag) === 'e') { + // ignore 'e's, we want 'a's + //$cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['id' => $tag[1]]); + //$next = count($this->tabs) + 1; + //$this->tabs[] = ['id' => $next, 'label' => $cat->getTitle()]; } } } public function getTabContent(): string|array { + // return current index return match ($this->activeTab) { - 1 => [ - '30023:c1e6505c02da8d1b0a5b3d6db6e19b2eb22dcd54f0e86306ec8a213902b3157e:809797', - '30032:c1e6505c02da8d1b0a5b3d6db6e19b2eb22dcd54f0e86306ec8a213902b3157e:012025-7zsaxt' - ], + 1 => 'This will eventually be content.', 2 => 'This is content for Tab 2. No AJAX needed!', default => 'No content available.', }; diff --git a/templates/components/SearchComponent.html.twig b/templates/components/SearchComponent.html.twig index bd389c6..3eac378 100644 --- a/templates/components/SearchComponent.html.twig +++ b/templates/components/SearchComponent.html.twig @@ -8,7 +8,9 @@ - {{ 'text.searching'|trans }} +
+ {{ 'text.searching'|trans }} +
{% if this.results is not empty %} diff --git a/templates/components/UserMenu.html.twig b/templates/components/UserMenu.html.twig index 6db3c75..1d99adf 100644 --- a/templates/components/UserMenu.html.twig +++ b/templates/components/UserMenu.html.twig @@ -2,22 +2,28 @@ {% if app.user %}

Hello, {{ app.user.displayName }}

{% if is_granted('ROLE_ADMIN') %} - +{# #} {% endif %}