mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 14:29:07 +02:00
remove mock peers
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { createContext, useCallback, useContext, useState, type ReactNode } from "react";
|
||||
import { Window } from "@wailsio/runtime";
|
||||
|
||||
export type ViewMode = "default" | "advanced";
|
||||
|
||||
// Window dimensions per view. Height matches the Settings window (640) so
|
||||
// the chrome height is identical across surfaces; width grows from the
|
||||
// compact 380 default to 900 in advanced.
|
||||
export const VIEW_SIZE: Record<ViewMode, { width: number; height: number }> = {
|
||||
default: { width: 380, height: 640 },
|
||||
advanced: { width: 900, height: 640 },
|
||||
};
|
||||
|
||||
type ViewModeContextValue = {
|
||||
viewMode: ViewMode;
|
||||
setViewMode: (mode: ViewMode) => void;
|
||||
};
|
||||
|
||||
const ViewModeContext = createContext<ViewModeContextValue | null>(null);
|
||||
|
||||
export const ViewModeProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [viewMode, setMode] = useState<ViewMode>("default");
|
||||
const setViewMode = useCallback(
|
||||
(mode: ViewMode) => {
|
||||
setMode((prev) => {
|
||||
if (prev === mode) return prev;
|
||||
const { width, height } = VIEW_SIZE[mode];
|
||||
void Window.SetSize(width, height).catch(() => {});
|
||||
return mode;
|
||||
});
|
||||
},
|
||||
[],
|
||||
);
|
||||
return (
|
||||
<ViewModeContext.Provider value={{ viewMode, setViewMode }}>
|
||||
{children}
|
||||
</ViewModeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useViewMode = () => {
|
||||
const ctx = useContext(ViewModeContext);
|
||||
if (!ctx) throw new Error("useViewMode must be used inside ViewModeProvider");
|
||||
return ctx;
|
||||
};
|
||||
Reference in New Issue
Block a user