| | |
| | | type AppsQuery = { |
| | | tagIDs?: string[] |
| | | keywords?: string |
| | | isCreatedByMe?: boolean |
| | | } |
| | | |
| | | // Parse the query parameters from the URL search string. |
| | | function parseParams(params: ReadonlyURLSearchParams): AppsQuery { |
| | | const tagIDs = params.get('tagIDs')?.split(';') |
| | | const keywords = params.get('keywords') || undefined |
| | | const isCreatedByMe = params.get('isCreatedByMe') === 'true' |
| | | return { tagIDs, keywords, isCreatedByMe } |
| | | return { tagIDs, keywords } |
| | | } |
| | | |
| | | // Update the URL search string with the given query parameters. |
| | | function updateSearchParams(query: AppsQuery, current: URLSearchParams) { |
| | | const { tagIDs, keywords, isCreatedByMe } = query || {} |
| | | const { tagIDs, keywords } = query || {} |
| | | |
| | | if (tagIDs && tagIDs.length > 0) |
| | | current.set('tagIDs', tagIDs.join(';')) |
| | |
| | | current.set('keywords', keywords) |
| | | else |
| | | current.delete('keywords') |
| | | |
| | | if (isCreatedByMe) |
| | | current.set('isCreatedByMe', 'true') |
| | | else |
| | | current.delete('isCreatedByMe') |
| | | } |
| | | |
| | | function useAppsQueryState() { |