Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feat/share-message
Browse files Browse the repository at this point in the history
  • Loading branch information
yzh990918 committed May 23, 2023
2 parents 4961260 + 42d431d commit 5f9dbda
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Main.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Conversation from './main/Conversation'
---

<main class="relative h-full flex-1 flex flex-col overflow-hidden bg-base">
<Header client:load />
<Header client:only />
<main class="flex-1 mt-14 flex flex-col overflow-hidden">
<div class="flex-1 relative overflow-hidden">
<Conversation client:only />
Expand Down
14 changes: 11 additions & 3 deletions src/components/header/ConversationMessageClearButton.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import { useStore } from '@nanostores/solid'
import { currentConversationId } from '@/stores/conversation'
import { scrollController } from '@/stores/ui'
import {
scrollController,
showConfirmModal,
} from '@/stores/ui'
import { clearMessagesByConversationId } from '@/stores/messages'
import { useI18n } from '@/hooks'
import ConfirmModal from '../ui/ConfirmModal'

export default () => {
const $currentConversationId = useStore(currentConversationId)
const { t } = useI18n()

const handleClearMessage = () => {
clearMessagesByConversationId($currentConversationId())
scrollController().scrollToBottom()
showConfirmModal.set(false)
}

return (
<>
{ $currentConversationId() && (
{$currentConversationId() && (
<div
class="fcc p-2 rounded-md text-xl hv-foreground"
onClick={handleClearMessage}
onClick={() => { showConfirmModal.set(true) }}
>
<div i-carbon-clean />
</div>
)}
<ConfirmModal title={t('conversations.confirm.title')} description={t('conversations.confirm.desc')} onConfirm={handleClearMessage} onCancel={() => { showConfirmModal.set(false) }} />
</>
)
}
29 changes: 29 additions & 0 deletions src/components/ui/ConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
showConfirmModal,
} from '@/stores/ui'
import { useI18n } from '@/hooks'
import Modal from './Modal'

interface Props {
title: string
description: string
onConfirm: () => void
onCancel: () => void
}

export default (props: Props) => {
const { t } = useI18n()
return (
<Modal bindValue={showConfirmModal} direction="bottom" closeBtnClass="hidden" >
<div class="max-h-[70vh] w-full">
<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">
<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>
<div class="flex flex-col-reverse sm:flex-row sm:justify-end gap-2">
<button class="button" onClick={() => props.onCancel()}>{t('conversations.confirm.cancel')}</button>
<button class="emerald-button" onClick={() => props.onConfirm()}>{t('conversations.confirm.btn')}</button>
</div>
</div>
</div>
</Modal>
)
}
7 changes: 7 additions & 0 deletions src/locale/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const en = {
recent: 'Recents',
noRecent: 'No recents',
untitled: 'Untitled',
confirm: {
title: 'Delete all messages in this chat',
desc: 'This action cannot be undone.',
message: 'Delete this record',
btn: 'confirm',
cancel: 'cancel',
},
},
send: {
placeholder: 'Enter Something...',
Expand Down
7 changes: 7 additions & 0 deletions src/locale/lang/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const zhCN = {
recent: '最近对话',
noRecent: '暂无最近对话',
untitled: '未命名对话',
confirm: {
title: '删除本会话的所有消息',
desc: '这将删除本会话的所有消息,且不可恢复',
message: '删除这条记录',
btn: '确认',
cancel: '取消',
},
},
send: {
placeholder: '输入内容...',
Expand Down
1 change: 1 addition & 0 deletions src/stores/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const showConversationSidebar = atom(false)
export const showSettingsSidebar = atom(false)
export const showConversationEditModal = atom(false)
export const showEmojiPickerModal = atom(false)
export const showConfirmModal = atom(false)

export const isSendBoxFocus = atom(false)
export const currentErrorMessage = atom<ErrorMessage | null>(null)
Expand Down
1 change: 1 addition & 0 deletions unocss.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default defineConfig({
'hv-foreground': 'transition-opacity cursor-pointer op-70 hover:op-100',
'input-base': 'bg-transparent placeholder:op-50 dark:placeholder:op-20 focus:(ring-0 outline-none) resize-none',
'button': 'mt-4 px-3 py-2 text-xs border border-base rounded-lg hv-base hover:border-base-100',
'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',
'max-w-base': 'max-w-3xl mx-auto',
'text-error': 'text-red-700 dark:text-red-400/80',
'border-error': 'border border-red-700 dark:border-red-400/80',
Expand Down

0 comments on commit 5f9dbda

Please sign in to comment.