Skip to content

Commit 8007ba0

Browse files
refactor(frontend): remove dead code, deduplicate error handling, tighten utility exports
1 parent 653846d commit 8007ba0

12 files changed

Lines changed: 31 additions & 65 deletions

File tree

content-gen/src/app/frontend/src/api/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ export async function* streamGenerateContent(
122122
}, { signal });
123123
const taskId = startData.task_id;
124124

125-
console.debug(`Generation started with task ID: ${taskId}`);
126-
127125
// Yield initial status
128126
yield {
129127
type: 'status',

content-gen/src/app/frontend/src/components/ChatHistory.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export const ChatHistory = memo(function ChatHistory({
7575
try {
7676
await dispatch(clearAllConversations()).unwrap();
7777
onNewConversation();
78-
} catch (err) {
79-
console.error('Error clearing all conversations:', err);
78+
} catch {
79+
// Error clearing all conversations
8080
}
8181
}, [dispatch, onNewConversation]);
8282

@@ -86,16 +86,16 @@ export const ChatHistory = memo(function ChatHistory({
8686
if (conversationId === currentConversationId) {
8787
onNewConversation();
8888
}
89-
} catch (err) {
90-
console.error('Error deleting conversation:', err);
89+
} catch {
90+
// Error deleting conversation
9191
}
9292
}, [dispatch, currentConversationId, onNewConversation]);
9393

9494
const handleRenameConversation = useCallback(async (conversationId: string, newTitle: string) => {
9595
try {
9696
await dispatch(renameConversation({ conversationId, newTitle })).unwrap();
97-
} catch (err) {
98-
console.error('Error renaming conversation:', err);
97+
} catch {
98+
// Error renaming conversation
9999
}
100100
}, [dispatch]);
101101

content-gen/src/app/frontend/src/hooks/useChatOrchestrator.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, type MutableRefObject } from 'react';
22

33
import type { GeneratedContent } from '../types';
4-
import { createMessage, matchesAnyKeyword, createNameSwapper } from '../utils';
4+
import { createMessage, createErrorMessage, matchesAnyKeyword, createNameSwapper } from '../utils';
55
import {
66
useAppDispatch,
77
useAppSelector,
@@ -467,14 +467,11 @@ export function useChatOrchestrator(
467467
}
468468
} catch (error) {
469469
if (error instanceof Error && error.name === 'AbortError') {
470-
console.debug('Request cancelled by user');
471470
dispatch(addMessage(createMessage('assistant', 'Generation stopped.')));
472471
} else {
473-
console.error('Error sending message:', error);
474472
dispatch(
475473
addMessage(
476-
createMessage(
477-
'assistant',
474+
createErrorMessage(
478475
'Sorry, there was an error processing your request. Please try again.',
479476
),
480477
),

content-gen/src/app/frontend/src/hooks/useContentGeneration.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, type MutableRefObject } from 'react';
22

3-
import { createMessage, buildGeneratedContent } from '../utils';
3+
import { createMessage, createErrorMessage, buildGeneratedContent } from '../utils';
44
import {
55
useAppDispatch,
66
useAppSelector,
@@ -66,25 +66,21 @@ export function useContentGeneration(
6666
const genContent = buildGeneratedContent(rawContent);
6767
dispatch(setGeneratedContent(genContent));
6868
dispatch(setGenerationStatus(''));
69-
} catch (parseError) {
70-
console.error('Error parsing generated content:', parseError);
69+
} catch {
70+
// Content parse failure — non-critical, generation result may be malformed
7171
}
7272
} else if (response.type === 'error') {
7373
dispatch(setGenerationStatus(''));
74-
dispatch(addMessage(createMessage(
75-
'assistant',
74+
dispatch(addMessage(createErrorMessage(
7675
`Error generating content: ${response.content}`,
7776
)));
7877
}
7978
}
8079
} catch (error) {
8180
if (error instanceof Error && error.name === 'AbortError') {
82-
console.debug('Content generation cancelled by user');
8381
dispatch(addMessage(createMessage('assistant', 'Content generation stopped.')));
8482
} else {
85-
console.error('Error generating content:', error);
86-
dispatch(addMessage(createMessage(
87-
'assistant',
83+
dispatch(addMessage(createErrorMessage(
8884
'Sorry, there was an error generating content. Please try again.',
8985
)));
9086
}

content-gen/src/app/frontend/src/hooks/useConversationActions.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,8 @@ export function useConversationActions() {
9696
products?: Product[];
9797
}>('/products');
9898
dispatch(setAvailableProducts(productsData.products || []));
99-
} catch (err) {
100-
console.error(
101-
'Error loading products for restored conversation:',
102-
err,
103-
);
99+
} catch {
100+
// Non-critical — product load failure for restored conversation
104101
}
105102
}
106103

@@ -122,8 +119,8 @@ export function useConversationActions() {
122119
dispatch(setGeneratedContent(null));
123120
dispatch(setSelectedProducts([]));
124121
}
125-
} catch (error) {
126-
console.error('Error loading conversation:', error);
122+
} catch {
123+
// Error loading conversation — swallowed silently
127124
}
128125
},
129126
[userId, dispatch],
@@ -164,8 +161,8 @@ export function useConversationActions() {
164161
),
165162
),
166163
);
167-
} catch (error) {
168-
console.error('Error confirming brief:', error);
164+
} catch {
165+
// Error confirming brief — swallowed silently
169166
}
170167
}, [conversationId, userId, pendingBrief, dispatch]);
171168

