2021-10-29 20:11:23 +02:00
|
|
|
/*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-19 16:36:02 +03:30
|
|
|
import { BooleanParam, useQueryParam, StringParam } from 'use-query-params';
|
2021-10-29 20:11:23 +02:00
|
|
|
|
|
|
|
|
interface IUseLibraryOptions {
|
2021-11-07 15:59:48 +05:30
|
|
|
downloaded: NullAndUndefined<boolean>
|
|
|
|
|
setDownloaded: (downloaded: NullAndUndefined<boolean>)=>void
|
2021-10-29 20:11:23 +02:00
|
|
|
unread: NullAndUndefined<boolean>
|
|
|
|
|
setUnread: (unread: NullAndUndefined<boolean>) => void
|
2021-10-31 12:45:34 +01:00
|
|
|
query: NullAndUndefined<string>
|
|
|
|
|
setQuery: (query: NullAndUndefined<string>) => void
|
2021-10-29 20:11:23 +02:00
|
|
|
active: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function useLibraryOptions(): IUseLibraryOptions {
|
2021-11-19 16:36:02 +03:30
|
|
|
const [downloaded, setDownloaded] = useQueryParam('downloaded', BooleanParam);
|
|
|
|
|
const [unread, setUnread] = useQueryParam('unread', BooleanParam);
|
|
|
|
|
const [query, setQuery] = useQueryParam('query', StringParam);
|
|
|
|
|
|
2021-10-29 20:11:23 +02:00
|
|
|
// eslint-disable-next-line eqeqeq
|
2021-11-07 15:59:48 +05:30
|
|
|
const active = !(unread == undefined) || !(downloaded == undefined);
|
2021-10-29 20:11:23 +02:00
|
|
|
return {
|
2021-11-19 16:36:02 +03:30
|
|
|
downloaded, setDownloaded, unread, setUnread, query, setQuery, active,
|
2021-10-29 20:11:23 +02:00
|
|
|
};
|
|
|
|
|
}
|