lobehub/src/features/ChatInput/ActionBar/SaveTopic/index.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

♻️ refactor(desktop): consolidate global shortcuts (LOBE-7181) (#13880) * ♻️ refactor(desktop): consolidate global shortcuts and remove default showApp hotkey - Add desktopGlobalShortcuts.ts as single source for Electron + renderer defaults - Wire ShortcutManager and store to DEFAULT_ELECTRON_DESKTOP_SHORTCUTS - Use DesktopHotkeyId for @shortcut; drop local shortcuts barrel - Stop re-exporting DESKTOP_HOTKEYS_REGISTRATION from hotkeys Fixes LOBE-7181 Made-with: Cursor * ✨ feat(desktop): introduce new stubs for business constants and types - Added `@lobechat/business-const` and `@lobechat/types` packages to support workspace dependency resolution. - Updated `package.json` and `pnpm-workspace.yaml` to include new stubs. - Refactored imports in `index.ts` to utilize the new constants structure. - Enhanced `desktopGlobalShortcuts.ts` with improved type definitions for hotkeys. This change streamlines the management of constants and types across the desktop application. Signed-off-by: Innei <tukon479@gmail.com> * ♻️ refactor(hotkeys): consolidate desktop global shortcut definitions (LOBE-7181) Made-with: Cursor * ✨ feat(session, user): replace direct type imports with constants - Updated session.ts to use constants for session types instead of direct imports from @lobechat/types. - Updated user.ts to use a constant for the default topic display mode, enhancing consistency and maintainability. This change improves code clarity and reduces dependencies on external type definitions. Signed-off-by: Innei <tukon479@gmail.com> --------- Signed-off-by: Innei <tukon479@gmail.com>
2026-04-16 16:32:05 +00:00
import { HotkeyEnum } from '@lobechat/const/hotkeys';
2025-12-21 14:39:01 +00:00
import { ActionIcon, Flexbox, Hotkey } from '@lobehub/ui';
import { Popconfirm } from 'antd';
import { LucideGalleryVerticalEnd, LucideMessageSquarePlus } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '@/hooks/useIsMobile';
import { useActionSWR } from '@/libs/swr';
✨ feat: refactor the persist layer from zustand's persist to dexie ORM (#500) * :art: chore: clean code * :card_file_box: refactor: make sure the db schema * :construction: wip: update the sessions service * ♻️ refactor: improve base model core * ♻️ refactor: 初步完成 sessions 重构为 dexie 版本 * ♻️ refactor: 合并 inbox 与 sessions 数据结构 * 🚚 refactor: move chat to the chatStore * 🚚 refactor: refactor to the useChatStore usage * 🚚 refactor: 初步完成 chatStore 提取改造 * 🚚 refactor: 实现 chat model与 message service ,基本完成 store 改造 * 🚚 refactor: 实现 topic model与 topic service * 🎨 refactor: 优化数据库部分实现逻辑 * ✅ test: 修正测试,补齐 models 层单测到 100% * 💚 ci: 修正大部分 type 错误 * 🗃️ feat: 初步实现数据迁移 * :art: chore: 优化导入与 schema 定义 * :label: fix: fix types * :bug: fix: 修正与插件的兼容性 * :bug: fix: 修正与图片文件的兼容性 * :label: chore: 修正大量类型问题 * :sparkles: feat: 完成导出功能 * 🚨 ci: fix lint * 🐛 fix: 修正重构遗留 bug * 🐛 fix: 修正更新 agent config 的问题 * 🗃️ fix: 完善数据迁移逻辑 * 🎨 chore: 优化迁移模块代码 * :recycle: refactor: 重构 configService * :zap: perf: 移除 localStorage 存储 * ✨ feat: 新增迁移组件 * 🎨 chore: 完善迁移逻辑 * ✨ feat: 支持 sessions 的全文本字段搜索 * ✨ feat: 支持 topics 的全文本字段搜索 * :children_crossing: style: 完善 i18n 与错误反馈 * :zap: perf: 补充性能测试模块 * :iphone: style: 移动端样式兼容 * ✨ feat: 新增数据导入弹窗 * 🐛 fix: 修正 topic 排序问题 * 🐛 fix: 修正 inbox 没有正常响应的问题 * ✅ test: fix test * 🎨 chore: 优化 chatSelectors * :bug: fix: 迁移前数据仅备份不清空 * :globe_with_meridians: style: 优化国际化文案
2023-11-30 06:37:40 +00:00
import { useChatStore } from '@/store/chat';
import { useUserStore } from '@/store/user';
import { settingsSelectors } from '@/store/user/selectors';
const SaveTopic = memo(() => {
const { t } = useTranslation('chat');
const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.SaveTopic));
✨ feat: refactor the persist layer from zustand's persist to dexie ORM (#500) * :art: chore: clean code * :card_file_box: refactor: make sure the db schema * :construction: wip: update the sessions service * ♻️ refactor: improve base model core * ♻️ refactor: 初步完成 sessions 重构为 dexie 版本 * ♻️ refactor: 合并 inbox 与 sessions 数据结构 * 🚚 refactor: move chat to the chatStore * 🚚 refactor: refactor to the useChatStore usage * 🚚 refactor: 初步完成 chatStore 提取改造 * 🚚 refactor: 实现 chat model与 message service ,基本完成 store 改造 * 🚚 refactor: 实现 topic model与 topic service * 🎨 refactor: 优化数据库部分实现逻辑 * ✅ test: 修正测试,补齐 models 层单测到 100% * 💚 ci: 修正大部分 type 错误 * 🗃️ feat: 初步实现数据迁移 * :art: chore: 优化导入与 schema 定义 * :label: fix: fix types * :bug: fix: 修正与插件的兼容性 * :bug: fix: 修正与图片文件的兼容性 * :label: chore: 修正大量类型问题 * :sparkles: feat: 完成导出功能 * 🚨 ci: fix lint * 🐛 fix: 修正重构遗留 bug * 🐛 fix: 修正更新 agent config 的问题 * 🗃️ fix: 完善数据迁移逻辑 * 🎨 chore: 优化迁移模块代码 * :recycle: refactor: 重构 configService * :zap: perf: 移除 localStorage 存储 * ✨ feat: 新增迁移组件 * 🎨 chore: 完善迁移逻辑 * ✨ feat: 支持 sessions 的全文本字段搜索 * ✨ feat: 支持 topics 的全文本字段搜索 * :children_crossing: style: 完善 i18n 与错误反馈 * :zap: perf: 补充性能测试模块 * :iphone: style: 移动端样式兼容 * ✨ feat: 新增数据导入弹窗 * 🐛 fix: 修正 topic 排序问题 * 🐛 fix: 修正 inbox 没有正常响应的问题 * ✅ test: fix test * 🎨 chore: 优化 chatSelectors * :bug: fix: 迁移前数据仅备份不清空 * :globe_with_meridians: style: 优化国际化文案
2023-11-30 06:37:40 +00:00
const [hasTopic, openNewTopicOrSaveTopic] = useChatStore((s) => [
!!s.activeTopicId,
s.openNewTopicOrSaveTopic,
]);
const mobile = useIsMobile();
const { mutate, isValidating } = useActionSWR('openNewTopicOrSaveTopic', openNewTopicOrSaveTopic);
const [confirmOpened, setConfirmOpened] = useState(false);
const icon = hasTopic ? LucideMessageSquarePlus : LucideGalleryVerticalEnd;
const desc = t(hasTopic ? 'topic.openNewTopic' : 'topic.saveCurrentMessages');
2023-10-17 16:21:43 +00:00
if (mobile) {
return (
<Popconfirm
arrow={false}
okButtonProps={{ danger: false, type: 'primary' }}
open={confirmOpened}
placement={'top'}
title={
<Flexbox horizontal align={'center'} style={{ marginBottom: 8 }}>
<div style={{ marginRight: '16px', whiteSpace: 'pre-line', wordBreak: 'break-word' }}>
{t(hasTopic ? 'topic.checkOpenNewTopic' : 'topic.checkSaveCurrentMessages')}
</div>
<Hotkey keys={hotkey} />
</Flexbox>
}
onConfirm={() => mutate()}
onOpenChange={setConfirmOpened}
>
<ActionIcon
aria-label={desc}
icon={icon}
loading={isValidating}
onClick={() => setConfirmOpened(true)}
/>
</Popconfirm>
);
} else {
return (
<ActionIcon
aria-label={desc}
icon={icon}
loading={isValidating}
size={{ blockSize: 32, size: 16, strokeWidth: 2.3 }}
title={desc}
variant={'outlined'}
tooltipProps={{
hotkey,
}}
onClick={() => mutate()}
/>
);
}
});
SaveTopic.displayName = 'SaveTopic';
export default SaveTopic;