From 0e05733bbb9ebe3ee40f23edf41531ea6d4f8d70 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Apr 2023 23:51:12 +0800 Subject: [PATCH] fix: #589 improve unauthorized tips --- app/components/chat.tsx | 9 ++++- app/components/settings.tsx | 65 +++++++++++++++++++------------------ app/components/ui-lib.tsx | 2 +- app/locales/cn.ts | 4 +-- app/store/access.ts | 8 +++-- app/store/app.ts | 26 +++++++++------ 6 files changed, 66 insertions(+), 48 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c5c257e5..fbac9f2c 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -19,6 +19,7 @@ import { BOT_HELLO, ROLES, createMessage, + useAccessStore, } from "../store"; import { @@ -485,11 +486,17 @@ export function Chat(props: { const context: RenderMessage[] = session.context.slice(); + const accessStore = useAccessStore(); + if ( context.length === 0 && session.messages.at(0)?.content !== BOT_HELLO.content ) { - context.push(BOT_HELLO); + const copiedHello = Object.assign({}, BOT_HELLO); + if (!accessStore.isAuthorized()) { + copiedHello.content = Locale.Error.Unauthorized; + } + context.push(copiedHello); } // preview messages diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 15fe5839..bbb28b46 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -124,8 +124,7 @@ export function Settings(props: { closeSettings: () => void }) { const builtinCount = SearchService.count.builtin; const customCount = promptStore.prompts.size ?? 0; - const showUsage = !!accessStore.token || !!accessStore.accessCode; - + const showUsage = accessStore.isAuthorized(); useEffect(() => { checkUpdate(); showUsage && checkUsage(); @@ -346,37 +345,7 @@ export function Settings(props: { closeSettings: () => void }) { > - - - - updateConfig( - (config) => - (config.disablePromptHint = e.currentTarget.checked), - ) - } - > - - - } - text={Locale.Settings.Prompt.Edit} - onClick={() => showToast(Locale.WIP)} - /> - - {enabledAccessControl ? ( void }) { + + + + updateConfig( + (config) => + (config.disablePromptHint = e.currentTarget.checked), + ) + } + > + + + + } + text={Locale.Settings.Prompt.Edit} + onClick={() => showToast(Locale.WIP)} + /> + + +