mirror of
https://github.com/open-webui/open-webui
synced 2025-04-06 13:45:41 +00:00
refactor: uses of chats.set(...)
support pagi sidebar
This commit is contained in:
parent
62dc486c85
commit
2c4bc7a2b2
@ -25,7 +25,9 @@
|
|||||||
user,
|
user,
|
||||||
socket,
|
socket,
|
||||||
showCallOverlay,
|
showCallOverlay,
|
||||||
tools
|
tools,
|
||||||
|
pageSkip,
|
||||||
|
pageLimit
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
import {
|
import {
|
||||||
convertMessagesToHistory,
|
convertMessagesToHistory,
|
||||||
@ -418,7 +420,9 @@
|
|||||||
params: params,
|
params: params,
|
||||||
files: chatFiles
|
files: chatFiles
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -464,7 +468,9 @@
|
|||||||
params: params,
|
params: params,
|
||||||
files: chatFiles
|
files: chatFiles
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -624,7 +630,9 @@
|
|||||||
tags: [],
|
tags: [],
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
await chatId.set(chat.id);
|
await chatId.set(chat.id);
|
||||||
} else {
|
} else {
|
||||||
await chatId.set('local');
|
await chatId.set('local');
|
||||||
@ -700,7 +708,8 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
|
||||||
|
|
||||||
return _responses;
|
return _responses;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -947,7 +956,9 @@
|
|||||||
params: params,
|
params: params,
|
||||||
files: chatFiles
|
files: chatFiles
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1220,7 +1231,9 @@
|
|||||||
params: params,
|
params: params,
|
||||||
files: chatFiles
|
files: chatFiles
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1385,7 +1398,9 @@
|
|||||||
|
|
||||||
if ($settings.saveChatHistory ?? true) {
|
if ($settings.saveChatHistory ?? true) {
|
||||||
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
|
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { chats, config, settings, user as _user, mobile } from '$lib/stores';
|
import { chats, config, settings, user as _user, mobile, pageSkip, pageLimit } from '$lib/stores';
|
||||||
import { tick, getContext, onMount } from 'svelte';
|
import { tick, getContext, onMount } from 'svelte';
|
||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
@ -90,7 +90,7 @@
|
|||||||
history: history
|
history: history
|
||||||
});
|
});
|
||||||
|
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmEditResponseMessage = async (messageId, content) => {
|
const confirmEditResponseMessage = async (messageId, content) => {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import fileSaver from 'file-saver';
|
import fileSaver from 'file-saver';
|
||||||
const { saveAs } = fileSaver;
|
const { saveAs } = fileSaver;
|
||||||
|
|
||||||
import { chats, user, settings } from '$lib/stores';
|
import { chats, user, settings, scrollPaginationEnabled, pageSkip, pageLimit } from '$lib/stores';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
archiveAllChats,
|
archiveAllChats,
|
||||||
@ -61,7 +61,12 @@
|
|||||||
await createNewChat(localStorage.token, chat);
|
await createNewChat(localStorage.token, chat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// loading all chats. disable pagination on scrol.
|
||||||
|
scrollPaginationEnabled.set(false);
|
||||||
|
// subsequent queries will calculate page size to rehydrate the ui.
|
||||||
|
// since every chat is already loaded, the calculation should now load all chats.
|
||||||
|
pageSkip.set(0);
|
||||||
|
pageLimit.set(-1);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,6 +82,12 @@
|
|||||||
await archiveAllChats(localStorage.token).catch((error) => {
|
await archiveAllChats(localStorage.token).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
});
|
});
|
||||||
|
// loading all chats. disable pagination on scrol.
|
||||||
|
scrollPaginationEnabled.set(false);
|
||||||
|
// subsequent queries will calculate page size to rehydrate the ui.
|
||||||
|
// since every chat is already loaded, the calculation should now load all chats.
|
||||||
|
pageSkip.set(0);
|
||||||
|
pageLimit.set(-1);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,6 +96,12 @@
|
|||||||
await deleteAllChats(localStorage.token).catch((error) => {
|
await deleteAllChats(localStorage.token).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
});
|
});
|
||||||
|
// loading all chats. disable pagination on scrol.
|
||||||
|
scrollPaginationEnabled.set(false);
|
||||||
|
// subsequent queries will calculate page size to rehydrate the ui.
|
||||||
|
// since every chat is already loaded, the calculation should now load all chats.
|
||||||
|
pageSkip.set(0);
|
||||||
|
pageLimit.set(-1);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
getTagsById,
|
getTagsById,
|
||||||
updateChatById
|
updateChatById
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import { tags as _tags, chats, pinnedChats } from '$lib/stores';
|
import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit } from '$lib/stores';
|
||||||
import { createEventDispatcher, onMount } from 'svelte';
|
import { createEventDispatcher, onMount } from 'svelte';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
@ -47,22 +47,29 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log($_tags);
|
console.log($_tags);
|
||||||
|
|
||||||
await _tags.set(await getAllChatTags(localStorage.token));
|
await _tags.set(await getAllChatTags(localStorage.token));
|
||||||
|
|
||||||
|
console.log($_tags);
|
||||||
|
console.log('this run !!!!!');
|
||||||
console.log($_tags);
|
console.log($_tags);
|
||||||
|
|
||||||
if ($_tags.map((t) => t.name).includes(tagName)) {
|
if ($_tags.map((t) => t.name).includes(tagName)) {
|
||||||
if (tagName === 'pinned') {
|
if (tagName === 'pinned') {
|
||||||
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
||||||
} else {
|
} else {
|
||||||
await chats.set(await getChatListByTagName(localStorage.token, tagName));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($chats.find((chat) => chat.id === chatId)) {
|
if ($chats.find((chat) => chat.id === chatId)) {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,15 @@
|
|||||||
getChatListByTagName,
|
getChatListByTagName,
|
||||||
updateChatById
|
updateChatById
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import { chatId, chats, mobile, pinnedChats, showSidebar } from '$lib/stores';
|
import {
|
||||||
|
chatId,
|
||||||
|
chats,
|
||||||
|
mobile,
|
||||||
|
pageSkip,
|
||||||
|
pageLimit,
|
||||||
|
pinnedChats,
|
||||||
|
showSidebar
|
||||||
|
} from '$lib/stores';
|
||||||
|
|
||||||
import ChatMenu from './ChatMenu.svelte';
|
import ChatMenu from './ChatMenu.svelte';
|
||||||
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
|
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
|
||||||
@ -40,7 +48,9 @@
|
|||||||
await updateChatById(localStorage.token, id, {
|
await updateChatById(localStorage.token, id, {
|
||||||
title: _title
|
title: _title
|
||||||
});
|
});
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -53,14 +63,16 @@
|
|||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
goto(`/c/${res.id}`);
|
goto(`/c/${res.id}`);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(
|
||||||
|
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
|
||||||
|
);
|
||||||
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const archiveChatHandler = async (id) => {
|
const archiveChatHandler = async (id) => {
|
||||||
await archiveChatById(localStorage.token, id);
|
await archiveChatById(localStorage.token, id);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
|
||||||
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user