Skip to content

Commit 56443cf

Browse files
committed
chore: start over
1 parent 5605148 commit 56443cf

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

examples/ai-conference-assistant/src/app/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export default function Home() {
4747
sessionData={sessionDataRef}
4848
onSessionDataChange={setSessionData}
4949
onGenerated={setGeneratedData}
50+
onChatReset={() => {
51+
setGeneratedData(null)
52+
setPreviewPage(null)
53+
}}
5054
onCreateNotes={() => setShowProgress(true)}
5155
onPreviewPage={setPreviewPage}
5256
generatedData={generatedData}

examples/ai-conference-assistant/src/components/chat-panel.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ interface ChatPanelProps {
3636
sessionData: MutableRefObject<string>
3737
onSessionDataChange: (data: string) => void
3838
onGenerated: (data: GeneratedData) => void
39+
/** Clear preview in parent when user resets the chat. */
40+
onChatReset: () => void
3941
onCreateNotes: () => void
4042
onPreviewPage: (page: { title: string; content: string }) => void
4143
generatedData: GeneratedData | null
@@ -48,6 +50,7 @@ export function ChatPanel({
4850
sessionData,
4951
onSessionDataChange,
5052
onGenerated,
53+
onChatReset,
5154
onCreateNotes,
5255
onPreviewPage,
5356
generatedData,
@@ -98,7 +101,7 @@ export function ChatPanel({
98101
})
99102
}, [config.apiKey, config.apiEndpoint, config.teamPath, prepareSendMessagesRequest])
100103

101-
const { messages, sendMessage, status, error } = useChat({
104+
const { messages, sendMessage, status, error, setMessages, stop, clearError } = useChat({
102105
transport,
103106
})
104107

@@ -184,6 +187,21 @@ export function ChatPanel({
184187
}
185188
}
186189

190+
const canStartOver = messages.length > 0 || generatedData !== null
191+
192+
function handleStartOver() {
193+
if (!canStartOver) return
194+
if (!window.confirm(t('chat.startOverConfirm'))) return
195+
if (status === 'submitted' || status === 'streaming') {
196+
stop()
197+
}
198+
clearError()
199+
setMessages([])
200+
previewAppliedRef.current = null
201+
setInputValue('')
202+
onChatReset()
203+
}
204+
187205
return (
188206
<div className="flex h-full flex-col bg-zinc-50/80 dark:bg-zinc-950/50">
189207
{/* Header */}
@@ -197,6 +215,16 @@ export function ChatPanel({
197215
</span>
198216
</div>
199217
<div className="flex shrink-0 items-center gap-2">
218+
{canStartOver && (
219+
<button
220+
type="button"
221+
onClick={handleStartOver}
222+
title={t('chat.startOverTitle')}
223+
className="rounded-lg border border-zinc-300 bg-white px-2.5 py-1.5 text-xs font-medium text-zinc-700 transition hover:bg-zinc-50 dark:border-zinc-600 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800 sm:px-3 sm:text-sm"
224+
>
225+
{t('chat.startOver')}
226+
</button>
227+
)}
200228
<AppSettingsBar className="hidden sm:inline-flex" />
201229
{generatedData && (
202230
<button
@@ -213,7 +241,17 @@ export function ChatPanel({
213241
)}
214242
</div>
215243
</div>
216-
<div className="flex justify-end border-b border-zinc-200/60 px-4 py-2 dark:border-zinc-800 sm:hidden">
244+
<div className="flex justify-end gap-2 border-b border-zinc-200/60 px-4 py-2 dark:border-zinc-800 sm:hidden">
245+
{canStartOver && (
246+
<button
247+
type="button"
248+
onClick={handleStartOver}
249+
title={t('chat.startOverTitle')}
250+
className="rounded-lg border border-zinc-300 bg-white px-2.5 py-1.5 text-xs font-medium text-zinc-700 transition hover:bg-zinc-50 dark:border-zinc-600 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800"
251+
>
252+
{t('chat.startOver')}
253+
</button>
254+
)}
217255
<AppSettingsBar />
218256
</div>
219257

examples/ai-conference-assistant/src/i18n/dictionaries.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export const en = {
6262
placeholderWithFile: 'Message… (Shift+Enter for new line, Enter to send)',
6363
placeholderNoFile: 'Upload session data or ask anything… (Shift+Enter for new line)',
6464
invalidJson: 'Invalid JSON file. Please upload a valid JSON file.',
65+
startOver: 'Start over',
66+
startOverTitle: 'Clear chat and preview (uploaded session file is kept)',
67+
startOverConfirm:
68+
'Clear this conversation and the preview? Your uploaded session file will stay loaded.',
6569
},
6670
preview: {
6771
empty: 'No preview yet.',
@@ -156,6 +160,9 @@ export const zhTW: Messages = {
156160
placeholderWithFile: '輸入訊息…(Shift+Enter 換行,Enter 送出)',
157161
placeholderNoFile: '上傳場次資料或任意提問…(Shift+Enter 換行)',
158162
invalidJson: '不是有效的 JSON 檔案,請上傳正確的 JSON。',
163+
startOver: '重新開始',
164+
startOverTitle: '清除對話與預覽(已上傳的場次檔會保留)',
165+
startOverConfirm: '要清除對話與右側預覽嗎?已上傳的場次檔會保留。',
159166
},
160167
preview: {
161168
empty: '尚無預覽。',

0 commit comments

Comments
 (0)