feat: use usePersistedState

This commit is contained in:
vagusx 2023-11-21 20:25:19 +08:00
parent 3bc2568052
commit 9b9db3ac07
4 changed files with 18 additions and 12 deletions

View File

@ -33,7 +33,7 @@ app.add_middleware(
# Useful for debugging purposes when you don't want to waste GPT4-Vision credits # Useful for debugging purposes when you don't want to waste GPT4-Vision credits
# Setting to True will stream a mock response instead of calling the OpenAI API # Setting to True will stream a mock response instead of calling the OpenAI API
SHOULD_MOCK_AI_RESPONSE = False SHOULD_MOCK_AI_RESPONSE = True
app.include_router(screenshot.router) app.include_router(screenshot.router)

View File

@ -40,6 +40,7 @@ function App() {
screenshotOneApiKey: null, screenshotOneApiKey: null,
isImageGenerationEnabled: true, isImageGenerationEnabled: true,
editorTheme: "cobalt", editorTheme: "cobalt",
termOfServiceAccepted: false,
}, },
"setting" "setting"
); );
@ -111,10 +112,17 @@ function App() {
setUpdateInstruction(""); setUpdateInstruction("");
} }
const onTermDialogOpenChange = (open: boolean) => {
setSettings((s) => ({
...s,
termOfServiceAccepted: !open,
}));
};
return ( return (
<div className="mt-2"> <div className="mt-2">
{IS_RUNNING_ON_CLOUD && <PicoBadge />} {IS_RUNNING_ON_CLOUD && <PicoBadge />}
{IS_RUNNING_ON_CLOUD && <TermsOfServiceDialog />} {IS_RUNNING_ON_CLOUD && <TermsOfServiceDialog open={!settings.termOfServiceAccepted} onOpenChange={onTermDialogOpenChange} />}
<div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-96 lg:flex-col"> <div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-96 lg:flex-col">
<div className="flex grow flex-col gap-y-2 overflow-y-auto border-r border-gray-200 bg-white px-6"> <div className="flex grow flex-col gap-y-2 overflow-y-auto border-r border-gray-200 bg-white px-6">

View File

@ -6,15 +6,14 @@ import {
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { useState } from "react";
const termAcceptedCacheKey = 'term_of_service_accepted'; const TermsOfServiceDialog: React.FC<{
open: boolean;
function TermsOfServiceDialog() { onOpenChange: (open: boolean) => void;
const [isOpen, setIsOpen] = useState(() => !localStorage.getItem(termAcceptedCacheKey)); }> = ({ open, onOpenChange }) => {
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent> <DialogContent>
<DialogHeader> <DialogHeader>
<DialogTitle className="mb-4">Terms of Service</DialogTitle> <DialogTitle className="mb-4">Terms of Service</DialogTitle>
@ -42,13 +41,11 @@ function TermsOfServiceDialog() {
</div> </div>
<DialogFooter> <DialogFooter>
<DialogClose onClick={() => { <DialogClose>Agree</DialogClose>
localStorage.setItem(termAcceptedCacheKey, 'true');
}}>Agree</DialogClose>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
); );
} };
export default TermsOfServiceDialog; export default TermsOfServiceDialog;

View File

@ -3,4 +3,5 @@ export interface Settings {
screenshotOneApiKey: string | null; screenshotOneApiKey: string | null;
isImageGenerationEnabled: boolean; isImageGenerationEnabled: boolean;
editorTheme: string; editorTheme: string;
termOfServiceAccepted: boolean;
} }