Move new conversation sticky to top

This commit is contained in:
Faisal Amir 2023-10-30 22:41:42 +07:00
parent b7e45dabad
commit 28c969759f
5 changed files with 70 additions and 77 deletions

View File

@ -1,33 +1,17 @@
import HistoryItem from '../HistoryItem' import HistoryItem from '../HistoryItem'
import { Fragment, useEffect } from 'react' import { useEffect } from 'react'
import ExpandableHeader from '../ExpandableHeader' import ExpandableHeader from '../ExpandableHeader'
import { useAtomValue, useSetAtom } from 'jotai' import { useAtomValue } from 'jotai'
import { searchAtom } from '@helpers/JotaiWrapper' import { searchAtom } from '@helpers/JotaiWrapper'
import useGetUserConversations from '@hooks/useGetUserConversations' import useGetUserConversations from '@hooks/useGetUserConversations'
import SidebarEmptyHistory from '../SidebarEmptyHistory' import SidebarEmptyHistory from '../SidebarEmptyHistory'
import { userConversationsAtom } from '@helpers/atoms/Conversation.atom' import { userConversationsAtom } from '@helpers/atoms/Conversation.atom'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { Button } from '@uikit'
import { activeAssistantModelAtom, stateModel } from '@helpers/atoms/Model.atom'
import useCreateConversation from '@hooks/useCreateConversation'
import { showingModalNoActiveModel } from '@helpers/atoms/Modal.atom'
import { PlusIcon } from '@heroicons/react/24/outline'
const HistoryList: React.FC = () => { const HistoryList: React.FC = () => {
const conversations = useAtomValue(userConversationsAtom) const conversations = useAtomValue(userConversationsAtom)
const searchText = useAtomValue(searchAtom) const searchText = useAtomValue(searchAtom)
const { getUserConversations } = useGetUserConversations() const { getUserConversations } = useGetUserConversations()
const activeModel = useAtomValue(activeAssistantModelAtom)
const { requestCreateConvo } = useCreateConversation()
const setShowModalNoActiveModel = useSetAtom(showingModalNoActiveModel)
const onNewConversationClick = () => {
if (activeModel) {
requestCreateConvo(activeModel)
} else {
setShowModalNoActiveModel(true)
}
}
useEffect(() => { useEffect(() => {
getUserConversations() getUserConversations()
@ -35,18 +19,15 @@ const HistoryList: React.FC = () => {
}, []) }, [])
return ( return (
<div className="flex flex-grow flex-col gap-2"> <div className="flex flex-grow flex-col gap-2 px-4 pb-4">
<ExpandableHeader title="CHAT HISTORY" /> <ExpandableHeader title="CHAT HISTORY" />
{conversations.length > 0 ? ( {conversations.length > 0 ? (
<Fragment>
<ul className={twMerge('mt-1 flex flex-col gap-y-3 overflow-y-auto')}> <ul className={twMerge('mt-1 flex flex-col gap-y-3 overflow-y-auto')}>
{conversations {conversations
.filter( .filter(
(e) => (e) =>
searchText.trim() === '' || searchText.trim() === '' ||
e.name e.name?.toLowerCase().includes(searchText.toLowerCase().trim())
?.toLowerCase()
.includes(searchText.toLowerCase().trim())
) )
.map((convo, i) => ( .map((convo, i) => (
<HistoryItem <HistoryItem
@ -58,14 +39,6 @@ const HistoryList: React.FC = () => {
/> />
))} ))}
</ul> </ul>
<Button
onClick={onNewConversationClick}
className="mt-2 flex items-center space-x-2"
>
<PlusIcon width={16} height={16} />
<span>New Conversation</span>
</Button>
</Fragment>
) : ( ) : (
<SidebarEmptyHistory /> <SidebarEmptyHistory />
)} )}

View File

@ -43,15 +43,7 @@ const InputToolbar: React.FC = () => {
} }
if (!activeConvoId) { if (!activeConvoId) {
return ( return null
<div className="my-3 flex justify-center gap-2">
<SecondaryButton
onClick={onNewConversationClick}
title="New Conversation"
icon={<PlusIcon width={16} height={16} />}
/>
</div>
)
} }
if ( if (
(activeConvoId && inputState === 'model-mismatch') || (activeConvoId && inputState === 'model-mismatch') ||
@ -94,13 +86,13 @@ const InputToolbar: React.FC = () => {
</span> </span>
</div> </div>
)} )}
<div className="my-3 flex justify-center gap-2"> {/* <div className="my-3 flex justify-center gap-2">
<SecondaryButton <SecondaryButton
onClick={onNewConversationClick} onClick={onNewConversationClick}
title="New Conversation" title="New Conversation"
icon={<PlusIcon width={16} height={16} />} icon={<PlusIcon width={16} height={16} />}
/> />
</div> </div> */}
{/* My text input */} {/* My text input */}
<div className="mb-5 flex items-start space-x-4"> <div className="mb-5 flex items-start space-x-4">
<div className="relative min-w-0 flex-1"> <div className="relative min-w-0 flex-1">

View File

@ -2,22 +2,37 @@
import React from 'react' import React from 'react'
import SecondaryButton from '../SecondaryButton' import SecondaryButton from '../SecondaryButton'
import { useSetAtom } from 'jotai' import { useSetAtom, useAtomValue } from 'jotai'
import { import {
MainViewState, MainViewState,
setMainViewStateAtom, setMainViewStateAtom,
} from '@helpers/atoms/MainView.atom' } from '@helpers/atoms/MainView.atom'
import { MagnifyingGlassIcon, PlusIcon } from '@heroicons/react/24/outline' import { MagnifyingGlassIcon, PlusIcon } from '@heroicons/react/24/outline'
import useCreateConversation from '@hooks/useCreateConversation'
import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels' import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels'
import { Button } from '@uikit'
import { activeAssistantModelAtom } from '@helpers/atoms/Model.atom'
import { showingModalNoActiveModel } from '@helpers/atoms/Modal.atom'
const LeftHeaderAction: React.FC = () => { const LeftHeaderAction: React.FC = () => {
const setMainView = useSetAtom(setMainViewStateAtom) const setMainView = useSetAtom(setMainViewStateAtom)
const { downloadedModels } = useGetDownloadedModels() const { downloadedModels } = useGetDownloadedModels()
const activeModel = useAtomValue(activeAssistantModelAtom)
const { requestCreateConvo } = useCreateConversation()
const setShowModalNoActiveModel = useSetAtom(showingModalNoActiveModel)
const onExploreClick = () => { const onExploreClick = () => {
setMainView(MainViewState.ExploreModel) setMainView(MainViewState.ExploreModel)
} }
const onNewConversationClick = () => {
if (activeModel) {
requestCreateConvo(activeModel)
} else {
setShowModalNoActiveModel(true)
}
}
const onCreateBotClicked = () => { const onCreateBotClicked = () => {
if (downloadedModels.length === 0) { if (downloadedModels.length === 0) {
alert('You need to download at least one model to create a bot.') alert('You need to download at least one model to create a bot.')
@ -27,20 +42,29 @@ const LeftHeaderAction: React.FC = () => {
} }
return ( return (
<div className="sticky top-0 mb-4 flex flex-row gap-2"> <div className="sticky top-0 mb-4 bg-background/90 p-4">
<div className="flex flex-row gap-2">
<SecondaryButton <SecondaryButton
title={'Explore'} title={'Explore'}
onClick={onExploreClick} onClick={onExploreClick}
className="flex-1" className="w-full flex-1"
icon={<MagnifyingGlassIcon width={16} height={16} />} icon={<MagnifyingGlassIcon width={16} height={16} />}
/> />
<SecondaryButton <SecondaryButton
title={'Create bot'} title={'Create bot'}
onClick={onCreateBotClicked} onClick={onCreateBotClicked}
className="flex-1" className="w-full flex-1"
icon={<PlusIcon width={16} height={16} />} icon={<PlusIcon width={16} height={16} />}
/> />
</div> </div>
<Button
onClick={onNewConversationClick}
className="mt-2 flex w-full items-center space-x-2"
>
<PlusIcon width={16} height={16} />
<span>New Conversation</span>
</Button>
</div>
) )
} }

View File

@ -16,7 +16,13 @@ const SecondaryButton: React.FC<Props> = ({
className, className,
icon, icon,
}) => ( }) => (
<Button size="sm" disabled={disabled} type="button" onClick={onClick}> <Button
size="sm"
disabled={disabled}
type="button"
onClick={onClick}
className={className}
>
{icon}&nbsp; {icon}&nbsp;
{title} {title}
</Button> </Button>

View File

@ -10,11 +10,9 @@ const ChatScreen = () => {
return ( return (
<div className="flex h-full"> <div className="flex h-full">
<div className="flex h-full w-64 flex-shrink-0 flex-col overflow-y-auto border-r border-border "> <div className="flex h-full w-64 flex-shrink-0 flex-col overflow-y-auto border-r border-border ">
<div className="px-4 py-6 pt-4">
<LeftHeaderAction /> <LeftHeaderAction />
<HistoryList /> <HistoryList />
</div> </div>
</div>
<div className="relative flex h-full w-full flex-col bg-background/50"> <div className="relative flex h-full w-full flex-col bg-background/50">
<MainHeader /> <MainHeader />
<ChatBody /> <ChatBody />