Louis 5fc1ba7067
feature: @janhq/plugin-core module & plugins update (#321)
* @janhq/plugin-core module

* refactor web to use exported services from module

* refactor data-plugin to provide DAL & move model logics to model management plugin

* model-management in TS

* add ci auto package, increate version, and publish to npm repository

* chore: storage operations

* chore: hybrid data-plugin esm & cjs module

* chore: PouchDB Driver

* chore: documentation

---------

Co-authored-by: Hien To <hien@jan.ai>
Co-authored-by: Service Account <service@jan.ai>
2023-10-14 15:59:28 +07:00

55 lines
1.8 KiB
TypeScript

import HistoryItem from "../HistoryItem";
import { useEffect, useState } from "react";
import ExpandableHeader from "../ExpandableHeader";
import { useAtomValue } from "jotai";
import { searchAtom } from "@/_helpers/JotaiWrapper";
import useGetUserConversations from "@/_hooks/useGetUserConversations";
import SidebarEmptyHistory from "../SidebarEmptyHistory";
import { userConversationsAtom } from "@/_helpers/atoms/Conversation.atom";
const HistoryList: React.FC = () => {
const conversations = useAtomValue(userConversationsAtom);
const searchText = useAtomValue(searchAtom);
const [expand, setExpand] = useState<boolean>(true);
const { getUserConversations } = useGetUserConversations();
useEffect(() => {
getUserConversations();
}, []);
return (
<div className="flex flex-col flex-grow pt-3 gap-2 overflow-hidden">
<ExpandableHeader
title="CHAT HISTORY"
expanded={expand}
onClick={() => setExpand(!expand)}
/>
<div
className={`flex flex-col gap-1 mt-1 overflow-y-auto scroll ${!expand ? "hidden " : "block"}`}
>
{conversations.length > 0 ? (
conversations
.filter(
(e) =>
searchText.trim() === "" ||
e.name?.toLowerCase().includes(searchText.toLowerCase().trim())
)
.map((convo) => (
<HistoryItem
key={convo._id}
conversation={convo}
avatarUrl={convo.image}
name={convo.name || "Jan"}
updatedAt={convo.updatedAt ?? ""}
/>
))
) : (
<SidebarEmptyHistory />
)}
</div>
</div>
);
};
export default HistoryList;