feat: adição de novos ícones SVG e configuração do ambiente
- Adicionados ícones SVG para ChatGPT, Claude, Gemini e OpenRouter - Implementados ícones para modos claro e escuro do ChatGPT - Criado script de inicialização para PostgreSQL com extensão pgcrypto - Adicionado script de configuração de ambiente que faz backup do .env - Configurado tsconfig.json para TypeScript com opções de compilação
This commit is contained in:
58
components/privacy-provider.tsx
Normal file
58
components/privacy-provider.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import React, { 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;
|
||||
}
|
||||
Reference in New Issue
Block a user