-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced override filters while searching setting #242
Changes from 1 commit
a57b46b
58c401d
fddf916
e60f30b
00c7780
5e4b3d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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'; | ||
|
||
export default function SearchSettings() { | ||
const { metadata, settings } = useSearchSettings(); | ||
|
||
const setSettingValue = (key: keyof ISearchSettings, value: boolean) => { | ||
requestUpdateServerMetadata(metadata ?? {}, [[key, value]]).catch(() => | ||
makeToast('Failed to save the default reader settings to the server', 'warning'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot to update the error message (still says reader settings) |
||
); | ||
}; | ||
return ( | ||
<ListItem> | ||
<ListItemIcon> | ||
<SearchIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Override Filters when Searching" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think about something like "Ignore filters while searching"? I feel like that is easier to understand then "Override" |
||
<ListItemSecondaryAction> | ||
<Switch | ||
edge="end" | ||
checked={settings.overrideFilters} | ||
onChange={(e) => setSettingValue('overrideFilters', e.target.checked)} | ||
/> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useQuery } from 'util/client'; | ||
import { getMetadataFrom } from 'util/metadata'; | ||
|
||
export const getDefaultSettings = () => | ||
({ | ||
overrideFilters: false, | ||
} as ISearchSettings); | ||
|
||
const getReaderSettingsWithDefaultValueFallback = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as for the error message, name inlcudes "ReaderSettings" |
||
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 = getReaderSettingsWithDefaultValueFallback(meta); | ||
|
||
return { metadata: meta, settings, loading }; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "ignoreFilters" would be better fitting over all.
"overrideFilters" sounds to me like the filters will get replaced with different ones, while they are just ignored if the flag is set to true