@@ -6,6 +6,8 @@ import React, {
66 useState ,
77} from 'react' ;
88
9+ import { SEARCH_OPTION_KEYS } from '~/modules/search/constants' ;
10+
911export type Location = {
1012 push ( location : string | Partial < Location > ) : void ;
1113 replace ( location : string | Partial < Location > ) : void ;
@@ -20,11 +22,12 @@ export type Location = {
2022 search : string | null ;
2123 status : string | null ;
2224 extra : string | null ;
23- search_identifiers : boolean ;
24- search_exclude_source_strings : boolean ;
25- search_rejected_translations : boolean ;
26- search_match_case : boolean ;
27- search_match_whole_word : boolean ;
25+ /** undefined = not provided in the URL, use default or profile setting instead */
26+ search_identifiers : boolean | undefined ;
27+ search_exclude_source_strings : boolean | undefined ;
28+ search_rejected_translations : boolean | undefined ;
29+ search_match_case : boolean | undefined ;
30+ search_match_whole_word : boolean | undefined ;
2831 tag : string | null ;
2932 author : string | null ;
3033 time : string | null ;
@@ -38,11 +41,11 @@ const emptyParams = {
3841 search : null ,
3942 status : null ,
4043 extra : null ,
41- search_identifiers : false ,
42- search_exclude_source_strings : false ,
43- search_rejected_translations : false ,
44- search_match_case : false ,
45- search_match_whole_word : false ,
44+ search_identifiers : undefined ,
45+ search_exclude_source_strings : undefined ,
46+ search_rejected_translations : undefined ,
47+ search_match_case : undefined ,
48+ search_match_whole_word : undefined ,
4649 tag : null ,
4750 author : null ,
4851 time : null ,
@@ -78,6 +81,14 @@ export function LocationProvider({
7881 return < Location . Provider value = { state } > { children } </ Location . Provider > ;
7982}
8083
84+ function getSearchParam (
85+ params : URLSearchParams ,
86+ key : string ,
87+ ) : boolean | undefined {
88+ const val = params . get ( key ) ;
89+ return val !== null ? val !== 'false' : undefined ;
90+ }
91+
8192function parse (
8293 history : History . History ,
8394 { pathname, search } : History . Location ,
@@ -107,15 +118,20 @@ function parse(
107118 search : params . get ( 'search' ) ,
108119 status : params . get ( 'status' ) ,
109120 extra : params . get ( 'extra' ) ,
110- search_identifiers : params . has ( 'search_identifiers' ) ,
111- search_exclude_source_strings : params . has (
121+ search_identifiers : getSearchParam ( params , 'search_identifiers' ) ,
122+ search_exclude_source_strings : getSearchParam (
123+ params ,
112124 'search_exclude_source_strings' ,
113125 ) ,
114- search_rejected_translations : params . has (
126+ search_rejected_translations : getSearchParam (
127+ params ,
115128 'search_rejected_translations' ,
116129 ) ,
117- search_match_case : params . has ( 'search_match_case' ) ,
118- search_match_whole_word : params . has ( 'search_match_whole_word' ) ,
130+ search_match_case : getSearchParam ( params , 'search_match_case' ) ,
131+ search_match_whole_word : getSearchParam (
132+ params ,
133+ 'search_match_whole_word' ,
134+ ) ,
119135 tag : params . get ( 'tag' ) ,
120136 author : params . get ( 'author' ) ,
121137 time : params . get ( 'time' ) ,
@@ -143,15 +159,17 @@ function stringify(prev: Location, next: string | Partial<Location>) {
143159 } else if ( prev . list && ! ( 'list' in next ) ) {
144160 params . set ( 'list' , prev . list . join ( ',' ) ) ;
145161 }
162+ // Encode explicit search option values (omit undefined).
163+ for ( const key of SEARCH_OPTION_KEYS ) {
164+ const value = key in next ? next [ key ] : prev [ key ] ;
165+ if ( value !== undefined ) {
166+ params . set ( key , String ( value ) ) ;
167+ }
168+ }
146169 for ( const key of [
147170 'search' ,
148171 'status' ,
149172 'extra' ,
150- 'search_identifiers' ,
151- 'search_exclude_source_strings' ,
152- 'search_rejected_translations' ,
153- 'search_match_case' ,
154- 'search_match_whole_word' ,
155173 'tag' ,
156174 'author' ,
157175 'time' ,
0 commit comments