feat: save user settings to db

This commit is contained in:
Timothy J. Baek
2024-05-26 22:47:42 -07:00
parent 9d4c07b76a
commit ccbafca74c
16 changed files with 235 additions and 70 deletions
+19 -8
View File
@@ -42,6 +42,7 @@
import type { Writable } from 'svelte/store';
import type { i18n as i18nType } from 'i18next';
import Banner from '../common/Banner.svelte';
import { getUserSettings } from '$lib/apis/users';
const i18n: Writable<i18nType> = getContext('i18n');
@@ -154,10 +155,13 @@
$models.map((m) => m.id).includes(modelId) ? modelId : ''
);
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
settings.set({
..._settings
});
const userSettings = await getUserSettings(localStorage.token);
if (userSettings) {
settings.set(userSettings.ui);
} else {
settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
}
const chatInput = document.getElementById('chat-textarea');
setTimeout(() => chatInput?.focus(), 0);
@@ -187,11 +191,18 @@
: convertMessagesToHistory(chatContent.messages);
title = chatContent.title;
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
const userSettings = await getUserSettings(localStorage.token);
if (userSettings) {
await settings.set(userSettings.ui);
} else {
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
}
await settings.set({
..._settings,
system: chatContent.system ?? _settings.system,
params: chatContent.options ?? _settings.params
...$settings,
system: chatContent.system ?? $settings.system,
params: chatContent.options ?? $settings.params
});
autoScroll = true;
await tick();