content-gen/src/app/frontend/src/hooks/useCopyToClipboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export function useCopyToClipboard(resetTimeout = 2000) {
1313

1414
const copy = useCallback(
1515
(text: string) => {
16-
navigator.clipboard.writeText(text).catch((err) => {
17-
console.error('Failed to copy text:', err);
16+
navigator.clipboard.writeText(text).catch(() => {
17+
// Clipboard write failure — non-critical
1818
});
1919
setCopied(true);
2020
clearTimeout(timerRef.current);

content-gen/src/app/frontend/src/store/chatHistorySlice.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ const chatHistorySlice = createSlice({
7878
setShowAll(state, action: PayloadAction<boolean>) {
7979
state.showAll = action.payload;
8080
},
81-
setConversations(state, action: PayloadAction<ConversationSummary[]>) {
82-
state.conversations = action.payload;
83-
},
84-
upsertConversation(state, action: PayloadAction<ConversationSummary>) {
85-
const idx = state.conversations.findIndex((c) => c.id === action.payload.id);
86-
if (idx >= 0) {
87-
state.conversations[idx] = action.payload;
88-
} else {
89-
state.conversations.unshift(action.payload);
90-
}
91-
},
9281
setIsClearAllDialogOpen(state, action: PayloadAction<boolean>) {
9382
state.isClearAllDialogOpen = action.payload;
9483
},
@@ -133,6 +122,6 @@ const chatHistorySlice = createSlice({
133122
},
134123
});
135124

136-
export const { setShowAll, setConversations, upsertConversation, setIsClearAllDialogOpen } =
125+
export const { setShowAll, setIsClearAllDialogOpen } =
137126
chatHistorySlice.actions;
138127
export default chatHistorySlice.reducer;

content-gen/src/app/frontend/src/store/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export {
4444
renameConversation,
4545
clearAllConversations,
4646
setShowAll,
47-
setConversations,
48-
upsertConversation,
4947
setIsClearAllDialogOpen,
5048
} from './chatHistorySlice';
5149
export type { ConversationSummary } from './chatHistorySlice';
-4.82 KB
Binary file not shown.

content-gen/src/app/frontend/src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// Message factories & formatting
8-
export { createMessage, formatContentForClipboard } from './messageUtils';
8+
export { createMessage, createErrorMessage } from './messageUtils';
99

1010
// Content parsing (raw API → typed domain objects)
1111
export { parseTextContent, resolveImageUrl, buildGeneratedContent } from './contentParsing';
@@ -21,7 +21,7 @@ export type { GenerationStage } from './generationStages';
2121
export { BRIEF_FIELD_LABELS, BRIEF_DISPLAY_ORDER, BRIEF_FIELD_KEYS } from './briefFields';
2222

2323
// String utilities
24-
export { escapeRegex, createNameSwapper, matchesAnyKeyword } from './stringUtils';
24+
export { createNameSwapper, matchesAnyKeyword } from './stringUtils';
2525

2626
// Production API utilities
2727
export { retryRequest, RequestCache, throttle } from './apiUtils';

0 commit comments

Comments
 (0)