Files
openmonetis/components/privacy-provider.tsx
Felipe Coutinho a7f63fb77a refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting
- Configure Biome with tabs, double quotes, and organized imports
- Move all SQL/Drizzle queries from page.tsx files to data.ts files
- Create new data.ts files for: ajustes, dashboard, relatorios/categorias
- Update existing data.ts files: extrato, fatura (add lancamentos queries)
- Remove all drizzle-orm imports from page.tsx files
- Update README.md with new tooling info

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 13:15:37 +00:00

58 lines
1.4 KiB
TypeScript

"use client";
import type React from "react";
import { createContext, useContext, useEffect, useState } from "react";
interface PrivacyContextType {
privacyMode: boolean;
toggle: () => void;
set: (value: boolean) => void;
}
const PrivacyContext = createContext<PrivacyContextType | undefined>(undefined);
const STORAGE_KEY = "app:privacyMode";
export function PrivacyProvider({ children }: { children: React.ReactNode }) {
const [privacyMode, setPrivacyMode] = useState(false);
const [hydrated, setHydrated] = useState(false);
// Sincronizar com localStorage na montagem (evitar mismatch SSR/CSR)
useEffect(() => {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored !== null) {
setPrivacyMode(stored === "true");
}
setHydrated(true);
}, []);
// Persistir mudanças no localStorage
useEffect(() => {
if (hydrated) {
localStorage.setItem(STORAGE_KEY, String(privacyMode));
}
}, [privacyMode, hydrated]);
const toggle = () => {
setPrivacyMode((prev) => !prev);
};
const set = (value: boolean) => {
setPrivacyMode(value);
};
return (
<PrivacyContext.Provider value={{ privacyMode, toggle, set }}>
{children}
</PrivacyContext.Provider>
);
}
export function usePrivacyMode() {
const context = useContext(PrivacyContext);
if (context === undefined) {
throw new Error("usePrivacyMode must be used within a PrivacyProvider");
}
return context;
}