Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
2c4bc7a2
Commit
2c4bc7a2
authored
Aug 01, 2024
by
Aryan Kothari
Browse files
refactor: uses of `chats.set(...)` support pagi sidebar
parent
62dc486c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
19 deletions
+70
-19
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+23
-8
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+2
-2
src/lib/components/chat/Settings/Chats.svelte
src/lib/components/chat/Settings/Chats.svelte
+19
-2
src/lib/components/chat/Tags.svelte
src/lib/components/chat/Tags.svelte
+10
-3
src/lib/components/layout/Sidebar/ChatItem.svelte
src/lib/components/layout/Sidebar/ChatItem.svelte
+16
-4
No files found.
src/lib/components/chat/Chat.svelte
View file @
2c4bc7a2
...
@@ -25,7 +25,9 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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)
);
}
}
};
};
...
...
src/lib/components/chat/Messages.svelte
View file @
2c4bc7a2
<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 @@
...
@@ -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) => {
...
...
src/lib/components/chat/Settings/Chats.svelte
View file @
2c4bc7a2
...
@@ -2,7 +2,7 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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));
};
};
...
...
src/lib/components/chat/Tags.svelte
View file @
2c4bc7a2
...
@@ -8,7 +8,7 @@
...
@@ -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 @@
...
@@ -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'));
}
}
};
};
...
...
src/lib/components/layout/Sidebar/ChatItem.svelte
View file @
2c4bc7a2
...
@@ -14,7 +14,15 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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'));
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment