Show more recent chats

c45f1ceaffd932e0e009ada84bfaa9a121e7dfec

Cohee <18619528+Cohee1207@users.noreply.github.com>

4 files changed, +40 -6Showing whitespace changes
public/css/welcome.css+14 -2
@@ -6,6 +6,10 @@
66 width: 100%;
77}
88
9+.welcomePanel:has(.showMoreChats) {
10+ padding-bottom: 5px;
11+}
12+
913body.bubblechat .welcomePanel {
1014 border-radius: 10px;
1115 background-color: var(--SmartThemeBotMesBlurTintColor);
@@ -22,7 +26,7 @@ body.bubblechat .welcomePanel {
2226
2327.welcomePanel .recentChatsTitle {
2428 flex-grow: 1;
2529 font-size: calc(var(--mainFontSize) * 1.115);
2630 font-weight: 600;
2731}
2832
@@ -36,7 +40,7 @@ body.bubblechat .welcomePanel {
3640}
3741
3842.welcomePanel .welcomeHeaderVersionDisplay {
3943 font-size: calc(var(--mainFontSize) * 1.23);
4044 font-weight: 600;
4145}
4246
@@ -174,6 +178,14 @@ body.big-avatars .welcomeRecent .recentChatList .recentChat .chatMessageContaine
174178 font-size: calc(var(--mainFontSize) * 0.95);
175179}
176180
181+.welcomeRecent .recentChatList .recentChat.hidden {
182+ display: none;
183+}
184+
185+.welcomeRecent .recentChatList .showMoreChats {
186+ align-self: center;
187+}
188+
177189@media screen and (max-width: 1000px) {
178190 .welcomePanel .welcomeShortcuts a span {
179191 display: none;
public/scripts/templates/welcomePanel.html+8 -1
@@ -37,7 +37,7 @@
3737 {{/if}}
3838 {{#each chats}}
3939 {{#with this}}
4040 <div class="recentChat {{#if hidden}}hidden{{/if}}" data-file="{{chat_name}}" data-avatar="{{avatar}}">
4141 <div class="avatar" title="{{char_name}}">
4242 <img src="{{char_thumbnail}}" alt="{{char_name}}">
4343 </div>
@@ -66,6 +66,13 @@
6666 </div>
6767 {{/with}}
6868 {{/each}}
69+ {{#if more}}
70+ <button class="menu_button menu_button_icon showMoreChats">
71+ <small data-i18n="Show more">
72+ Show more
73+ </small>
74+ </button>
75+ {{/if}}
6976 </div>
7077 </div>
7178</div>
public/scripts/welcome-screen.js+17 -2
@@ -62,6 +62,7 @@ async function sendWelcomePanel() {
6262 chats,
6363 empty: !chats.length,
6464 version: displayVersion,
65+ more: chats.some(chat => chat.hidden),
6566 };
6667 const template = await renderTemplateAsync('welcomePanel', templateData);
6768 const fragment = document.createRange().createContextualFragment(template);
@@ -74,9 +75,20 @@ async function sendWelcomePanel() {
7475 }
7576 });
7677 });
77- fragment.querySelector('button.openTemporaryChat').addEventListener('click', () => {
78+ const hiddenChats = fragment.querySelectorAll('.recentChat.hidden');
79+ fragment.querySelectorAll('button.showMoreChats').forEach((button) => {
80+ button.addEventListener('click', () => {
81+ hiddenChats.forEach((chatItem) => {
82+ chatItem.classList.remove('hidden');
83+ });
84+ button.remove();
85+ });
86+ });
87+ fragment.querySelectorAll('button.openTemporaryChat').forEach((button) => {
88+ button.addEventListener('click', () => {
7889 void newAssistantChat({ temporary: true });
7990 });
91+ });
8092 chatElement.append(fragment.firstChild);
8193 } catch (error) {
8294 console.error('Welcome screen error:', error);
@@ -125,6 +137,7 @@ async function openRecentChat(avatarId, fileName) {
125137 * @property {string} char_name Character name
126138 * @property {string} date_short Date in short format
127139 * @property {string} date_long Date in long format
140+ * @property {boolean} hidden Chat will be hidden by default
128141 */
129142async function getRecentChats() {
130143 const response = await fetch('/api/characters/recent', {
@@ -141,13 +154,15 @@ async function getRecentChats() {
141154 data.sort((a, b) => b.last_mes - a.last_mes)
142155 .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar) }))
143156 .filter(t => t.character)
144157 .forEach(({ chat, character }, index) => {
158+ const DEFAULT_DISPLAYED = 5;
145159 const chatTimestamp = timestampToMoment(chat.last_mes);
146160 chat.char_name = character.name;
147161 chat.date_short = chatTimestamp.format('l');
148162 chat.date_long = chatTimestamp.format('LL LT');
149163 chat.chat_name = chat.file_name.replace('.jsonl', '');
150164 chat.char_thumbnail = getThumbnailUrl('avatar', character.avatar);
165+ chat.hidden = index >= DEFAULT_DISPLAYED;
151166 });
152167
153168 return data;
src/endpoints/characters.js+1 -1
@@ -1312,7 +1312,7 @@ router.post('/recent', async function (request, response) {
13121312 }
13131313 }
13141314
13151315 const recentChats = allChatFiles.sort((a, b) => b.mtime - a.mtime).slice(0, 515);
13161316 const jsonFilesPromise = recentChats.map((file) => {
13171317 return getChatInfo(file.filePath, { avatar: file.pngFile });
13181318 });