* feat: adding create bot functionality Signed-off-by: James <james@jan.ai> * update the temperature progress bar Signed-off-by: James <james@jan.ai> * WIP baselayout * Mapping plugins with available preferences * Added loader component * WIP working another screen * Cleanup types and avoid import one by one * Prepare bottom bar * Add css variables colors to enable user select the accent * Enable change accent color * Seperate css variable * Fix conflict * Add blank state of my model empty * Restyle explore models page * Enable user config left sidebar * Restyle my models page * WIP styling chat page * Restyling chat message * Fix conflict * Adde form preferences setting plugins * Fixed form bot info * Sidebar bot chat * Showing rightbar for both setting when user created bot * Fix style bot info * Using overflow auto intead of scroll * Remove script built UI from root package * Fix missig import * Resolve error linter * fix e2e tests Signed-off-by: James <james@jan.ai> --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
import React from 'react'
|
|
import { useAtomValue, useSetAtom } from 'jotai'
|
|
import Image from 'next/image'
|
|
import { ModelManagementService } from '@janhq/core'
|
|
import { executeSerial } from '../../../../electron/core/plugin-manager/execution/extension-manager'
|
|
import {
|
|
getActiveConvoIdAtom,
|
|
setActiveConvoIdAtom,
|
|
updateConversationErrorAtom,
|
|
updateConversationWaitingForResponseAtom,
|
|
} from '@helpers/atoms/Conversation.atom'
|
|
import {
|
|
setMainViewStateAtom,
|
|
MainViewState,
|
|
} from '@helpers/atoms/MainView.atom'
|
|
import useInitModel from '@hooks/useInitModel'
|
|
import { displayDate } from '@utils/datetime'
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
type Props = {
|
|
conversation: Conversation
|
|
avatarUrl?: string
|
|
name: string
|
|
summary?: string
|
|
updatedAt?: string
|
|
}
|
|
|
|
const HistoryItem: React.FC<Props> = ({
|
|
conversation,
|
|
avatarUrl,
|
|
name,
|
|
summary,
|
|
updatedAt,
|
|
}) => {
|
|
const setMainViewState = useSetAtom(setMainViewStateAtom)
|
|
const activeConvoId = useAtomValue(getActiveConvoIdAtom)
|
|
const setActiveConvoId = useSetAtom(setActiveConvoIdAtom)
|
|
const updateConvWaiting = useSetAtom(updateConversationWaitingForResponseAtom)
|
|
const updateConvError = useSetAtom(updateConversationErrorAtom)
|
|
const isSelected = activeConvoId === conversation._id
|
|
|
|
const { initModel } = useInitModel()
|
|
|
|
const onClick = async () => {
|
|
const model = await executeSerial(
|
|
ModelManagementService.GetModelById,
|
|
conversation.modelId
|
|
)
|
|
|
|
if (conversation._id) updateConvWaiting(conversation._id, true)
|
|
initModel(model).then((res: any) => {
|
|
if (conversation._id) updateConvWaiting(conversation._id, false)
|
|
|
|
if (res?.error && conversation._id) {
|
|
updateConvError(conversation._id, res.error)
|
|
}
|
|
})
|
|
|
|
if (activeConvoId !== conversation._id) {
|
|
setMainViewState(MainViewState.Conversation)
|
|
setActiveConvoId(conversation._id)
|
|
}
|
|
}
|
|
|
|
const backgroundColor = isSelected ? 'bg-background/80' : 'bg-background/20'
|
|
const description = conversation?.lastMessage ?? 'No new message'
|
|
|
|
return (
|
|
<li
|
|
role="button"
|
|
className={twMerge(
|
|
'flex flex-row rounded-md border border-border p-3',
|
|
backgroundColor
|
|
)}
|
|
onClick={onClick}
|
|
>
|
|
<div className="flex flex-1 flex-col">
|
|
{/* title */}
|
|
|
|
<span className="mb-1 line-clamp-1 leading-5 text-muted-foreground">
|
|
{updatedAt && displayDate(new Date(updatedAt).getTime())}
|
|
</span>
|
|
|
|
<span className="line-clamp-1">{summary ?? name}</span>
|
|
|
|
{/* description */}
|
|
<span className="mt-1 line-clamp-2 text-muted-foreground">
|
|
{description}
|
|
</span>
|
|
</div>
|
|
</li>
|
|
)
|
|
}
|
|
|
|
export default HistoryItem
|