mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Lint
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { MenuButton } from "@headlessui/react";
|
||||||
|
import { signIn, useSession } from "next-auth/react";
|
||||||
import { Button, Menu } from "@headlessui/react";
|
|
||||||
import { signIn, signOut, useSession } from "next-auth/react";
|
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { RxAvatar } from "react-icons/rx";
|
import { RxAvatar } from "react-icons/rx";
|
||||||
|
|
||||||
import { useAuthMenuOptions } from "@/hooks/useAuthMenuOptions";
|
import { useAuthMenuOptions } from "@/hooks/useAuthMenuOptions";
|
||||||
@@ -27,9 +24,9 @@ const AuthButton = () => {
|
|||||||
items={menuItems}
|
items={menuItems}
|
||||||
containerClassName="flex items-center justify-center"
|
containerClassName="flex items-center justify-center"
|
||||||
buttonComponent={
|
buttonComponent={
|
||||||
<Menu.Button>
|
<MenuButton>
|
||||||
<RxAvatar className="h-6 w-6" />
|
<RxAvatar className="h-6 w-6" />
|
||||||
</Menu.Button>
|
</MenuButton>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const LocaleChecker = ({ children }: LocaleCheckerProps) => {
|
|||||||
) {
|
) {
|
||||||
router.push({ pathname, params: params as any }, { locale: userLocale });
|
router.push({ pathname, params: params as any }, { locale: userLocale });
|
||||||
}
|
}
|
||||||
}, [locale, sessionData, status]);
|
}, [locale, sessionData, status, params, pathname, router, userLocale]);
|
||||||
|
|
||||||
// To avoid flickering, we don't render the children until we have the user's locale
|
// To avoid flickering, we don't render the children until we have the user's locale
|
||||||
if (status === "loading") return null;
|
if (status === "loading") return null;
|
||||||
|
|||||||
+32
-34
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
|
|
||||||
import { SetFieldValue } from "react-hook-form";
|
import { SetFieldValue } from "react-hook-form";
|
||||||
|
|
||||||
@@ -7,12 +7,9 @@ export interface FormPersistConfig {
|
|||||||
watch: (names?: string | string[]) => any;
|
watch: (names?: string | string[]) => any;
|
||||||
setValue: SetFieldValue<any>;
|
setValue: SetFieldValue<any>;
|
||||||
exclude?: string[];
|
exclude?: string[];
|
||||||
onDataRestored?: (data: any) => void;
|
|
||||||
validate?: boolean;
|
validate?: boolean;
|
||||||
dirty?: boolean;
|
dirty?: boolean;
|
||||||
touch?: boolean;
|
touch?: boolean;
|
||||||
onTimeout?: () => void;
|
|
||||||
timeout?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const useFormPersist = (
|
const useFormPersist = (
|
||||||
@@ -21,39 +18,36 @@ const useFormPersist = (
|
|||||||
storage,
|
storage,
|
||||||
watch,
|
watch,
|
||||||
setValue,
|
setValue,
|
||||||
exclude = [],
|
exclude,
|
||||||
onDataRestored,
|
|
||||||
validate = false,
|
validate = false,
|
||||||
dirty = false,
|
dirty = false,
|
||||||
touch = false,
|
touch = false,
|
||||||
onTimeout,
|
|
||||||
timeout,
|
|
||||||
}: FormPersistConfig,
|
}: FormPersistConfig,
|
||||||
) => {
|
) => {
|
||||||
const watchedValues = watch();
|
const watchedValues = watch();
|
||||||
|
|
||||||
const getStorage = () => storage || window.sessionStorage;
|
const getStorage = useCallback(
|
||||||
|
() => storage || window.sessionStorage,
|
||||||
|
[storage],
|
||||||
|
);
|
||||||
|
|
||||||
const clearStorage = () => getStorage().removeItem(name);
|
const clearStorage = useCallback(
|
||||||
|
() => getStorage().removeItem(name),
|
||||||
|
[getStorage, name],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const str = getStorage().getItem(name);
|
const storedValuesJSON = getStorage().getItem(name);
|
||||||
|
|
||||||
if (str) {
|
if (storedValuesJSON) {
|
||||||
const { _timestamp = null, ...values } = JSON.parse(str);
|
const values = JSON.parse(storedValuesJSON);
|
||||||
const dataRestored: { [key: string]: any } = {};
|
const dataRestored: { [key: string]: any } = {};
|
||||||
const currTimestamp = Date.now();
|
|
||||||
|
|
||||||
if (timeout && currTimestamp - _timestamp > timeout) {
|
|
||||||
onTimeout && onTimeout();
|
|
||||||
clearStorage();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(values).forEach((key) => {
|
Object.keys(values).forEach((key) => {
|
||||||
const shouldSet = !exclude.includes(key);
|
const shouldSet = !exclude?.includes(key);
|
||||||
if (shouldSet) {
|
if (shouldSet) {
|
||||||
dataRestored[key] = values[key];
|
dataRestored[key] = values[key];
|
||||||
|
|
||||||
setValue(key, values[key], {
|
setValue(key, values[key], {
|
||||||
shouldValidate: validate,
|
shouldValidate: validate,
|
||||||
shouldDirty: dirty,
|
shouldDirty: dirty,
|
||||||
@@ -62,28 +56,32 @@ const useFormPersist = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (onDataRestored) {
|
|
||||||
onDataRestored(dataRestored);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => getStorage().setItem(name, JSON.stringify(dataRestored));
|
return () => getStorage().setItem(name, JSON.stringify(dataRestored));
|
||||||
}
|
}
|
||||||
}, [storage, name, onDataRestored, setValue]);
|
}, [
|
||||||
|
storage,
|
||||||
|
name,
|
||||||
|
setValue,
|
||||||
|
clearStorage,
|
||||||
|
dirty,
|
||||||
|
exclude,
|
||||||
|
touch,
|
||||||
|
validate,
|
||||||
|
getStorage,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const values = exclude.length
|
const values =
|
||||||
|
(exclude?.length ?? 0) > 0
|
||||||
? Object.entries(watchedValues)
|
? Object.entries(watchedValues)
|
||||||
.filter(([key]) => !exclude.includes(key))
|
.filter(([key]) => !exclude!.includes(key))
|
||||||
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {})
|
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {})
|
||||||
: Object.assign({}, watchedValues);
|
: { ...watchedValues };
|
||||||
|
|
||||||
if (Object.entries(values).length) {
|
if (Object.entries(values).length > 0) {
|
||||||
if (timeout !== undefined) {
|
|
||||||
values._timestamp = Date.now();
|
|
||||||
}
|
|
||||||
getStorage().setItem(name, JSON.stringify(values));
|
getStorage().setItem(name, JSON.stringify(values));
|
||||||
}
|
}
|
||||||
}, [watchedValues, timeout]);
|
}, [watchedValues, exclude, getStorage, name]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
clear: () => getStorage().removeItem(name),
|
clear: () => getStorage().removeItem(name),
|
||||||
|
|||||||
Reference in New Issue
Block a user