Focus on send textarea on opening temp chat
| @@ -30,6 +30,9 @@ import { sortMoments, timestampToMoment } from './utils.js'; | |||
| 30 | const assistantAvatarKey = 'assistant'; | 30 | const assistantAvatarKey = 'assistant'; |
| 31 | const defaultAssistantAvatar = 'default_Assistant.png'; | 31 | const defaultAssistantAvatar = 'default_Assistant.png'; |
| 32 | 32 | ||
| 33 | const DEFAULT_DISPLAYED = 5; | ||
| 34 | const MAX_DISPLAYED = 20; | ||
| 35 | |||
| 33 | export function getPermanentAssistantAvatar() { | 36 | export function getPermanentAssistantAvatar() { |
| 34 | const assistantAvatar = accountStorage.getItem(assistantAvatarKey); | 37 | const assistantAvatar = accountStorage.getItem(assistantAvatarKey); |
| 35 | if (assistantAvatar === null) { | 38 | if (assistantAvatar === null) { |
| @@ -78,6 +81,7 @@ function sendAssistantMessage() { | |||
| 78 | async function sendWelcomePanel() { | 81 | async function sendWelcomePanel() { |
| 79 | try { | 82 | try { |
| 80 | const chatElement = document.getElementById('chat'); | 83 | const chatElement = document.getElementById('chat'); |
| 84 | const sendTextArea = document.getElementById('send_textarea'); | ||
| 81 | if (!chatElement) { | 85 | if (!chatElement) { |
| 82 | console.error('Chat element not found'); | 86 | console.error('Chat element not found'); |
| 83 | return; | 87 | return; |
| @@ -134,8 +138,11 @@ async function sendWelcomePanel() { | |||
| 134 | }); | 138 | }); |
| 135 | }); | 139 | }); |
| 136 | fragment.querySelectorAll('button.openTemporaryChat').forEach((button) => { | 140 | fragment.querySelectorAll('button.openTemporaryChat').forEach((button) => { |
| 137 | button.addEventListener('click', () => { | 141 | button.addEventListener('click', async () => { |
| 138 | void newAssistantChat({ temporary: true }); | 142 | await newAssistantChat({ temporary: true }); |
| 143 | if (sendTextArea instanceof HTMLTextAreaElement) { | ||
| 144 | sendTextArea.focus(); | ||
| 145 | } | ||
| 139 | }); | 146 | }); |
| 140 | }); | 147 | }); |
| 141 | fragment.querySelectorAll('.recentChat.group').forEach((groupChat) => { | 148 | fragment.querySelectorAll('.recentChat.group').forEach((groupChat) => { |
| @@ -259,8 +266,8 @@ async function getRecentChats() { | |||
| 259 | data.sort((a, b) => sortMoments(timestampToMoment(a.last_mes), timestampToMoment(b.last_mes))) | 266 | data.sort((a, b) => sortMoments(timestampToMoment(a.last_mes), timestampToMoment(b.last_mes))) |
| 260 | .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) })) | 267 | .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) })) |
| 261 | .filter(t => t.character || t.group) | 268 | .filter(t => t.character || t.group) |
| 269 | .slice(0, MAX_DISPLAYED) | ||
| 262 | .forEach(({ chat, character, group }, index) => { | 270 | .forEach(({ chat, character, group }, index) => { |
| 263 | const DEFAULT_DISPLAYED = 5; | ||
| 264 | const chatTimestamp = timestampToMoment(chat.last_mes); | 271 | const chatTimestamp = timestampToMoment(chat.last_mes); |
| 265 | chat.char_name = character?.name || group?.name || ''; | 272 | chat.char_name = character?.name || group?.name || ''; |
| 266 | chat.date_short = chatTimestamp.format('l'); | 273 | chat.date_short = chatTimestamp.format('l'); |