Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrandaws committed Aug 26, 2024
2 parents 7ba5787 + 59d8a2b commit 7ec4800
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/web/src/hooks/useChatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ListChatsResponse, Chat } from 'generative-ai-use-cases-jp';

const useChatList = () => {
const { listChats, deleteChat: deleteChatApi, updateTitle } = useChatApi();
const { data, size, setSize, isLoading, mutate } = listChats();
const { data, size, setSize, mutate } = listChats();

const chats = useMemo(() => {
if (data) {
Expand All @@ -15,14 +15,16 @@ const useChatList = () => {
}
}, [data]);

const isLoadingMore = useMemo(() => {
return (
isLoading || (size > 0 && data && typeof data[size - 1] === 'undefined')
);
}, [isLoading, size, data]);
const isLoading = useMemo(() => {
if (!data) return false;
return data!.length < size || data![size - 1] === undefined;
}, [data, size]);

const canLoadMore = useMemo(() => {
return !data || data!.length === size;
// チャットリストは 1 度に最大で 100 件取得される
return (
!data || (data!.length === size && data![size - 1].chats.length === 100)
);
}, [data, size]);

const loadMore = useCallback(() => {
Expand Down Expand Up @@ -93,7 +95,7 @@ const useChatList = () => {
};

return {
loading: isLoadingMore,
loading: isLoading,
chats,
mutate,
updateChatTitle,
Expand Down

0 comments on commit 7ec4800

Please sign in to comment.