Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 20240218-protect-search
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Feb 18, 2024
2 parents 7a9d532 + f3a9eaf commit cd0777f
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 484 deletions.
10 changes: 7 additions & 3 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index(): View
]);
}

public function post(SearchRequest $request): View
public function post(SearchRequest $request): View|string
{
$term = $request->input('term');

Expand All @@ -35,11 +35,15 @@ public function post(SearchRequest $request): View
? Cache::remember('user-favorites-' . auth()->id(), 604800, fn () => UserViewModel::favorites())
: collect();

return view('search.index', [
$data = [
'stats' => $stats,
'names' => $names,
'term' => $term,
'favorites' => $favoritedNamesForLoggedUser,
]);
];

return $request->isHtmxRequest()
? view()->renderFragment('search.index', 'content', $data)
: view('search.index', $data);
}
}
8 changes: 8 additions & 0 deletions app/Http/Requests/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

class SearchRequest extends FormRequest
{
/**
* Indicates that the request is made via Htmx.
*/
public function isHtmxRequest(): bool
{
return filter_var($this->headers->get('HX-Request', 'false'), FILTER_VALIDATE_BOOLEAN);
}

/**
* Determine if the user is authorized to make this request.
*/
Expand Down
4 changes: 3 additions & 1 deletion resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
</head>

<body class="font-sans text-gray-900 antialiased">
<div class="flex min-h-screen flex-col">
@fragment('page')
<div class="flex min-h-screen flex-col" id="page">
{{ $slot }}
</div>
@endfragment

<div class="bg-violet-100 border-t border-violet-200">
@include('layouts.footer')
Expand Down
57 changes: 1 addition & 56 deletions resources/views/names/female/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,56 +1 @@
<x-guest-layout>
<div class="bg-violet-100 mb-8">
<div class="border-b border-violet-200">
@include('layouts.unlogged-navigation')
</div>

<div class="border-b border-violet-200">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<ul class="text-xs">
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a>
</li>
<li class="inline">Tous les prénoms féminins</li>
</ul>
</div>
</div>
</div>

<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<div class="grid name-index-grid gap-4">

<!-- left -->
<div>
@include('names.partials.sidebar')
</div>

<!-- right -->
<div>

<!-- list of letters -->
<div class="grid grid-cols-12 gap-y-2 gap-2 mb-12">
@foreach ($letters as $letter)
<a href="{{ $letter['url'] }}" class="flex flex-col rounded-lg px-2 py-1 border hover:bg-violet-100">
<div>{{ $letter['letter'] }}</div>
<div class="text-xs text-gray-600">{{ $letter['count'] }}</div>
</a>
@endforeach
</div>

<!-- names -->
<h2 class="mb-8 font-bold text-xl text-center">Tous les prénoms féminins</h2>
<div class="grid grid-cols-3 gap-10 gap-y-1 mb-10" x-data="{ last_name: '{{ auth()->check() ? auth()->user()->last_name : "" }}' }">
@foreach ($names as $name)
<x-name-items :name="$name" favorited="{{ $favorites->contains($name['id']) }}" />
@endforeach
</div>

<div class="flex justify-center">
{{ $namesPagination->onEachSide(2)->links('vendor.pagination.tailwind') }}
</div>
</div>
</div>
</div>
</div>
</x-guest-layout>
@include('names.partials.index', ['title' => 'Tous les prénoms féminins'])
62 changes: 1 addition & 61 deletions resources/views/names/female/letter.blade.php
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
<x-guest-layout>
<div class="bg-violet-100 mb-8">
<div class="border-b border-violet-200">
@include('layouts.unlogged-navigation')
</div>

<div class="border-b border-violet-200">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<ul class="text-xs">
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a>
</li>
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a href="{{ route('name.index') }}" class="text-violet-900 underline">Tous les prénoms</a>
</li>
<li class="inline">Tous les prénoms féminins commençant par la lettre {{ $activeLetter }}</li>
</ul>
</div>
</div>
</div>

<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<div class="grid name-index-grid gap-4">

<!-- left -->
<div>
@include('names.partials.sidebar')
</div>

<!-- right -->
<div>

<!-- list of letters -->
<div class="grid grid-cols-12 gap-y-2 gap-2 mb-12">
@foreach ($letters as $letter)
<a href="{{ $letter['url'] }}" class="flex flex-col rounded-lg px-2 py-1 border hover:bg-violet-100 {{ $activeLetter === $letter['letter'] ? 'bg-violet-100' : '' }}">
<div>{{ $letter['letter'] }}</div>
<div class="text-xs text-gray-600">{{ $letter['count'] }}</div>
</a>
@endforeach
</div>

<!-- names -->
<h2 class="mb-2 font-bold text-xl text-center">Tous les prénoms féminins commençant par la lettre {{ $activeLetter }}</h2>
<p class="text-gray-600 mb-8 text-center">Les prénoms sont triés par popularité.</p>

<div class="grid grid-cols-4 gap-10 gap-y-1 mb-10">
@foreach ($names as $name)
<x-name-items :name="$name" favorited="{{ $favorites->contains($name['id']) }}" />
@endforeach
</div>

<div class="flex justify-center">
{{ $namesPagination->onEachSide(2)->links('vendor.pagination.tailwind') }}
</div>
</div>
</div>
</div>
</div>
</x-guest-layout>
@include('names.partials.letter', ['title' => "Tous les prénoms féminins commençant par la lettre $activeLetter"])
56 changes: 1 addition & 55 deletions resources/views/names/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,55 +1 @@
<x-guest-layout>
<div class="bg-violet-100 mb-8">
<div class="border-b border-violet-200">
@include('layouts.unlogged-navigation')
</div>

<div class="border-b border-violet-200">
<div class="mx-auto max-w-7xl px-2 sm:px-6 lg:px-8 py-2">
<ul class="text-xs">
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a hx-boost="true" href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a>
</li>
<li class="inline">Tous les prénoms</li>
</ul>
</div>
</div>
</div>

<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<div class="grid name-index-grid gap-4">

<!-- left -->
<div>
@include('names.partials.sidebar')
</div>

<!-- right -->
<div class="sm:px-0 px-2">

<!-- list of letters -->
<div class="grid grid-cols-6 sm:grid-cols-12 gap-y-2 gap-2 mb-12">
@foreach ($letters as $letter)
<a href="{{ $letter['url'] }}" class="flex flex-col rounded-lg px-2 py-1 border hover:bg-violet-100">
<div>{{ $letter['letter'] }}</div>
<div class="text-xs text-gray-600">{{ $letter['count'] }}</div>
</a>
@endforeach
</div>

<!-- names -->
<div class="grid grid-cols-2 sm:grid-cols-3 gap-10 gap-y-1 mb-10" x-data="{ last_name: '{{ auth()->check() ? auth()->user()->last_name : "" }}' }">
@foreach ($names as $name)
<x-name-items :name="$name" favorited="{{ $favorites->contains($name['id']) }}" />
@endforeach
</div>

<div class="flex justify-center mb-10">
{{ $namesPagination->onEachSide(2)->links('vendor.pagination.tailwind') }}
</div>
</div>
</div>
</div>
</div>
</x-guest-layout>
@include('names.partials.index', ['title' => 'Tous les prénoms', 'noTitle' => true])
62 changes: 1 addition & 61 deletions resources/views/names/letter.blade.php
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
<x-guest-layout>
<div class="bg-violet-100 mb-8">
<div class="border-b border-violet-200">
@include('layouts.unlogged-navigation')
</div>

<div class="border-b border-violet-200">
<div class="mx-auto max-w-7xl px-2 sm:px-6 lg:px-8 py-2">
<ul class="text-xs">
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a hx-boost="true" href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a>
</li>
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a hx-boost="true" href="{{ route('name.index') }}" class="text-violet-900 underline">Tous les prénoms</a>
</li>
<li class="inline">Tous les prénoms commençant par la lettre {{ $activeLetter }}</li>
</ul>
</div>
</div>
</div>

<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<div class="grid name-index-grid gap-4">

<!-- left -->
<div>
@include('names.partials.sidebar')
</div>

<!-- right -->
<div class="sm:px-0 px-2">

<!-- list of letters -->
<div class="grid grid-cols-6 sm:grid-cols-12 gap-y-2 gap-2 mb-12">
@foreach ($letters as $letter)
<a hx-boost="true" href="{{ $letter['url'] }}" class="flex flex-col rounded-lg px-2 py-1 border hover:bg-violet-100 {{ $activeLetter === $letter['letter'] ? 'bg-violet-100' : '' }}">
<div>{{ $letter['letter'] }}</div>
<div class="text-xs text-gray-600">{{ $letter['count'] }}</div>
</a>
@endforeach
</div>

<!-- names -->
<h2 class="mb-2 font-bold text-xl text-center">Tous les prénoms commençant par la lettre {{ $activeLetter }}</h2>
<p class="text-gray-600 mb-8 text-center">Les prénoms sont triés par popularité.</p>

<div class="grid grid-cols-2 sm:grid-cols-3 gap-10 gap-y-1 mb-10" x-data="{ last_name: '{{ auth()->check() ? auth()->user()->last_name : "" }}' }">
@foreach ($names as $name)
<x-name-items :name="$name" favorited="{{ $favorites->contains($name['id']) }}" />
@endforeach
</div>

<div class="flex justify-center">
{{ $namesPagination->onEachSide(2)->links('vendor.pagination.tailwind') }}
</div>
</div>
</div>
</div>
</div>
</x-guest-layout>
@include('names.partials.letter', ['title' => "Tous les prénoms commençant par la lettre $activeLetter"])
57 changes: 1 addition & 56 deletions resources/views/names/male/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,56 +1 @@
<x-guest-layout>
<div class="bg-violet-100 mb-8">
<div class="border-b border-violet-200">
@include('layouts.unlogged-navigation')
</div>

<div class="border-b border-violet-200">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<ul class="text-xs">
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs">
<a href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a>
</li>
<li class="inline">Tous les prénoms masculins</li>
</ul>
</div>
</div>
</div>

<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2">
<div class="grid name-index-grid gap-4">

<!-- left -->
<div>
@include('names.partials.sidebar')
</div>

<!-- right -->
<div>

<!-- list of letters -->
<div class="grid grid-cols-12 gap-y-2 gap-2 mb-12">
@foreach ($letters as $letter)
<a href="{{ $letter['url'] }}" class="flex flex-col rounded-lg px-2 py-1 border hover:bg-violet-100">
<div>{{ $letter['letter'] }}</div>
<div class="text-xs text-gray-600">{{ $letter['count'] }}</div>
</a>
@endforeach
</div>

<!-- names -->
<h2 class="mb-8 font-bold text-xl text-center">Tous les prénoms masculins</h2>
<div class="grid grid-cols-3 gap-10 gap-y-1 mb-10" x-data="{ last_name: '{{ auth()->check() ? auth()->user()->last_name : "" }}' }">
@foreach ($names as $name)
<x-name-items :name="$name" favorited="{{ $favorites->contains($name['id']) }}" />
@endforeach
</div>

<div class="flex justify-center">
{{ $namesPagination->onEachSide(2)->links('vendor.pagination.tailwind') }}
</div>
</div>
</div>
</div>
</div>
</x-guest-layout>
@include('names.partials.index', ['title' => 'Tous les prénoms masculins'])
Loading

0 comments on commit cd0777f

Please sign in to comment.