refactor: unify floating toolbar sizing and show graph title
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useMemo, useState, type Dispatch, type ReactNode, type SetStateAction } from "react";
|
||||
import type { Board } from "@/lib/workspace";
|
||||
|
||||
type ActiveBoard = Pick<Board, "id" | "workspace_id" | "title"> | null;
|
||||
const ActiveBoardContext = createContext<{
|
||||
board: ActiveBoard;
|
||||
setBoard: Dispatch<SetStateAction<ActiveBoard>>;
|
||||
} | null>(null);
|
||||
|
||||
export function ActiveBoardProvider({ children }: { children: ReactNode }) {
|
||||
const [board, setBoard] = useState<ActiveBoard>(null);
|
||||
const value = useMemo(() => ({ board, setBoard }), [board]);
|
||||
return <ActiveBoardContext.Provider value={value}>{children}</ActiveBoardContext.Provider>;
|
||||
}
|
||||
|
||||
export function useActiveBoard() {
|
||||
const context = useContext(ActiveBoardContext);
|
||||
if (!context) throw new Error("useActiveBoard requires ActiveBoardProvider");
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user