From 0140f771c6a23256bf171b3edcf2f7fd810b5794 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 28 Jun 2023 23:12:35 +0800 Subject: [PATCH 1/6] feat: close #2175 use default api host if endpoint is empty --- app/client/platforms/openai.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index fce7eee4..79d48556 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -1,4 +1,8 @@ -import { OpenaiPath, REQUEST_TIMEOUT_MS } from "@/app/constant"; +import { + DEFAULT_API_HOST, + OpenaiPath, + REQUEST_TIMEOUT_MS, +} from "@/app/constant"; import { useAccessStore, useAppConfig, useChatStore } from "@/app/store"; import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api"; @@ -12,6 +16,9 @@ import { prettyObject } from "@/app/utils/format"; export class ChatGPTApi implements LLMApi { path(path: string): string { let openaiUrl = useAccessStore.getState().openaiUrl; + if (openaiUrl.length === 0) { + openaiUrl = DEFAULT_API_HOST; + } if (openaiUrl.endsWith("/")) { openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1); } From 3298961748ec331669e8e34d8e33b585d439c032 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 28 Jun 2023 23:40:39 +0800 Subject: [PATCH 2/6] feat: replace window.confirm with showConfirm --- app/components/chat-list.tsx | 8 +++++-- app/components/chat.tsx | 6 ++--- app/components/error.tsx | 12 ++++++---- app/components/mask.tsx | 18 +++++++++++---- app/components/new-chat.tsx | 5 ++-- app/components/settings.tsx | 13 +++++++---- app/components/sidebar.tsx | 6 ++--- app/components/ui-lib.tsx | 45 +++++++++++++++++++++++++++++++++++- 8 files changed, 89 insertions(+), 24 deletions(-) diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index fc4e5378..a6143f32 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -17,6 +17,7 @@ import { Path } from "../constant"; import { MaskAvatar } from "./mask"; import { Mask } from "../store/mask"; import { useRef, useEffect } from "react"; +import { showConfirm } from "./ui-lib"; export function ChatItem(props: { onClick?: () => void; @@ -139,8 +140,11 @@ export function ChatList(props: { narrow?: boolean }) { navigate(Path.Chat); selectSession(i); }} - onDelete={() => { - if (!props.narrow || confirm(Locale.Home.DeleteChat)) { + onDelete={async () => { + if ( + !props.narrow || + (await showConfirm(Locale.Home.DeleteChat)) + ) { chatStore.deleteSession(i); } }} diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 6db5eb2b..fd732b9d 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -61,7 +61,7 @@ import Locale from "../locales"; import { IconButton } from "./button"; import styles from "./chat.module.scss"; -import { ListItem, Modal, showToast } from "./ui-lib"; +import { ListItem, Modal, showConfirm, showToast } from "./ui-lib"; import { useLocation, useNavigate } from "react-router-dom"; import { LAST_INPUT_KEY, Path, REQUEST_TIMEOUT_MS } from "../constant"; import { Avatar } from "./emoji"; @@ -93,8 +93,8 @@ export function SessionConfigModel(props: { onClose: () => void }) { icon={} bordered text={Locale.Chat.Config.Reset} - onClick={() => { - if (confirm(Locale.Memory.ResetConfirm)) { + onClick={async () => { + if (await showConfirm(Locale.Memory.ResetConfirm)) { chatStore.updateCurrentSession( (session) => (session.memoryPrompt = ""), ); diff --git a/app/components/error.tsx b/app/components/error.tsx index 0e01c417..33abe931 100644 --- a/app/components/error.tsx +++ b/app/components/error.tsx @@ -5,6 +5,7 @@ import ResetIcon from "../icons/reload.svg"; import { ISSUE_URL } from "../constant"; import Locale from "../locales"; import { downloadAs } from "../utils"; +import { showConfirm } from "./ui-lib"; interface IErrorBoundaryState { hasError: boolean; @@ -57,10 +58,13 @@ export class ErrorBoundary extends React.Component { } text="Clear All Data" - onClick={() => - confirm(Locale.Settings.Actions.ConfirmClearAll) && - this.clearAndSaveData() - } + onClick={async () => { + if ( + await showConfirm(Locale.Settings.Actions.ConfirmClearAll) + ) { + this.clearAndSaveData(); + } + }} bordered /> diff --git a/app/components/mask.tsx b/app/components/mask.tsx index d48ed7c2..c10ba476 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -15,7 +15,15 @@ import CopyIcon from "../icons/copy.svg"; import { DEFAULT_MASK_AVATAR, Mask, useMaskStore } from "../store/mask"; import { ChatMessage, ModelConfig, useAppConfig, useChatStore } from "../store"; import { ROLES } from "../client/api"; -import { Input, List, ListItem, Modal, Popover, Select } from "./ui-lib"; +import { + Input, + List, + ListItem, + Modal, + Popover, + Select, + showConfirm, +} from "./ui-lib"; import { Avatar, AvatarPicker } from "./emoji"; import Locale, { AllLangs, ALL_LANG_OPTIONS, Lang } from "../locales"; import { useNavigate } from "react-router-dom"; @@ -125,10 +133,10 @@ export function MaskConfig(props: { { + onChange={async (e) => { if ( e.currentTarget.checked && - confirm(Locale.Mask.Config.Sync.Confirm) + (await showConfirm(Locale.Mask.Config.Sync.Confirm)) ) { props.updateMask((mask) => { mask.syncGlobalConfig = e.currentTarget.checked; @@ -439,8 +447,8 @@ export function MaskPage() { } text={Locale.Mask.Item.Delete} - onClick={() => { - if (confirm(Locale.Mask.Item.DeleteConfirm)) { + onClick={async () => { + if (await showConfirm(Locale.Mask.Item.DeleteConfirm)) { maskStore.delete(m.id); } }} diff --git a/app/components/new-chat.tsx b/app/components/new-chat.tsx index 30041c5c..64c4703a 100644 --- a/app/components/new-chat.tsx +++ b/app/components/new-chat.tsx @@ -14,6 +14,7 @@ import Locale from "../locales"; import { useAppConfig, useChatStore } from "../store"; import { MaskAvatar } from "./mask"; import { useCommand } from "../command"; +import { showConfirm } from "./ui-lib"; function getIntersectionArea(aRect: DOMRect, bRect: DOMRect) { const xmin = Math.max(aRect.x, bRect.x); @@ -125,8 +126,8 @@ export function NewChat() { {!state?.fromHome && ( { - if (confirm(Locale.NewChat.ConfirmNoShow)) { + onClick={async () => { + if (await showConfirm(Locale.NewChat.ConfirmNoShow)) { startChat(); config.update( (config) => (config.dontShowMaskSplashScreen = true), diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 1d45a0c6..54389c9b 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -18,6 +18,7 @@ import { PasswordInput, Popover, Select, + showConfirm, } from "./ui-lib"; import { ModelConfigList } from "./model-config"; @@ -377,8 +378,10 @@ export function Settings() {
} - onClick={() => { - if (confirm(Locale.Settings.Actions.ConfirmClearAll)) { + onClick={async () => { + if ( + await showConfirm(Locale.Settings.Actions.ConfirmClearAll) + ) { chatStore.clearAllData(); } }} @@ -389,8 +392,10 @@ export function Settings() {
} - onClick={() => { - if (confirm(Locale.Settings.Actions.ConfirmResetAll)) { + onClick={async () => { + if ( + await showConfirm(Locale.Settings.Actions.ConfirmResetAll) + ) { resetConfig(); } }} diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index 038ca86f..d9d861d5 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -26,7 +26,7 @@ import { import { Link, useNavigate } from "react-router-dom"; import { useMobileScreen } from "../utils"; import dynamic from "next/dynamic"; -import { showToast } from "./ui-lib"; +import { showConfirm, showToast } from "./ui-lib"; const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { loading: () => null, @@ -160,8 +160,8 @@ export function SideBar(props: { className?: string }) {
} - onClick={() => { - if (confirm(Locale.Home.DeleteChat)) { + onClick={async () => { + if (await showConfirm(Locale.Home.DeleteChat)) { chatStore.deleteSession(chatStore.currentSessionIndex); } }} diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index be9b30a6..156eecfa 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -4,6 +4,7 @@ import CloseIcon from "../icons/close.svg"; import EyeIcon from "../icons/eye.svg"; import EyeOffIcon from "../icons/eye-off.svg"; import DownIcon from "../icons/down.svg"; +import Locale from "../locales"; import { createRoot } from "react-dom/client"; import React, { HTMLProps, useEffect, useState } from "react"; @@ -87,7 +88,7 @@ export function Loading() { interface ModalProps { title: string; - children?: JSX.Element | JSX.Element[]; + children?: any; actions?: JSX.Element[]; onClose?: () => void; } @@ -262,3 +263,45 @@ export function Select(
); } + +export function showConfirm(content: any) { + const div = document.createElement("div"); + div.className = "modal-mask"; + document.body.appendChild(div); + + const root = createRoot(div); + const closeModal = () => { + root.unmount(); + div.remove(); + }; + + return new Promise((resolve) => { + root.render( + { + resolve(false); + closeModal(); + }} + >
, + { + resolve(true); + closeModal(); + }} + >, + ]} + onClose={closeModal} + > + {content} + , + ); + }); +} From ea6926cad3de64173d39717444e42aad62c68d1a Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Thu, 29 Jun 2023 00:09:56 +0800 Subject: [PATCH 3/6] feat: replace window.prompt with showPrompt --- app/components/button.module.scss | 9 ++-- app/components/button.tsx | 4 ++ app/components/chat.tsx | 13 +++-- app/components/ui-lib.module.scss | 20 +++++++ app/components/ui-lib.tsx | 86 +++++++++++++++++++++++++++++++ app/icons/cancel.svg | 1 + app/icons/confirm.svg | 1 + app/styles/globals.scss | 3 ++ 8 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 app/icons/cancel.svg create mode 100644 app/icons/confirm.svg diff --git a/app/components/button.module.scss b/app/components/button.module.scss index 5aa53dcf..27e4278b 100644 --- a/app/components/button.module.scss +++ b/app/components/button.module.scss @@ -27,6 +27,11 @@ fill: white !important; } } + + &:hover, + &:focus { + border-color: var(--primary); + } } .shadow { @@ -37,10 +42,6 @@ border: var(--border-in-light); } -.icon-button:hover { - border-color: var(--primary); -} - .icon-button-icon { width: 16px; height: 16px; diff --git a/app/components/button.tsx b/app/components/button.tsx index f93741b3..51698d07 100644 --- a/app/components/button.tsx +++ b/app/components/button.tsx @@ -12,6 +12,8 @@ export function IconButton(props: { className?: string; title?: string; disabled?: boolean; + tabIndex?: number; + autoFocus?: boolean; }) { return (
-
- } - onClick={async () => { - if ( - await showConfirm(Locale.Settings.Actions.ConfirmClearAll) - ) { - chatStore.clearAllData(); - } - }} - bordered - title={Locale.Settings.Actions.ClearAll} - /> -
-
- } - onClick={async () => { - if ( - await showConfirm(Locale.Settings.Actions.ConfirmResetAll) - ) { - resetConfig(); - } - }} - bordered - title={Locale.Settings.Actions.ResetAll} - /> -
+
+
} onClick={() => navigate(Path.Home)} bordered - title={Locale.Settings.Actions.Close} />
@@ -691,6 +701,8 @@ export function Settings() { {shouldShowPromptModal && ( setShowPromptModal(false)} /> )} + +
); diff --git a/app/locales/ar.ts b/app/locales/ar.ts index 7a3eaa2b..6ece142b 100644 --- a/app/locales/ar.ts +++ b/app/locales/ar.ts @@ -100,13 +100,7 @@ const ar: PartialLocaleType = { Settings: { Title: "الإعدادات", SubTitle: "جميع الإعدادات", - Actions: { - ClearAll: "مسح جميع البيانات", - ResetAll: "إعادة تعيين جميع الإعدادات", - Close: "إغلاق", - ConfirmResetAll: "هل أنت متأكد من رغبتك في إعادة تعيين جميع الإعدادات؟", - ConfirmClearAll: "هل أنت متأكد من رغبتك في مسح جميع البيانات؟", - }, + Lang: { Name: "Language", // تنبيه: إذا كنت ترغب في إضافة ترجمة جديدة، يرجى عدم ترجمة هذه القيمة وتركها "Language" All: "كل اللغات", diff --git a/app/locales/cn.ts b/app/locales/cn.ts index ae22efa9..d8b4bd0f 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -108,13 +108,21 @@ const cn = { }, Settings: { Title: "设置", - SubTitle: "设置选项", - Actions: { - ClearAll: "清除所有数据", - ResetAll: "重置所有选项", - Close: "关闭", - ConfirmResetAll: "确认重置所有配置?", - ConfirmClearAll: "确认清除所有数据?", + SubTitle: "所有设置选项", + + Danger: { + Reset: { + Title: "重置所有设置", + SubTitle: "重置所有设置项回默认值", + Action: "立即重置", + Confirm: "确认重置所有设置?", + }, + Clear: { + Title: "清除所有数据", + SubTitle: "清除所有聊天、设置数据", + Action: "立即清除", + Confirm: "确认清除所有聊天、设置数据?", + }, }, Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` diff --git a/app/locales/cs.ts b/app/locales/cs.ts index e1706b72..9f9afab0 100644 --- a/app/locales/cs.ts +++ b/app/locales/cs.ts @@ -61,13 +61,7 @@ const cs: PartialLocaleType = { Settings: { Title: "Nastavení", SubTitle: "Všechna nastavení", - Actions: { - ClearAll: "Vymazat všechna data", - ResetAll: "Obnovit veškeré nastavení", - Close: "Zavřít", - ConfirmResetAll: "Jste si jisti, že chcete obnovit všechna nastavení?", - ConfirmClearAll: "Jste si jisti, že chcete smazat všechna data?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Všechny jazyky", diff --git a/app/locales/de.ts b/app/locales/de.ts index 30eb2b0d..b8158c12 100644 --- a/app/locales/de.ts +++ b/app/locales/de.ts @@ -61,14 +61,7 @@ const de: PartialLocaleType = { Settings: { Title: "Einstellungen", SubTitle: "Alle Einstellungen", - Actions: { - ClearAll: "Alle Daten löschen", - ResetAll: "Alle Einstellungen zurücksetzen", - Close: "Schließen", - ConfirmResetAll: - "Möchten Sie wirklich alle Konfigurationen zurücksetzen?", - ConfirmClearAll: "Möchten Sie wirklich alle Chats zurücksetzen?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Alle Sprachen", diff --git a/app/locales/en.ts b/app/locales/en.ts index 5261e7ed..3b6b7ff6 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -111,12 +111,19 @@ const en: LocaleType = { Settings: { Title: "Settings", SubTitle: "All Settings", - Actions: { - ClearAll: "Clear All Data", - ResetAll: "Reset All Settings", - Close: "Close", - ConfirmResetAll: "Are you sure you want to reset all configurations?", - ConfirmClearAll: "Are you sure you want to reset all data?", + Danger: { + Reset: { + Title: "Reset All Settings", + SubTitle: "Reset all setting items to default", + Action: "Reset", + Confirm: "Confirm to reset all settings to default?", + }, + Clear: { + Title: "Clear All Data", + SubTitle: "Clear all messages and settings", + Action: "Clear", + Confirm: "Confirm to clear all messages and settings?", + }, }, Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` diff --git a/app/locales/es.ts b/app/locales/es.ts index 4f89208b..e7f8cca4 100644 --- a/app/locales/es.ts +++ b/app/locales/es.ts @@ -61,13 +61,7 @@ const es: PartialLocaleType = { Settings: { Title: "Configuración", SubTitle: "Todas las configuraciones", - Actions: { - ClearAll: "Borrar todos los datos", - ResetAll: "Restablecer todas las configuraciones", - Close: "Cerrar", - ConfirmResetAll: "Are you sure you want to reset all configurations?", - ConfirmClearAll: "Are you sure you want to reset all chat?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Todos los idiomas", diff --git a/app/locales/fr.ts b/app/locales/fr.ts index db5e3544..b6b8c032 100644 --- a/app/locales/fr.ts +++ b/app/locales/fr.ts @@ -61,14 +61,7 @@ const fr: PartialLocaleType = { Settings: { Title: "Paramètres", SubTitle: "Toutes les configurations", - Actions: { - ClearAll: "Effacer toutes les données", - ResetAll: "Réinitialiser les configurations", - Close: "Fermer", - ConfirmResetAll: - "Êtes-vous sûr de vouloir réinitialiser toutes les configurations?", - ConfirmClearAll: "Êtes-vous sûr de vouloir supprimer toutes les données?", - }, + Lang: { Name: "Language", // ATTENTION : si vous souhaitez ajouter une nouvelle traduction, ne traduisez pas cette valeur, laissez-la sous forme de `Language` All: "Toutes les langues", diff --git a/app/locales/it.ts b/app/locales/it.ts index 72206754..8962968a 100644 --- a/app/locales/it.ts +++ b/app/locales/it.ts @@ -61,13 +61,7 @@ const it: PartialLocaleType = { Settings: { Title: "Impostazioni", SubTitle: "Tutte le impostazioni", - Actions: { - ClearAll: "Cancella tutti i dati", - ResetAll: "Resetta tutte le impostazioni", - Close: "Chiudi", - ConfirmResetAll: "Sei sicuro vuoi cancellare tutte le impostazioni?", - ConfirmClearAll: "Sei sicuro vuoi cancellare tutte le chat?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Tutte le lingue", diff --git a/app/locales/jp.ts b/app/locales/jp.ts index 02a0bf86..cf0f1d7a 100644 --- a/app/locales/jp.ts +++ b/app/locales/jp.ts @@ -61,13 +61,7 @@ const jp: PartialLocaleType = { Settings: { Title: "設定", SubTitle: "設定オプション", - Actions: { - ClearAll: "すべてのデータをクリア", - ResetAll: "すべてのオプションをリセット", - Close: "閉じる", - ConfirmResetAll: "すべての設定をリセットしてもよろしいですか?", - ConfirmClearAll: "すべてのチャットをリセットしてもよろしいですか?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "全ての言語", diff --git a/app/locales/ko.ts b/app/locales/ko.ts index 8985fcfb..a3a5f73d 100644 --- a/app/locales/ko.ts +++ b/app/locales/ko.ts @@ -61,13 +61,7 @@ const ko: PartialLocaleType = { Settings: { Title: "설정", SubTitle: "모든 설정", - Actions: { - ClearAll: "모든 데이터 지우기", - ResetAll: "모든 설정 초기화", - Close: "닫기", - ConfirmResetAll: "모든 설정을 초기화하시겠습니까?", - ConfirmClearAll: "모든 데이터를 지우시겠습니까?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "All Languages", diff --git a/app/locales/no.ts b/app/locales/no.ts index f46a454f..b296bd5c 100644 --- a/app/locales/no.ts +++ b/app/locales/no.ts @@ -56,11 +56,7 @@ const no: PartialLocaleType = { Settings: { Title: "Innstillinger", SubTitle: "Alle innstillinger", - Actions: { - ClearAll: "Fjern alle data", - ResetAll: "Nullstill innstillinger", - Close: "Lukk", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` }, diff --git a/app/locales/ru.ts b/app/locales/ru.ts index fcc494c0..9121e278 100644 --- a/app/locales/ru.ts +++ b/app/locales/ru.ts @@ -61,13 +61,7 @@ const ru: PartialLocaleType = { Settings: { Title: "Настройки", SubTitle: "Все настройки", - Actions: { - ClearAll: "Очистить все данные", - ResetAll: "Сбросить все настройки", - Close: "Закрыть", - ConfirmResetAll: "Вы уверены, что хотите сбросить все настройки?", - ConfirmClearAll: "Вы уверены, что хотите очистить все данные?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Все языки", diff --git a/app/locales/tr.ts b/app/locales/tr.ts index fb49b64c..e199f115 100644 --- a/app/locales/tr.ts +++ b/app/locales/tr.ts @@ -61,13 +61,7 @@ const tr: PartialLocaleType = { Settings: { Title: "Ayarlar", SubTitle: "Tüm Ayarlar", - Actions: { - ClearAll: "Tüm Verileri Temizle", - ResetAll: "Tüm Ayarları Sıfırla", - Close: "Kapat", - ConfirmResetAll: "Tüm ayarları sıfırlamak istediğinizden emin misiniz?", - ConfirmClearAll: "Tüm sohbeti sıfırlamak istediğinizden emin misiniz?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Tüm Diller", diff --git a/app/locales/tw.ts b/app/locales/tw.ts index adc2767e..cb92a81d 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -59,13 +59,7 @@ const tw: PartialLocaleType = { Settings: { Title: "設定", SubTitle: "設定選項", - Actions: { - ClearAll: "清除所有資料", - ResetAll: "重設所有設定", - Close: "關閉", - ConfirmResetAll: "您確定要重設所有設定嗎?", - ConfirmClearAll: "您確定要清除所有数据嗎?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "所有语言", diff --git a/app/locales/vi.ts b/app/locales/vi.ts index fea4545d..cc0178b1 100644 --- a/app/locales/vi.ts +++ b/app/locales/vi.ts @@ -61,13 +61,7 @@ const vi: PartialLocaleType = { Settings: { Title: "Cài đặt", SubTitle: "Tất cả cài đặt", - Actions: { - ClearAll: "Xóa toàn bộ dữ liệu", - ResetAll: "Khôi phục cài đặt gốc", - Close: "Đóng", - ConfirmResetAll: "Bạn chắc chắn muốn thiết lập lại tất cả cài đặt?", - ConfirmClearAll: "Bạn chắc chắn muốn thiết lập lại tất cả dữ liệu?", - }, + Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "Tất cả ngôn ngữ", From b044e274aa0ae8eb450042cfe31be2f201c8a754 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Thu, 29 Jun 2023 01:31:27 +0800 Subject: [PATCH 6/6] feat: close #2136 click avatar to edit message --- app/components/chat.module.scss | 23 +++++++++++++++++++++++ app/components/chat.tsx | 20 ++++++++++++++++++++ app/locales/cn.ts | 1 + app/locales/en.ts | 1 + 4 files changed, 45 insertions(+) diff --git a/app/components/chat.module.scss b/app/components/chat.module.scss index b908f220..a56c1c69 100644 --- a/app/components/chat.module.scss +++ b/app/components/chat.module.scss @@ -251,6 +251,12 @@ display: flex; flex-direction: column; align-items: flex-start; + + &:hover { + .chat-message-edit { + opacity: 0.9; + } + } } .chat-message-user > .chat-message-container { @@ -259,6 +265,23 @@ .chat-message-avatar { margin-top: 20px; + position: relative; + + .chat-message-edit { + position: absolute; + height: 100%; + width: 100%; + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; + opacity: 0; + transition: all ease 0.3s; + + button { + padding: 7px; + } + } } .chat-message-status { diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 7f785387..f6746217 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -23,6 +23,7 @@ import BreakIcon from "../icons/break.svg"; import SettingsIcon from "../icons/chat-settings.svg"; import DeleteIcon from "../icons/clear.svg"; import PinIcon from "../icons/pin.svg"; +import EditIcon from "../icons/rename.svg"; import LightIcon from "../icons/light.svg"; import DarkIcon from "../icons/dark.svg"; @@ -902,6 +903,25 @@ export function Chat() { >
+
+ } + onClick={async () => { + const newMessage = await showPrompt( + Locale.Chat.Actions.Edit, + message.content, + ); + chatStore.updateCurrentSession((session) => { + const m = session.messages.find( + (m) => m.id === message.id, + ); + if (m) { + m.content = newMessage; + } + }); + }} + > +
{message.role === "user" ? ( ) : ( diff --git a/app/locales/cn.ts b/app/locales/cn.ts index d8b4bd0f..f567f6d2 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -29,6 +29,7 @@ const cn = { PinToastContent: "已将 2 条对话固定至预设提示词", PinToastAction: "查看", Delete: "删除", + Edit: "编辑", }, Commands: { new: "新建聊天", diff --git a/app/locales/en.ts b/app/locales/en.ts index 3b6b7ff6..d0b96dba 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -30,6 +30,7 @@ const en: LocaleType = { PinToastContent: "Pinned 2 messages to contextual prompts", PinToastAction: "View", Delete: "Delete", + Edit: "Edit", }, Commands: { new: "Start a new chat",