Make chapter sort options typing more strict

This commit is contained in:
schroda
2024-06-30 14:10:49 +02:00
parent d1286c2779
commit ea102eceb6
2 changed files with 8 additions and 8 deletions

View File

@@ -80,7 +80,7 @@ export const ChapterOptions: React.FC<IProps> = ({ open, onClose, options, optio
);
}
if (key === 'sort') {
return SORT_OPTIONS.map(([mode, label]) => (
return Object.entries(SORT_OPTIONS).map(([mode, label]) => (
<SortRadioInput
key={mode}
label={t(label)}
@@ -88,7 +88,7 @@ export const ChapterOptions: React.FC<IProps> = ({ open, onClose, options, optio
sortDescending={options.reverse}
onClick={() =>
mode !== options.sortBy
? optionsDispatch({ type: 'sortBy', sortBy: mode })
? optionsDispatch({ type: 'sortBy', sortBy: mode as keyof typeof SORT_OPTIONS })
: optionsDispatch({ type: 'sortReverse' })
}
/>

View File

@@ -129,12 +129,12 @@ export const useChapterOptions = (mangaId: number) =>
defaultChapterOptions,
);
export const SORT_OPTIONS: [ChapterSortMode, TranslationKey][] = [
['source', 'global.sort.label.by_source'],
['chapterNumber', 'global.sort.label.by_chapter_number'],
['uploadedAt', 'global.sort.label.by_upload_date'],
['fetchedAt', 'global.sort.label.by_fetch_date'],
];
export const SORT_OPTIONS: Record<ChapterSortMode, TranslationKey> = {
source: 'global.sort.label.by_source',
chapterNumber: 'global.sort.label.by_chapter_number',
uploadedAt: 'global.sort.label.by_upload_date',
fetchedAt: 'global.sort.label.by_fetch_date',
};
export const isFilterActive = (options: ChapterListOptions) => {
const { unread, downloaded, bookmarked } = options;