-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce override filters while searching setting (#242)
* Introduced override filters while searching setting * update branch; change strings and method names * fix eslint issue * code review changes * moved search setting types into its own type --------- Co-authored-by: akxer <>
- Loading branch information
Showing
5 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ListItem, ListItemText, Switch } from '@mui/material'; | ||
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction'; | ||
import React from 'react'; | ||
import { useSearchSettings } from 'util/searchSettings'; | ||
import { requestUpdateServerMetadata } from 'util/metadata'; | ||
import makeToast from 'components/util/Toast'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import SearchIcon from '@mui/icons-material/Search'; | ||
import { SearchMetadataKeys } from 'typings'; | ||
|
||
export default function SearchSettings() { | ||
const { metadata, settings } = useSearchSettings(); | ||
|
||
const setSettingValue = (key: SearchMetadataKeys, value: boolean) => { | ||
requestUpdateServerMetadata(metadata ?? {}, [[key, value]]).catch(() => | ||
makeToast('Failed to save the default search settings to the server', 'warning'), | ||
); | ||
}; | ||
return ( | ||
<ListItem> | ||
<ListItemIcon> | ||
<SearchIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Ignore Filters when Searching" /> | ||
<ListItemSecondaryAction> | ||
<Switch | ||
edge="end" | ||
checked={settings.ignoreFilters} | ||
onChange={(e) => setSettingValue('ignoreFilters', e.target.checked)} | ||
/> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useQuery } from 'util/client'; | ||
import { getMetadataFrom } from 'util/metadata'; | ||
import { IMetadata, ISearchSettings, MetadataKeyValuePair } from 'typings'; | ||
|
||
export const getDefaultSettings = () => | ||
({ | ||
ignoreFilters: false, | ||
} as ISearchSettings); | ||
|
||
const getSearchSettingsWithDefaultValueFallback = ( | ||
meta?: IMetadata, | ||
defaultSettings?: ISearchSettings, | ||
applyMetadataMigration: boolean = true, | ||
): ISearchSettings => ({ | ||
...(getMetadataFrom( | ||
{ meta }, | ||
Object.entries(defaultSettings ?? getDefaultSettings()) as MetadataKeyValuePair[], | ||
applyMetadataMigration, | ||
) as unknown as ISearchSettings), | ||
}); | ||
|
||
export const useSearchSettings = (): { | ||
metadata?: IMetadata; | ||
settings: ISearchSettings; | ||
loading: boolean; | ||
} => { | ||
const { data: meta, loading } = useQuery<IMetadata>('/api/v1/meta'); | ||
const settings = getSearchSettingsWithDefaultValueFallback(meta); | ||
|
||
return { metadata: meta, settings, loading }; | ||
}; |