-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
349 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ | |
} | ||
|
||
@keyframes sk-bouncedelay { | ||
|
||
0%, | ||
80%, | ||
100% { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,99 @@ | ||
import { IconEdit, IconTrash, IconMore, IconDownload } from "./ui/icons" | ||
import { useCallback, useEffect, useState } from 'react' | ||
import { useChatHistory, ChatConversation } from '@/lib/hooks/chat-history' | ||
import { IconEdit, IconTrash, IconMore, IconDownload, IconCheck, IconClose } from './ui/icons' | ||
import { cn, formatDate } from '@/lib/utils' | ||
import { BingReturnType } from '@/lib/hooks/use-bing' | ||
|
||
export function ChatHistory() { | ||
return ( | ||
<div className="chat-history fixed top-18 right-4"> | ||
<div className="chat-history-header text-sm font-semibold text-left w-[280px] px-4 py-6"> | ||
历史记录 | ||
</div> | ||
<div className="chat-history-main"> | ||
<div className="scroller"> | ||
<div className="surface"> | ||
<div className="threads"> | ||
<div className="thread"> | ||
<div className="primary-row"> | ||
<button type="button" aria-label="加载聊天"> | ||
|
||
</button> | ||
<div className="description"> | ||
<h3 className="name">无标题的聊天</h3> | ||
</div> | ||
<h4 className="time">上午1:42</h4> | ||
<div className="controls"> | ||
interface ConversationTheadProps { | ||
conversation: ChatConversation | ||
onRename: (conversation: ChatConversation, chatName: string) => void | ||
onDelete: (conversation: ChatConversation) => void | ||
onUpdate: (conversation: ChatConversation) => void | ||
} | ||
|
||
<button className="edit icon-button" type="button" aria-label="重命名"> | ||
<IconEdit /> | ||
</button> | ||
export function ConversationThead({ conversation, onRename, onDelete, onUpdate }: ConversationTheadProps) { | ||
const [isEdit, setEdit] = useState(false) | ||
const [name, setName] = useState(conversation.chatName) | ||
const handleSave = useCallback(() => { | ||
if (!name) { | ||
setName(conversation.chatName) | ||
return | ||
} | ||
setEdit(false) | ||
onRename(conversation, name) | ||
}, [conversation, name]) | ||
const handleDelete = useCallback(() => { | ||
onDelete(conversation) | ||
}, [conversation]) | ||
useEffect(() => { | ||
setName(conversation.chatName) | ||
}, [conversation]) | ||
return ( | ||
<div className={cn('thread select-none', { active: isEdit })} onClick={() => onUpdate(conversation)}> | ||
<div className="primary-row flex"> | ||
<div className="description flex-1"> | ||
{!isEdit ? ( | ||
<h3 className="name w-[200px]">{name}</h3> | ||
) : (<input className="input-name" defaultValue={name} onChange={(event) => setName(event.target.value)} />)} | ||
</div> | ||
{!isEdit && (<h4 className="time">{formatDate(conversation.updateTimeUtc)}</h4>)} | ||
<div className="controls"> | ||
{!isEdit ? (<> | ||
<button className="edit icon-button" type="button" aria-label="重命名" onClick={() => setEdit(true)}> | ||
<IconEdit /> | ||
</button> | ||
|
||
<button className="delete icon-button" type="button" aria-label="删除"> | ||
<IconTrash /> | ||
</button> | ||
<button className="delete icon-button" type="button" aria-label="删除" onClick={handleDelete}> | ||
<IconTrash /> | ||
</button> | ||
|
||
<button className="more icon-button" type="button" aria-haspopup="true" aria-expanded="false" aria-label="更多"> | ||
<IconMore /> | ||
</button> | ||
<button className="export icon-button" type="button" aria-label="导出"> | ||
<IconDownload /> | ||
</button> | ||
</>) : ( | ||
<> | ||
<button className="edit icon-button" type="button" aria-label="保存" onClick={handleSave}> | ||
<IconCheck /> | ||
</button> | ||
<button className="edit icon-button" type="button" aria-label="取消" onClick={() => setEdit(false)}> | ||
<IconClose /> | ||
</button> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
<button className="export icon-button" type="button" aria-label="导出"> | ||
<IconDownload /> | ||
</button> | ||
</div> | ||
</div> | ||
export function ChatHistory({ className }: { className?: string }) { | ||
const { chatHistory, refreshChats, deleteChat, renameChat, updateMessage } = useChatHistory() | ||
useEffect(() => { | ||
refreshChats() | ||
}, []) | ||
return ( | ||
<div className={cn('chat-history right-4 z-10 fixed w-[342px]', className)}> | ||
<div className="chat-history-header text-sm font-semibold text-left px-4 pb-6"> | ||
历史记录 | ||
</div> | ||
{chatHistory?.chats?.length ? ( | ||
<div className="chat-history-main"> | ||
<div className="scroller"> | ||
<div className="surface"> | ||
<div className="threads w-[310px]"> | ||
{chatHistory.chats.map((chat) => ( | ||
<ConversationThead key={chat.conversationId} | ||
conversation={chat} | ||
onDelete={deleteChat} | ||
onRename={renameChat} | ||
onUpdate={updateMessage} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) : []} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.