diff --git a/app/Livewire/GlobalSearch.php b/app/Livewire/GlobalSearch.php index 46dabd7..9e0ea0c 100644 --- a/app/Livewire/GlobalSearch.php +++ b/app/Livewire/GlobalSearch.php @@ -7,6 +7,7 @@ use App\Models\User; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Illuminate\View\View; +use Livewire\Attributes\Locked; use Livewire\Component; class GlobalSearch extends Component @@ -17,20 +18,26 @@ class GlobalSearch extends Component public string $query = ''; /** - * Whether to show the search result dropdown. + * The search results. */ - public bool $showDropdown = false; + #[Locked] + public array $result = []; /** - * Whether to show the "no results found" message. + * The total number of search results. */ - public bool $noResults = false; + #[Locked] + public int $count = 0; + /** + * Render the component. + */ public function render(): View { - return view('livewire.global-search', [ - 'results' => $this->executeSearch($this->query), - ]); + $this->result = $this->executeSearch($this->query); + $this->count = $this->countTotalResults($this->result); + + return view('livewire.global-search'); } /** @@ -39,19 +46,15 @@ class GlobalSearch extends Component protected function executeSearch(string $query): array { $query = Str::trim($query); - $results = ['data' => [], 'total' => 0]; if (Str::length($query) > 0) { - $results['data'] = [ + return [ 'user' => $this->fetchUserResults($query), 'mod' => $this->fetchModResults($query), ]; - $results['total'] = $this->countTotalResults($results['data']); } - $this->noResults = $results['total'] === 0; - - return $results; + return []; } /** @@ -59,10 +62,7 @@ class GlobalSearch extends Component */ protected function fetchUserResults(string $query): Collection { - /** @var array> $userHits */ - $userHits = User::search($query)->raw()['hits']; - - return collect($userHits); + return collect(User::search($query)->raw()['hits']); } /** @@ -70,10 +70,7 @@ class GlobalSearch extends Component */ protected function fetchModResults(string $query): Collection { - /** @var array> $modHits */ - $modHits = Mod::search($query)->raw()['hits']; - - return collect($modHits); + return collect(Mod::search($query)->raw()['hits']); } /** diff --git a/app/Models/User.php b/app/Models/User.php index 7182f42..4c268c4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -127,7 +127,7 @@ class User extends Authenticatable implements MustVerifyEmail */ public function shouldBeSearchable(): bool { - return ! is_null($this->email_verified_at); + return $this->isNotBanned(); } /** diff --git a/resources/views/components/global-search-result-mod.blade.php b/resources/views/components/global-search-result-mod.blade.php index e8dd449..3bbbfea 100644 --- a/resources/views/components/global-search-result-mod.blade.php +++ b/resources/views/components/global-search-result-mod.blade.php @@ -1,10 +1,9 @@ - @if(empty($result->thumbnail)) - {{ $result['name'] }} - + @empty ($result['thumbnail']) + {{ $result['name'] }} @else {{ $result['name'] }} - @endif + @endempty

{{ $result['name'] }}

{{ $result['latestVersion'] }} diff --git a/resources/views/components/global-search-results.blade.php b/resources/views/components/global-search-results.blade.php deleted file mode 100644 index 12f08b3..0000000 --- a/resources/views/components/global-search-results.blade.php +++ /dev/null @@ -1,40 +0,0 @@ -

- @if ($showDropdown) -

{{ __('Search Results') }}

-
- @foreach($results['data'] as $typeName => $typeResults) - @if($typeResults->count()) -

- {{ Str::plural($typeName) }} - - - -

-
- @foreach($typeResults as $result) - @component('components.global-search-result-' . Str::lower($typeName), [ - 'result' => $result, - 'linkClass' => 'group/global-search-link flex flex-row gap-3 py-1.5 px-4 text-gray-900 dark:text-gray-100 hover:bg-gray-200 dark:hover:bg-gray-800 transition-colors duration-200 ease-in-out', - ]) - @endcomponent - @endforeach -
- @endif - @endforeach -
- @endif - @if($noResults) -
- -

{{ __("We couldn't find any content with that query. Please try again.") }}

-
- @endif -
diff --git a/resources/views/livewire/global-search.blade.php b/resources/views/livewire/global-search.blade.php index e9fcd90..2a0e38a 100644 --- a/resources/views/livewire/global-search.blade.php +++ b/resources/views/livewire/global-search.blade.php @@ -1,15 +1,18 @@ -
-
+
- +
+
+

{{ __('Search Results') }}

+
+ @foreach($result as $type => $results) + @if ($results->count()) +

+ {{ Str::plural($type) }} + + + +

+
+ @foreach($results as $hit) + @component('components.global-search-result-' . Str::lower($type), [ + 'result' => $hit, + 'linkClass' => 'group/global-search-link flex flex-row gap-3 py-1.5 px-4 text-gray-900 dark:text-gray-100 hover:bg-gray-200 dark:hover:bg-gray-800 transition-colors duration-200 ease-in-out', + ]) + @endcomponent + @endforeach +
+ @endif + @endforeach +
+
+
+ +

{{ __("We couldn't find any content with that query. Please try again.") }}

+
+