v0.1 - макет интерфейса, аутентификация через логин, аккаунт админа, создание партии в 2 этапа, базовые настройки профиля и группы, переключение между группами, статистика
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { createContext, useCallback, useContext, useRef, useState } from "react";
|
||||
import type { PropsWithChildren } from "react";
|
||||
|
||||
interface ToastCtx {
|
||||
show: (message: string) => void;
|
||||
}
|
||||
|
||||
const Ctx = createContext<ToastCtx>({ show: () => {} });
|
||||
|
||||
export function ToastProvider({ children }: PropsWithChildren) {
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const show = useCallback((msg: string) => {
|
||||
setMessage(msg);
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
timer.current = setTimeout(() => setMessage(null), 2800);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Ctx.Provider value={{ show }}>
|
||||
{children}
|
||||
{message && <div className="toast">{message}</div>}
|
||||
</Ctx.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useToast(): ToastCtx {
|
||||
return useContext(Ctx);
|
||||
}
|
||||
Reference in New Issue
Block a user