Implement Unread Filter for Library (#54)

This commit is contained in:
Sascha Hahne
2021-10-29 20:11:23 +02:00
committed by GitHub
parent 88fb4b64b6
commit e9bdc95060
9 changed files with 378 additions and 90 deletions

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { BooleanParam, useQueryParams } from 'use-query-params';
export type NullAndUndefined<T> = T | null | undefined;
interface IUseLibraryOptions {
unread: NullAndUndefined<boolean>
setUnread: (unread: NullAndUndefined<boolean>) => void
active: boolean
}
export default function useLibraryOptions(): IUseLibraryOptions {
const [query, setQuery] = useQueryParams({
unread: BooleanParam,
});
const { unread } = query;
const setUnread = (newUnread: NullAndUndefined<boolean>) => {
setQuery(Object.assign(query, { unread: newUnread }), 'replace');
};
// eslint-disable-next-line eqeqeq
const active = !(unread == undefined);
return {
unread, setUnread, active,
};
}