refac: sticky new chat selected models behaviour

This commit is contained in:
Timothy Jaeryang Baek 2024-11-10 18:01:10 -08:00
parent 36712c1597
commit c92091721b
3 changed files with 67 additions and 47 deletions

View File

@ -141,6 +141,21 @@
})(); })();
} }
$: if (selectedModels) {
saveSessionSelectedModels();
}
const saveSessionSelectedModels = () => {
if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) {
return;
}
if (chatIdProp === '') {
return;
}
sessionStorage.selectedModels = JSON.stringify(selectedModels);
console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels);
};
const showMessage = async (message) => { const showMessage = async (message) => {
const _chatId = JSON.parse(JSON.stringify($chatId)); const _chatId = JSON.parse(JSON.stringify($chatId));
let _messageId = JSON.parse(JSON.stringify(message.id)); let _messageId = JSON.parse(JSON.stringify(message.id));
@ -300,6 +315,7 @@
}; };
onMount(async () => { onMount(async () => {
console.log('mounted');
window.addEventListener('message', onMessageHandler); window.addEventListener('message', onMessageHandler);
$socket?.on('chat-events', chatEventHandler); $socket?.on('chat-events', chatEventHandler);
@ -420,28 +436,10 @@
////////////////////////// //////////////////////////
const initNewChat = async () => { const initNewChat = async () => {
await showControls.set(false); if (sessionStorage.selectedModels) {
await showCallOverlay.set(false); selectedModels = JSON.parse(sessionStorage.selectedModels);
await showOverview.set(false); sessionStorage.removeItem('selectedModels');
await showArtifacts.set(false); } else {
if ($page.url.pathname.includes('/c/')) {
window.history.replaceState(history.state, '', `/`);
}
autoScroll = true;
await chatId.set('');
await chatTitle.set('');
history = {
messages: {},
currentId: null
};
chatFiles = [];
params = {};
if ($page.url.searchParams.get('models')) { if ($page.url.searchParams.get('models')) {
selectedModels = $page.url.searchParams.get('models')?.split(','); selectedModels = $page.url.searchParams.get('models')?.split(',');
} else if ($page.url.searchParams.get('model')) { } else if ($page.url.searchParams.get('model')) {
@ -474,9 +472,9 @@
console.log($config?.default_models.split(',') ?? ''); console.log($config?.default_models.split(',') ?? '');
selectedModels = $config?.default_models.split(','); selectedModels = $config?.default_models.split(',');
} }
}
selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId)); selectedModels = selectedModels.filter((modelId) => $models.map((m) => m.id).includes(modelId));
if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) { if (selectedModels.length === 0 || (selectedModels.length === 1 && selectedModels[0] === '')) {
if ($models.length > 0) { if ($models.length > 0) {
selectedModels = [$models[0].id]; selectedModels = [$models[0].id];
@ -487,6 +485,28 @@
console.log(selectedModels); console.log(selectedModels);
await showControls.set(false);
await showCallOverlay.set(false);
await showOverview.set(false);
await showArtifacts.set(false);
if ($page.url.pathname.includes('/c/')) {
window.history.replaceState(history.state, '', `/`);
}
autoScroll = true;
await chatId.set('');
await chatTitle.set('');
history = {
messages: {},
currentId: null
};
chatFiles = [];
params = {};
if ($page.url.searchParams.get('youtube')) { if ($page.url.searchParams.get('youtube')) {
uploadYoutubeTranscription( uploadYoutubeTranscription(
`https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}` `https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}`

View File

@ -468,7 +468,7 @@
} }
onMount(async () => { onMount(async () => {
console.log('ResponseMessage mounted'); // console.log('ResponseMessage mounted');
await tick(); await tick();
}); });

View File

@ -83,7 +83,7 @@
}; };
onMount(() => { onMount(() => {
console.log('UserMessage mounted'); // console.log('UserMessage mounted');
}); });
</script> </script>