mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 15:17:43 -05:00
Use createContext
This commit is contained in:
@@ -46,6 +46,7 @@ let sideNavCollapsed = $state(initialCollapsed);
|
||||
let sideNavModalOpen = $state(false);
|
||||
const mounted = new IsMounted();
|
||||
|
||||
// xxx: query.live
|
||||
// the bell data loads lazily like the React app's NotificationsProvider:
|
||||
// after hydration, never blocking SSR
|
||||
const notificationsQuery = $derived(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getContext, setContext } from "svelte";
|
||||
import { createContext } from "svelte";
|
||||
|
||||
export interface MenuTriggerProps {
|
||||
readonly popovertarget: string;
|
||||
@@ -10,16 +10,4 @@ export interface MenuContext {
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
const KEY = Symbol("menu");
|
||||
|
||||
export function setMenuContext(context: MenuContext) {
|
||||
setContext(KEY, context);
|
||||
}
|
||||
|
||||
export function getMenuContext(): MenuContext {
|
||||
const context = getContext<MenuContext>(KEY);
|
||||
if (!context) {
|
||||
throw new Error("Menu items must be used inside <Menu>");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
export const [getMenuContext, setMenuContext] = createContext<MenuContext>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getContext, setContext } from "svelte";
|
||||
import { createContext } from "svelte";
|
||||
|
||||
export interface SelectContext {
|
||||
readonly selectedKey: string | number | null;
|
||||
@@ -12,16 +12,5 @@ export interface SelectContext {
|
||||
setFocusedKey: (key: string | number | null) => void;
|
||||
}
|
||||
|
||||
const KEY = Symbol("select");
|
||||
|
||||
export function setSelectContext(context: SelectContext) {
|
||||
setContext(KEY, context);
|
||||
}
|
||||
|
||||
export function getSelectContext(): SelectContext {
|
||||
const context = getContext<SelectContext>(KEY);
|
||||
if (!context) {
|
||||
throw new Error("Select items must be used inside <Select>");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
export const [getSelectContext, setSelectContext] =
|
||||
createContext<SelectContext>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getContext, setContext } from "svelte";
|
||||
import { createContext } from "svelte";
|
||||
|
||||
export interface TabsContext {
|
||||
readonly selectedKey: string | null;
|
||||
@@ -11,16 +11,4 @@ export interface TabsContext {
|
||||
) => void;
|
||||
}
|
||||
|
||||
const KEY = Symbol("tabs");
|
||||
|
||||
export function setTabsContext(context: TabsContext) {
|
||||
setContext(KEY, context);
|
||||
}
|
||||
|
||||
export function getTabsContext(): TabsContext {
|
||||
const context = getContext<TabsContext>(KEY);
|
||||
if (!context) {
|
||||
throw new Error("Tabs components must be used inside <Tabs>");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
export const [getTabsContext, setTabsContext] = createContext<TabsContext>();
|
||||
|
||||
Reference in New Issue
Block a user