|
5 | 5 | use Closure; |
6 | 6 | use Illuminate\Http\Request; |
7 | 7 | use Illuminate\Support\Str; |
| 8 | +use Reach\StatamicLivewireFilters\Support\CustomQueryString; |
8 | 9 | use Reach\StatamicLivewireFilters\Support\Nocache; |
9 | 10 |
|
10 | 11 | class HandleFiltersQueryString |
11 | 12 | { |
12 | 13 | /** |
13 | 14 | * Keys we must never overwrite when hydrating the request from the target URL's |
14 | 15 | * query string, since Statamic's nocache controller and Livewire rely on them. |
| 16 | + * Note that `params` is intentionally not reserved: it is the query key Livewire |
| 17 | + * uses to restore filter state when `enable_query_string` is on. |
15 | 18 | */ |
16 | | - protected const RESERVED_INPUT_KEYS = ['url', 'params', '_token', '_method', 'fingerprint', 'serialized', 'effects']; |
| 19 | + protected const RESERVED_INPUT_KEYS = ['url', '_token', '_method', 'fingerprint', 'serialized', 'effects']; |
17 | 20 |
|
18 | 21 | public function handle(Request $request, Closure $next): mixed |
19 | 22 | { |
@@ -42,10 +45,10 @@ public function handle(Request $request, Closure $next): mixed |
42 | 45 | } else { |
43 | 46 | $path = $request->path(); |
44 | 47 | } |
45 | | - $prefix = config('statamic-livewire-filters.custom_query_string', 'filters'); |
| 48 | + $prefix = CustomQueryString::prefix(); |
46 | 49 |
|
47 | 50 | $segments = explode('/', $path); |
48 | | - $filterIndex = array_search($prefix, $segments); |
| 51 | + $filterIndex = array_search($prefix, $segments, true); |
49 | 52 |
|
50 | 53 | if ($filterIndex !== false) { |
51 | 54 | // Extract and parse filter segments |
@@ -92,15 +95,15 @@ protected function hydrateNocacheRequestFromUrl(Request $request): void |
92 | 95 | return; |
93 | 96 | } |
94 | 97 |
|
95 | | - if (config('statamic-livewire-filters.enable_query_string') === true) { |
| 98 | + if (CustomQueryString::livewireQueryStringEnabled()) { |
96 | 99 | $this->hydrateFromOriginalQueryString($request, $parsed); |
97 | 100 |
|
98 | 101 | return; |
99 | 102 | } |
100 | 103 |
|
101 | | - $prefix = config('statamic-livewire-filters.custom_query_string', 'filters'); |
| 104 | + $prefix = CustomQueryString::prefix(); |
102 | 105 |
|
103 | | - if (! $prefix) { |
| 106 | + if ($prefix === false) { |
104 | 107 | return; |
105 | 108 | } |
106 | 109 |
|
@@ -130,7 +133,7 @@ protected function hydrateNocacheRequestFromUrl(Request $request): void |
130 | 133 | $normalized .= ':'.$parsed['port']; |
131 | 134 | } |
132 | 135 |
|
133 | | - $normalized .= $basePath === '/' ? '' : $basePath; |
| 136 | + $normalized .= $basePath === '/' ? '/' : $basePath; |
134 | 137 |
|
135 | 138 | if (! empty($parsed['query'])) { |
136 | 139 | $normalized .= '?'.$parsed['query']; |
@@ -166,7 +169,7 @@ protected function hydrateFromOriginalQueryString(Request $request, array $parse |
166 | 169 |
|
167 | 170 | protected function shouldSkip(): bool |
168 | 171 | { |
169 | | - return config('statamic-livewire-filters.custom_query_string') === false || config('statamic-livewire-filters.enable_query_string') === true; |
| 172 | + return ! CustomQueryString::enabled(); |
170 | 173 | } |
171 | 174 |
|
172 | 175 | protected function shouldProcessRequest(Request $request): bool |
|
0 commit comments