refac: user chat list modal

This commit is contained in:
Timothy Jaeryang Baek
2025-05-25 01:44:53 +04:00
parent 44e7e09784
commit 75208935d7
6 changed files with 166 additions and 189 deletions
+32 -9
View File
@@ -111,17 +111,37 @@ export const getChatList = async (token: string = '', page: number | null = null
}));
};
export const getChatListByUserId = async (token: string = '', userId: string) => {
export const getChatListByUserId = async (
token: string = '',
userId: string,
page: number = 1,
filter?: object
) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/list/user/${userId}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
const searchParams = new URLSearchParams();
searchParams.append('page', `${page}`);
if (filter) {
Object.entries(filter).forEach(([key, value]) => {
if (value !== undefined && value !== null) {
searchParams.append(key, value.toString());
}
});
}
const res = await fetch(
`${WEBUI_API_BASE_URL}/chats/list/user/${userId}?${searchParams.toString()}`,
{
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
}
}
})
)
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
@@ -188,7 +208,10 @@ export const getArchivedChatList = async (
throw error;
}
return res;
return res.map((chat) => ({
...chat,
time_range: getTimeRange(chat.updated_at)
}));
};
export const getAllChats = async (token: string) => {