feat: add settings menu
All checks were successful
Deploy to VPS (dist) / deploy (push) Successful in 1m40s
All checks were successful
Deploy to VPS (dist) / deploy (push) Successful in 1m40s
This commit is contained in:
57
src/components/lift/LiftContext.tsx
Normal file
57
src/components/lift/LiftContext.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import { createContext, useCallback, useContext, useRef, useState } from "react";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
type LiftContextValue = {
|
||||
liftedIds: Set<string>;
|
||||
alwaysLiftedIds: Set<string>;
|
||||
setLiftedIds: (ids: string[]) => void;
|
||||
registerAlways: (id: string) => void;
|
||||
unregisterAlways: (id: string) => void;
|
||||
portalContainer: HTMLElement | null;
|
||||
setPortalContainer: (el: HTMLElement | null) => void;
|
||||
};
|
||||
|
||||
const LiftContext = createContext<LiftContextValue | null>(null);
|
||||
|
||||
export function useLift(): LiftContextValue {
|
||||
const ctx = useContext(LiftContext);
|
||||
if (!ctx) throw new Error("useLift must be used within LiftProvider");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
export function LiftProvider({ children }: { children: ReactNode }) {
|
||||
const [liftedIds, setLiftedIdsRaw] = useState<Set<string>>(new Set());
|
||||
const [alwaysLiftedIds, setAlwaysLiftedIds] = useState<Set<string>>(new Set());
|
||||
const [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);
|
||||
const alwaysRef = useRef<Set<string>>(new Set());
|
||||
|
||||
const setLiftedIds = useCallback((ids: string[]) => {
|
||||
setLiftedIdsRaw(new Set(ids));
|
||||
}, []);
|
||||
|
||||
const registerAlways = useCallback((id: string) => {
|
||||
alwaysRef.current.add(id);
|
||||
setAlwaysLiftedIds(new Set(alwaysRef.current));
|
||||
}, []);
|
||||
|
||||
const unregisterAlways = useCallback((id: string) => {
|
||||
alwaysRef.current.delete(id);
|
||||
setAlwaysLiftedIds(new Set(alwaysRef.current));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<LiftContext
|
||||
value={{
|
||||
liftedIds,
|
||||
alwaysLiftedIds,
|
||||
setLiftedIds,
|
||||
registerAlways,
|
||||
unregisterAlways,
|
||||
portalContainer,
|
||||
setPortalContainer,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</LiftContext>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user