From e162d66a5c3aee77766e5c5936febf4591dd09cf Mon Sep 17 00:00:00 2001 From: yorkeking <34937020+yorkeking@users.noreply.github.com> Date: Tue, 4 Apr 2023 01:00:02 +0800 Subject: [PATCH] Update settings.tsx --- app/components/settings.tsx | 65 +++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 5d3879b26..936588b79 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useRef, useMemo } from "react"; +import { useState, useEffect, useMemo, HTMLProps } from "react"; import EmojiPicker, { Theme as EmojiTheme } from "emoji-picker-react"; @@ -8,6 +8,8 @@ import ResetIcon from "../icons/reload.svg"; import CloseIcon from "../icons/close.svg"; import ClearIcon from "../icons/clear.svg"; import EditIcon from "../icons/edit.svg"; +import EyeIcon from "../icons/eye.svg"; +import EyeOffIcon from "../icons/eye-off.svg"; import { List, ListItem, Popover, showToast } from "./ui-lib"; @@ -20,7 +22,7 @@ import { useUpdateStore, useAccessStore, } from "../store"; -import { Avatar, PromptHints } from "./home"; +import { Avatar } from "./chat"; import Locale, { AllLangs, changeLang, getLang } from "../locales"; import { getCurrentVersion } from "../utils"; @@ -47,6 +49,28 @@ function SettingItem(props: { ); } +function PasswordInput(props: HTMLProps) { + const [visible, setVisible] = useState(false); + + function changeVisibility() { + setVisible(!visible); + } + + return ( + + + : } + onClick={changeVisibility} + /> + + ); +} + export function Settings(props: { closeSettings: () => void }) { const [showEmojiPicker, setShowEmojiPicker] = useState(false); const [config, updateConfig, resetConfig, clearAllData, clearSessions] = @@ -72,7 +96,6 @@ export function Settings(props: { closeSettings: () => void }) { } const [usage, setUsage] = useState<{ - granted?: number; used?: number; }>(); const [loadingUsage, setLoadingUsage] = useState(false); @@ -81,8 +104,7 @@ export function Settings(props: { closeSettings: () => void }) { requestUsage() .then((res) => setUsage({ - granted: res?.total_granted, - used: res?.total_used, + used: res, }), ) .finally(() => { @@ -105,6 +127,13 @@ export function Settings(props: { closeSettings: () => void }) { const builtinCount = SearchService.count.builtin; const customCount = promptStore.prompts.size ?? 0; + const showUsage = accessStore.token !== ""; + useEffect(() => { + if (showUsage) { + checkUsage(); + } + }, [showUsage]); + return ( <>
@@ -182,7 +211,7 @@ export function Settings(props: { closeSettings: () => void }) { {checkingUpdate ? (
) : hasNewVersion ? ( - + {Locale.Settings.Update.GoToUpdate} ) : ( @@ -285,7 +314,8 @@ export function Settings(props: { closeSettings: () => void }) { checked={config.sendPreviewBubble} onChange={(e) => updateConfig( - (config) => (config.sendPreviewBubble = e.currentTarget.checked), + (config) => + (config.sendPreviewBubble = e.currentTarget.checked), ) } > @@ -328,14 +358,14 @@ export function Settings(props: { closeSettings: () => void }) { title={Locale.Settings.AccessCode.Title} subTitle={Locale.Settings.AccessCode.SubTitle} > - { accessStore.updateCode(e.currentTarget.value); }} - > + /> ) : ( <> @@ -345,28 +375,27 @@ export function Settings(props: { closeSettings: () => void }) { title={Locale.Settings.Token.Title} subTitle={Locale.Settings.Token.SubTitle} > - { accessStore.updateToken(e.currentTarget.value); }} - > + /> - {loadingUsage ? ( + {!showUsage || loadingUsage ? (
) : (