- Add NODE_ENV=production to .env for environment configuration - Enhance product API route with JSON cache manager for local storage and retrieval - Introduce cache-only mode and detailed logging for better performance and offline support - Update UI to display cache status and storage statistics
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Database, Globe } from "lucide-react";
|
|
|
|
export function CacheOnlySwitch() {
|
|
const [cacheOnly, setCacheOnly] = useState(false);
|
|
const isProd = process.env.NODE_ENV === "production";
|
|
|
|
// Carregar preferência do localStorage
|
|
useEffect(() => {
|
|
const saved = localStorage.getItem("cache_only_mode");
|
|
if (saved) {
|
|
setCacheOnly(saved === "true");
|
|
}
|
|
}, []);
|
|
|
|
// Salvar preferência
|
|
const handleToggle = (checked: boolean) => {
|
|
setCacheOnly(checked);
|
|
localStorage.setItem("cache_only_mode", checked.toString());
|
|
};
|
|
|
|
// Só exibir em produção
|
|
if (!isProd) return null;
|
|
|
|
return (
|
|
<div className="flex items-center gap-2 p-3 bg-gray-100 dark:bg-gray-800 rounded-lg">
|
|
{cacheOnly ? (
|
|
<Database className="w-4 h-4 text-blue-600" />
|
|
) : (
|
|
<Globe className="w-4 h-4 text-green-600" />
|
|
)}
|
|
|
|
<Label htmlFor="cache-only" className="cursor-pointer">
|
|
{cacheOnly ? "Modo Cache Local" : "Modo Online"}
|
|
</Label>
|
|
|
|
<Switch
|
|
id="cache-only"
|
|
checked={cacheOnly}
|
|
onCheckedChange={handleToggle}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|