Skip to content

Commit 3588f2d

Browse files
committed
feat: add clear messages confirm modal
1 parent ab6cced commit 3588f2d

File tree

8 files changed

+61
-8
lines changed

8 files changed

+61
-8
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
import { useStore } from '@nanostores/solid'
22
import { currentConversationId } from '@/stores/conversation'
3-
import { scrollController } from '@/stores/ui'
3+
import {
4+
scrollController,
5+
showConfirmModal,
6+
} from '@/stores/ui'
47
import { clearMessagesByConversationId } from '@/stores/messages'
8+
import { useI18n } from '@/hooks'
9+
import ConfirmModal from '../ui/ConfirmModal'
510

611
export default () => {
712
const $currentConversationId = useStore(currentConversationId)
13+
const { t } = useI18n()
814

915
const handleClearMessage = () => {
1016
clearMessagesByConversationId($currentConversationId())
1117
scrollController().scrollToBottom()
18+
showConfirmModal.set(false)
1219
}
1320

1421
return (
1522
<>
1623
{ $currentConversationId() && (
1724
<div
1825
class="fcc p-2 rounded-md text-xl hv-foreground"
19-
onClick={handleClearMessage}
26+
onClick={() => { showConfirmModal.set(true) }}
2027
>
2128
<div i-carbon-clean />
2229
</div>
2330
)}
31+
<ConfirmModal title={t('conversations.confirm.title')} description={t('conversations.confirm.desc')} onConfirm={handleClearMessage} onCancel={() => { showConfirmModal.set(false) }} />
2432
</>
2533
)
2634
}

src/components/main/Conversation.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default () => {
3333
<Switch
3434
fallback={(
3535
<Welcome />
36-
)}
36+
)}
3737
>
3838
<Match when={$currentConversationId() && !currentConversationMessages().length}>
3939
<ConversationEmpty conversation={currentConversation()} />
@@ -52,9 +52,8 @@ export default () => {
5252
</Match>
5353
<Match when={currentBot()?.type === 'image_generation'}>
5454
<Image
55-
// conversationId={$currentConversationId()}
55+
// conversationId={$currentConversationId()}
5656
messages={currentConversationMessages}
57-
// fetching={isLoading() || !isStreaming()}
5857
/>
5958
</Match>
6059
</Switch>

src/components/ui/ConfirmModal.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
showConfirmModal,
3+
} from '@/stores/ui'
4+
import { useI18n } from '@/hooks'
5+
import Modal from './Modal'
6+
7+
interface Props {
8+
title: string
9+
description: string
10+
onConfirm: () => void
11+
onCancel: () => void
12+
}
13+
14+
export default (props: Props) => {
15+
const { t } = useI18n()
16+
return (
17+
<Modal bindValue={showConfirmModal} direction="bottom" closeBtnClass="top-6 right-6" hiddenCloseIcon>
18+
<div class="max-h-[70vh] w-full">
19+
<div class="grid w-full max-w-lg scale-100 gap-4 border-base sm:border bg-white dark:bg-zinc-900/90 dark:backdrop-blur-lg p-6 opacity-100 shadow-lg sm:rounded-lg md:w-full">
20+
<div class="flex flex-col space-y-2 text-center sm:text-left"><h2 id="radix-:rl:" class="text-lg font-semibold">{props.title}</h2><p id="radix-:rm:" class="text-sm text-muted-foreground">{props.description}</p></div>
21+
<div class="flex flex-col-reverse sm:flex-row sm:justify-end gap-2">
22+
<button class="button" onClick={() => props.onCancel()}>{t('conversations.confirm.cancel')}</button>
23+
<button class="emerald-button" onClick={() => props.onConfirm()}>{t('conversations.confirm.btn')}</button>
24+
</div>
25+
</div>
26+
</div>
27+
</Modal>
28+
)
29+
}

src/components/ui/Modal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props {
1111
direction: 'top' | 'bottom' | 'left' | 'right'
1212
children: JSXElement
1313
closeBtnClass?: string
14+
hiddenCloseIcon?: boolean
1415
}
1516

1617
export default (props: Props) => {
@@ -45,9 +46,9 @@ export default (props: Props) => {
4546
</Portal>
4647
<div {...api().containerProps}>
4748
<div {...api().contentProps} class={`bg-modal transition-transform ease-out max-w-screen max-h-screen overflow-auto border-base shadow-lg ring-0 outline-none ${containerBaseClass}`}>
48-
<button {...api().closeTriggerProps} class={`absolute p-1 rounded-md top-4 right-4 hv-base hv-foreground ${props.closeBtnClass || ''}`}>
49-
<div i-carbon-close class="text-xl" />
50-
</button>
49+
{
50+
!props.hiddenCloseIcon && <button {...api().closeTriggerProps} class={`absolute p-1 rounded-md top-4 right-4 hv-base hv-foreground ${props.closeBtnClass || ''}`}> <div i-carbon-close class="text-xl" /></button>
51+
}
5152
{ props.children }
5253
</div>
5354
</div>

src/locale/lang/en.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export const en = {
2424
recent: 'Recents',
2525
noRecent: 'No recents',
2626
untitled: 'Untitled',
27+
confirm: {
28+
title: 'Delete all messages in this chat',
29+
desc: 'This action cannot be undone.',
30+
message: 'Delete this record',
31+
btn: 'confirm',
32+
cancel: 'cancel',
33+
},
2734
},
2835
send: {
2936
placeholder: 'Enter Something...',

src/locale/lang/zh-cn.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export const zhCN = {
2424
recent: '最近对话',
2525
noRecent: '暂无最近对话',
2626
untitled: '未命名对话',
27+
confirm: {
28+
title: '删除本会话的所有消息',
29+
desc: '这将删除本会话的所有消息,且不可恢复',
30+
message: '删除这条记录',
31+
btn: '确认',
32+
cancel: '取消',
33+
},
2734
},
2835
send: {
2936
placeholder: '输入内容...',

src/stores/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const showConversationSidebar = atom(false)
55
export const showSettingsSidebar = atom(false)
66
export const showConversationEditModal = atom(false)
77
export const showEmojiPickerModal = atom(false)
8+
export const showConfirmModal = atom(false)
89

910
export const isSendBoxFocus = atom(false)
1011
export const currentErrorMessage = atom<ErrorMessage | null>(null)

unocss.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default defineConfig({
5858
'hv-foreground': 'transition-opacity cursor-pointer op-70 hover:op-100',
5959
'input-base': 'bg-transparent placeholder:op-50 dark:placeholder:op-20 focus:(ring-0 outline-none) resize-none',
6060
'button': 'mt-4 px-3 py-2 text-xs border border-base rounded-lg hv-base hover:border-base-100',
61+
'emerald-button': 'mt-4 px-3 py-2 text-xs border rounded-lg text-light-400 border-emerald-600 bg-emerald-600 hover-bg-emerald-700 hover-border-emerald-700',
6162
'max-w-base': 'max-w-3xl mx-auto',
6263
'text-error': 'text-red-700 dark:text-red-400/80',
6364
'border-error': 'border border-red-700 dark:border-red-400/80',

0 commit comments

Comments
 (0)