Add rescan button on admin interface

This commit is contained in:
Zoe Roux 2024-05-02 01:23:06 +02:00
parent 3521d577c1
commit efd2ac179d
No known key found for this signature in database
4 changed files with 28 additions and 3 deletions

View File

@ -18,24 +18,44 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>. * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Issue, IssueP, QueryIdentifier, useFetch } from "@kyoo/models"; import { Issue, IssueP, QueryIdentifier, queryFn, useFetch } from "@kyoo/models";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { SettingsContainer } from "../settings/base"; import { SettingsContainer } from "../settings/base";
import { Icon, P, Skeleton, tooltip, ts } from "@kyoo/primitives"; import { Button, Icon, P, Skeleton, tooltip, ts } from "@kyoo/primitives";
import { ErrorView } from "../errors"; import { ErrorView } from "../errors";
import { z } from "zod"; import { z } from "zod";
import { View } from "react-native"; import { View } from "react-native";
import { useYoshiki } from "yoshiki/native"; import { useYoshiki } from "yoshiki/native";
import Info from "@material-symbols/svg-400/outlined/info.svg"; import Info from "@material-symbols/svg-400/outlined/info.svg";
import Scan from "@material-symbols/svg-400/outlined/sensors.svg";
import { useMutation } from "@tanstack/react-query";
export const Scanner = () => { export const Scanner = () => {
const { css } = useYoshiki(); const { css } = useYoshiki();
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useFetch(Scanner.query()); const { data, error } = useFetch(Scanner.query());
const metadataRefreshMutation = useMutation({
mutationFn: () =>
queryFn({
path: ["rescan"],
method: "POST",
}),
});
return ( return (
<SettingsContainer title={t("admin.scanner.label")}> <SettingsContainer
title={t("admin.scanner.label")}
extraTop={
<Button
licon={<Icon icon={Scan} {...css({ marginX: ts(1) })} />}
text={t("admin.scanner.scan")}
onPress={() => metadataRefreshMutation.mutate()}
{...css({ marginBottom: ts(2), })}
/>
}
>
<> <>
{error != null ? ( {error != null ? (
<ErrorView error={error} /> <ErrorView error={error} />

View File

@ -88,17 +88,20 @@ export const SettingsContainer = ({
children, children,
title, title,
extra, extra,
extraTop,
...props ...props
}: { }: {
children: ReactElement | (ReactElement | Falsy)[] | Falsy; children: ReactElement | (ReactElement | Falsy)[] | Falsy;
title: string; title: string;
extra?: ReactElement; extra?: ReactElement;
extraTop?: ReactElement;
}) => { }) => {
const { css } = useYoshiki(); const { css } = useYoshiki();
return ( return (
<Container {...props}> <Container {...props}>
<H1 {...css({ fontSize: rem(2) })}>{title}</H1> <H1 {...css({ fontSize: rem(2) })}>{title}</H1>
{extraTop}
<SwitchVariant> <SwitchVariant>
{({ css }) => ( {({ css }) => (
<View <View

View File

@ -237,6 +237,7 @@
}, },
"scanner": { "scanner": {
"label": "Scanner", "label": "Scanner",
"scan": "Trigger library scan",
"empty": "No issue found. All your items are registered." "empty": "No issue found. All your items are registered."
} }
} }

View File

@ -237,6 +237,7 @@
}, },
"scanner": { "scanner": {
"label": "Scanner", "label": "Scanner",
"scan": "Déclencher le scan de la bibliothèque",
"empty": "Aucun problème trouvé. Toutes vos vidéos sont enregistrés." "empty": "Aucun problème trouvé. Toutes vos vidéos sont enregistrés."
} }
} }