Skip to content

Commit 770d3d7

Browse files
committed
Simplify
1 parent 2f9ea56 commit 770d3d7

2 files changed

Lines changed: 9 additions & 32 deletions

File tree

src/renderer/components/Sidebar.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React from 'react';
22

33
import { DraftsIcon, FolderIcon, PublishedIcon, TasksIcon } from '../icons';
44

5-
import { CHAT_ACTIONS } from '../../chat-actions';
6-
import type { ChatKind, RecentChat } from '../../types';
5+
import type { RecentChat } from '../../types';
76

87
import { TopActions } from './TopActions';
98

@@ -22,11 +21,6 @@ type SidebarProps = {
2221
onSelectView: ( view: View ) => void;
2322
};
2423

25-
const KIND_LABEL: Record< ChatKind, string > = {
26-
general: 'Untitled',
27-
...Object.fromEntries( CHAT_ACTIONS.map( ( a ) => [ a.id, a.chatTitle ] ) ),
28-
} as Record< ChatKind, string >;
29-
3024
export function Sidebar( {
3125
isOpen,
3226
onToggle,
@@ -125,8 +119,7 @@ export function Sidebar( {
125119
) : (
126120
recentChats.map( ( entry ) => {
127121
const label =
128-
entry.chat.title?.trim() ||
129-
KIND_LABEL[ entry.chat.kind ];
122+
entry.chat.title?.trim() || 'Untitled';
130123
const isActive =
131124
entry.projectId === activeProjectId &&
132125
entry.chat.id === activeChatId &&

src/renderer/screens/ProjectScreen.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,18 @@ function groupMessages( messages: Message[] ): TranscriptItem[] {
7171

7272
function computeChatLabels( chats: ChatMeta[] ): Map< string, string > {
7373
const labels = new Map< string, string >();
74-
const untitledByKind = new Map< ChatMeta[ 'kind' ], number >();
75-
for ( const c of chats ) {
76-
if ( c.title ) {
77-
continue;
78-
}
79-
untitledByKind.set( c.kind, ( untitledByKind.get( c.kind ) ?? 0 ) + 1 );
80-
}
81-
const seenByKind = new Map< ChatMeta[ 'kind' ], number >();
74+
const untitledTotal = chats.filter( ( c ) => ! c.title ).length;
75+
let untitledSeen = 0;
8276
for ( const c of chats ) {
8377
if ( c.title ) {
8478
labels.set( c.id, c.title );
8579
continue;
8680
}
87-
const kindBase: Record< ChatMeta[ 'kind' ], string > = {
88-
general: 'Untitled',
89-
...Object.fromEntries(
90-
CHAT_ACTIONS.map( ( a ) => [ a.id, a.chatTitle ] )
91-
),
92-
} as Record< ChatMeta[ 'kind' ], string >;
93-
const base = kindBase[ c.kind ];
94-
const total = untitledByKind.get( c.kind ) ?? 1;
95-
if ( total === 1 ) {
96-
labels.set( c.id, base );
97-
} else {
98-
const idx = ( seenByKind.get( c.kind ) ?? 0 ) + 1;
99-
seenByKind.set( c.kind, idx );
100-
labels.set( c.id, `${ base } ${ idx }` );
101-
}
81+
untitledSeen += 1;
82+
labels.set(
83+
c.id,
84+
untitledTotal === 1 ? 'Untitled' : `Untitled ${ untitledSeen }`
85+
);
10286
}
10387
return labels;
10488
}

0 commit comments

Comments
 (0)