18 changed files with 195 additions and 74 deletions
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
fos_elastica: |
||||
clients: |
||||
default: |
||||
host: '%env(ELASTICSEARCH_HOST)%' |
||||
port: '%env(int:ELASTICSEARCH_PORT)%' |
||||
username: '%env(ELASTICSEARCH_USERNAME)%' |
||||
password: '%env(ELASTICSEARCH_PASSWORD)%' |
||||
indexes: |
||||
# create the index by running php bin/console fos:elastica:populate |
||||
articles: |
||||
properties: |
||||
title: ~ |
||||
summary: ~ |
||||
content: ~ |
||||
slug: ~ |
||||
topics: ~ |
||||
persistence: |
||||
driver: orm |
||||
model: App\Entity\Article |
||||
provider: ~ |
||||
listener: ~ |
||||
finder: ~ |
||||
|
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace App\Controller; |
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||||
use Symfony\Component\HttpFoundation\Response; |
||||
use Symfony\Component\Routing\Attribute\Route; |
||||
|
||||
class SearchController extends AbstractController |
||||
{ |
||||
#[Route('/search')] |
||||
public function index(): Response |
||||
{ |
||||
return $this->render('pages/search.html.twig'); |
||||
} |
||||
} |
||||
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace App\Security; |
||||
|
||||
use App\Entity\User; |
||||
use Symfony\Component\Security\Core\User\UserInterface; |
||||
|
||||
class UserDTO implements UserInterface |
||||
{ |
||||
private User $user; |
||||
private $metadata; |
||||
private $relays; |
||||
|
||||
public function __construct(User $user, $metadata, $relays) |
||||
{ |
||||
$this->user = $user; |
||||
$this->metadata = $metadata; |
||||
$this->relays = $relays; |
||||
} |
||||
|
||||
public function getUser(): User |
||||
{ |
||||
return $this->user; |
||||
} |
||||
|
||||
public function getMetadata() |
||||
{ |
||||
return $this->metadata; |
||||
} |
||||
|
||||
public function getDisplayName() { |
||||
return $this->metadata->name; |
||||
} |
||||
|
||||
/** |
||||
* @return null|array |
||||
*/ |
||||
public function getRelays(): ?array |
||||
{ |
||||
return $this->relays; |
||||
} |
||||
|
||||
// Delegate UserInterface methods to the wrapped User entity |
||||
public function getRoles(): array |
||||
{ |
||||
return $this->user->getRoles(); |
||||
} |
||||
|
||||
public function eraseCredentials(): void |
||||
{ |
||||
$this->metadata = null; |
||||
$this->relays = null; |
||||
} |
||||
|
||||
public function getUserIdentifier(): string |
||||
{ |
||||
return $this->user->getNpub(); |
||||
} |
||||
|
||||
public function getNpub(): string { |
||||
return $this->user->getNpub(); |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
<?php |
||||
|
||||
namespace App\Twig\Components; |
||||
|
||||
use FOS\ElasticaBundle\Finder\FinderInterface; |
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; |
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp; |
||||
use Symfony\UX\LiveComponent\DefaultActionTrait; |
||||
|
||||
#[AsLiveComponent] |
||||
final class SearchComponent |
||||
{ |
||||
use DefaultActionTrait; |
||||
|
||||
#[LiveProp(writable: true)] |
||||
public string $query = ''; |
||||
|
||||
private FinderInterface $finder; |
||||
|
||||
public function __construct(FinderInterface $finder) |
||||
{ |
||||
$this->finder = $finder; |
||||
} |
||||
|
||||
public function getResults() |
||||
{ |
||||
if (empty($this->query)) { |
||||
return []; |
||||
} |
||||
$res = $this->finder->find($this->query, 10); // Limit to 10 results |
||||
return $res; // Limit to 10 results |
||||
} |
||||
|
||||
} |
||||
@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
|
||||
<span> |
||||
{% if author.display_name is defined and author.display_name is not empty %} |
||||
{{ author.display_name }} |
||||
{% elseif author.name is not empty %} |
||||
{% elseif author.name is defined and author.name is not empty %} |
||||
{{ author.name }} |
||||
{% endif %} |
||||
</span> |
||||
|
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
<div {{ attributes }}> |
||||
<label class="search"> |
||||
<input type="search" |
||||
placeholder="{{ 'text.search'|trans }}" |
||||
data-model="norender|query" |
||||
/> |
||||
<button type="submit" data-action="live#$render"><twig:ux:icon name="iconoir:search" class="icon" /></button> |
||||
</label> |
||||
|
||||
<!-- Loading Indicator --> |
||||
<span data-loading>{{ 'text.searching'|trans }}</span> |
||||
|
||||
<!-- Results --> |
||||
{% if this.results is not empty %} |
||||
<twig:Organisms:CardList :list="this.results" /> |
||||
{% elseif this.query is not empty %} |
||||
<p><small>{{ 'text.noResults'|trans }}</small></p> |
||||
{% endif %} |
||||
</div> |
||||
|
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
{% extends 'base.html.twig' %} |
||||
|
||||
{% block nav %} |
||||
{% endblock %} |
||||
|
||||
{% block body %} |
||||
<twig:SearchComponent /> |
||||
{% endblock %} |
||||
|
||||
{% block aside %} |
||||
<h6>Magazines</h6> |
||||
<twig:Organisms:ZineList /> |
||||
{% endblock %} |
||||
@ -1,8 +1,12 @@
@@ -1,8 +1,12 @@
|
||||
text: |
||||
byline: 'By' |
||||
search: 'Search...' |
||||
searching: 'Searching...' |
||||
noResults: 'No results.' |
||||
heading: |
||||
roles: 'Roles' |
||||
logout: 'Log out' |
||||
logIn: 'Log in' |
||||
createNzine: 'Create an N-Zine' |
||||
editNzine: 'Edit your N-Zine' |
||||
search: 'Search' |
||||
|
||||
Loading…
Reference in new issue