Skip to content

Commit 85b45cb

Browse files
authored
🐛 fix: improve topic item interaction and editing behavior (#10409)
♻️ refactor: improve topic item interaction and editing behavior
1 parent c58f37a commit 85b45cb

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/TopicContent.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ const TopicContent = memo<TopicContentProps>(({ id, title, fav, showMore }) => {
9797
},
9898
...(isDesktop
9999
? [
100-
{
101-
icon: <Icon icon={ExternalLink} />,
102-
key: 'openInNewWindow',
103-
label: t('actions.openInNewWindow'),
104-
onClick: () => {
105-
openTopicInNewWindow(activeId, id);
100+
{
101+
icon: <Icon icon={ExternalLink} />,
102+
key: 'openInNewWindow',
103+
label: t('actions.openInNewWindow'),
104+
onClick: () => {
105+
openTopicInNewWindow(activeId, id);
106+
},
106107
},
107-
},
108-
]
108+
]
109109
: []),
110110
{
111111
type: 'divider',
@@ -210,6 +210,13 @@ const TopicContent = memo<TopicContentProps>(({ id, title, fav, showMore }) => {
210210
) : (
211211
<EditableText
212212
editing={editing}
213+
onBlur={(e) => {
214+
const v = (e.target as HTMLInputElement).value;
215+
if (title !== v) {
216+
updateTopicTitle(id, v);
217+
}
218+
toggleEditing(false);
219+
}}
213220
onChangeEnd={(v) => {
214221
if (title !== v) {
215222
updateTopicTitle(id, v);

src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/index.tsx

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createStyles } from 'antd-style';
33
import qs from 'query-string';
44
import { Suspense, memo, useState } from 'react';
55
import { Flexbox } from 'react-layout-kit';
6-
import { Link } from 'react-router-dom';
76

87
import { useChatStore } from '@/store/chat';
98
import { useGlobalStore } from '@/store/global';
@@ -54,47 +53,45 @@ export interface ConfigCellProps {
5453
const TopicItem = memo<ConfigCellProps>(({ title, active, id, fav, threadId }) => {
5554
const { styles, cx } = useStyles();
5655
const toggleConfig = useGlobalStore((s) => s.toggleMobileTopic);
57-
const [toggleTopic] = useChatStore((s) => [s.switchTopic]);
56+
const [toggleTopic, editing] = useChatStore((s) => [s.switchTopic, s.topicRenamingId === id]);
5857
const activeId = useSessionStore((s) => s.activeId);
5958
const [isHover, setHovering] = useState(false);
6059

61-
const topicUrl = qs.stringifyUrl({
62-
query: id ? { session: activeId, topic: id } : { session: activeId },
63-
url: '/chat',
64-
});
65-
6660
return (
6761
<Flexbox style={{ position: 'relative' }}>
68-
<Link
62+
<Flexbox
63+
align={'center'}
64+
className={cx(styles.container, 'topic-item', active && !threadId && styles.active)}
65+
distribution={'space-between'}
66+
horizontal
6967
onClick={(e) => {
70-
if (e.button === 0 && (e.metaKey || e.ctrlKey)) {
68+
// 重命名时不切换话题
69+
if (editing) return;
70+
// Ctrl/Cmd+点击在新窗口打开
71+
if (e.button === 0 && (e.metaKey || e.ctrlKey) && id) {
72+
const topicUrl = qs.stringifyUrl({
73+
query: { session: activeId, topic: id },
74+
url: '/chat',
75+
});
76+
window.open(topicUrl, '_blank');
7177
return;
7278
}
73-
e.preventDefault();
7479
toggleTopic(id);
7580
toggleConfig(false);
7681
}}
77-
to={topicUrl}
82+
onMouseEnter={() => {
83+
setHovering(true);
84+
}}
85+
onMouseLeave={() => {
86+
setHovering(false);
87+
}}
7888
>
79-
<Flexbox
80-
align={'center'}
81-
className={cx(styles.container, 'topic-item', active && !threadId && styles.active)}
82-
distribution={'space-between'}
83-
horizontal
84-
onMouseEnter={() => {
85-
setHovering(true);
86-
}}
87-
onMouseLeave={() => {
88-
setHovering(false);
89-
}}
90-
>
91-
{!id ? (
92-
<DefaultContent />
93-
) : (
94-
<TopicContent fav={fav} id={id} showMore={isHover} title={title} />
95-
)}
96-
</Flexbox>
97-
</Link>
89+
{!id ? (
90+
<DefaultContent />
91+
) : (
92+
<TopicContent fav={fav} id={id} showMore={isHover} title={title} />
93+
)}
94+
</Flexbox>
9895
{active && (
9996
<Suspense
10097
fallback={

src/layout/GlobalProvider/StoreInitialization.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { createStoreUpdater } from 'zustand-utils';
99
import { useIsMobile } from '@/hooks/useIsMobile';
1010
import { useAgentStore } from '@/store/agent';
1111
import { useAiInfraStore } from '@/store/aiInfra';
12+
import { useElectronStore } from '@/store/electron';
13+
import { electronSyncSelectors } from '@/store/electron/selectors';
1214
import { useGlobalStore } from '@/store/global';
1315
import { useServerConfigStore } from '@/store/serverConfig';
1416
import { serverConfigSelectors } from '@/store/serverConfig/selectors';
1517
import { useUrlHydrationStore } from '@/store/urlHydration';
1618
import { useUserStore } from '@/store/user';
1719
import { authSelectors } from '@/store/user/selectors';
18-
import { electronSyncSelectors } from '@/store/electron/selectors';
19-
import { useElectronStore } from '@/store/electron';
2020

2121
const StoreInitialization = memo(() => {
2222
// prefetch error ns to avoid don't show error content correctly
@@ -68,7 +68,7 @@ const StoreInitialization = memo(() => {
6868
const isSyncActive = useElectronStore((s) => electronSyncSelectors.isSyncActive(s));
6969

7070
// init user provider key vaults
71-
useInitAiProviderKeyVaults(isLoginOnInit,isSyncActive);
71+
useInitAiProviderKeyVaults(isLoginOnInit, isSyncActive);
7272

7373
// init user state
7474
useInitUserState(isLoginOnInit, serverConfig, {

src/store/aiInfra/slices/aiProvider/action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ export const normalizeImageModel = async (
7777
const fallbackParametersPromise = model.parameters
7878
? Promise.resolve<ModelParamsSchema | undefined>(model.parameters)
7979
: getModelPropertyWithFallback<ModelParamsSchema | undefined>(
80-
model.id,
81-
'parameters',
82-
model.providerId,
83-
);
80+
model.id,
81+
'parameters',
82+
model.providerId,
83+
);
8484

8585
const modelWithPricing = model as AIImageModelCard;
8686
const fallbackPricingPromise = modelWithPricing.pricing

0 commit comments

Comments
 (0)