From 3a936e0f264593535bb0e52097d3f179e3083097 Mon Sep 17 00:00:00 2001 From: ousugo Date: Thu, 20 Feb 2025 04:04:46 +0800 Subject: [PATCH] feat: Add confirmation dialog for topic deletion --- src/renderer/src/i18n/locales/en-us.json | 1 + src/renderer/src/i18n/locales/ja-jp.json | 1 + src/renderer/src/i18n/locales/ru-ru.json | 1 + src/renderer/src/i18n/locales/zh-cn.json | 1 + src/renderer/src/i18n/locales/zh-tw.json | 1 + .../src/pages/home/Tabs/TopicsTab.tsx | 38 +++++++++++++------ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 1b61eabf..8f126924 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -139,6 +139,7 @@ "topics.pinned": "Pinned Topics", "topics.title": "Topics", "topics.unpinned": "Unpinned Topics", + "topics.delete.title": "Are you sure you want to delete this topic? This action cannot be undone", "translate": "Translate", "topics.prompt": "Topic Prompts", "topics.prompt.tips": "Topic Prompts: Additional supplementary prompts provided for the current topic", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 89c9d7d0..575981ce 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -139,6 +139,7 @@ "topics.pinned": "トピックを固定", "topics.title": "トピック", "topics.unpinned": "固定解除", + "topics.delete.title": "このトピックを削除してもよろしいですか?この操作は元に戻せません", "translate": "翻訳", "topics.prompt": "トピック提示語", "topics.prompt.tips": "トピック提示語:現在のトピックに対して追加の補足提示語を提供", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index b98332d6..b9dcee0f 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -139,6 +139,7 @@ "topics.pinned": "Закрепленные темы", "topics.title": "Топики", "topics.unpinned": "Открепленные темы", + "topics.delete.title": "Вы уверены, что хотите удалить этот топик? Это действие нельзя отменить", "translate": "Перевести", "topics.prompt": "Тематические подсказки", "topics.prompt.tips": "Тематические подсказки: Дополнительные подсказки, предоставленные для текущей темы", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 4f3b1fcf..04e469cd 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -141,6 +141,7 @@ "topics.pinned": "固定话题", "topics.title": "话题", "topics.unpinned": "取消固定", + "topics.delete.title": "确定要删除此话题吗?此操作无法撤销", "translate": "翻译", "topics.prompt": "话题提示词", "topics.prompt.tips": "话题提示词: 针对当前话题提供额外的补充提示词", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 3dc4ab99..14fb0b0b 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -139,6 +139,7 @@ "topics.pinned": "固定話題", "topics.title": "話題", "topics.unpinned": "取消固定", + "topics.delete.title": "確定要刪除此話題嗎?此操作無法撤銷", "translate": "翻譯", "topics.prompt": "話題提示詞", "topics.prompt.tips": "話題提示詞:針對目前話題提供額外的補充提示詞", diff --git a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx index 592d0d79..543d04fa 100644 --- a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx @@ -21,7 +21,7 @@ import store from '@renderer/store' import { setGenerating } from '@renderer/store/runtime' import { Assistant, Topic } from '@renderer/types' import { exportTopicAsMarkdown, exportTopicToNotion, topicToMarkdown } from '@renderer/utils/export' -import { Dropdown, MenuProps, Tooltip } from 'antd' +import { Dropdown, MenuProps, Popconfirm, Tooltip } from 'antd' import dayjs from 'dayjs' import { findIndex } from 'lodash' import { FC, useCallback } from 'react' @@ -54,7 +54,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic async (topic: Topic) => { await modelGenerating() const index = findIndex(assistant.topics, (t) => t.id === topic.id) - setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1]) + setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? index - 1 : index + 1]) removeTopic(topic) }, [assistant.topics, removeTopic, setActiveTopic] @@ -219,7 +219,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic return menus }, - [assistant, assistants, onClearMessages, onPinTopic, onDeleteTopic, onMoveTopic, t, updateTopic] + [assistant, assistants, onClearMessages, onDeleteTopic, onPinTopic, onMoveTopic, t, updateTopic] ) return ( @@ -244,17 +244,33 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic )} {topic.pinned && } {isActive && !topic.pinned && ( - { - e.stopPropagation() + { + e?.stopPropagation() if (assistant.topics.length === 1) { return onClearMessages() } - onDeleteTopic(topic) - }}> - - + await modelGenerating() + const index = findIndex(assistant.topics, (t) => t.id === topic.id) + setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? index - 1 : index + 1]) + removeTopic(topic) + }} + onCancel={(e) => e?.stopPropagation()}> + { + e.stopPropagation() + if (assistant.topics.length === 1) { + return onClearMessages() + } + }}> + + + )}