update preferences

This commit is contained in:
Jesse Winton
2025-07-10 11:44:58 -04:00
parent ea1341b49e
commit 4a756bfb69
3 changed files with 16 additions and 18 deletions
+2 -4
View File
@@ -6,7 +6,7 @@
disableBodySelect,
enabledBodySelect,
getChatWidthFromPrefs,
saveProjectPrefs
saveImagineProjectPrefs
} from '$lib/helpers/studioLayout.js';
import { createStreamParser } from '$lib/components/studio/chat/parser.js';
import { sdk } from '$lib/stores/sdk.js';
@@ -23,8 +23,6 @@
}
});
console.log(page.data);
let resizer = $state(null);
let resizerLeftPosition = $state(
page.data?.subNavigation
@@ -82,7 +80,7 @@
resizerLeftPosition = 500;
}
const saveWidth = page.data?.subNavigation ? resizerLeftPosition - 24 : resizerLeftPosition;
saveProjectPrefs(page.data?.project.$id, 'studioChatWidth', saveWidth);
saveImagineProjectPrefs(page.data?.project.$id, 'studioChatWidth', saveWidth);
isResizing = false;
window.removeEventListener('mousemove', resize);
+10 -10
View File
@@ -16,19 +16,18 @@ type ImaginePrefs = {
[projectId: string]: ProjectPrefs;
};
const getImaginePrefs = () => {
const currentPrefs = userPreferences();
return currentPrefs?.imagine as unknown as ImaginePrefs;
};
const getProjectPrefs = (projectId: string): ProjectPrefs => {
const currentPrefs = userPreferences();
const projectPrefs = currentPrefs?.imagine;
return projectPrefs[projectId];
const imaginePrefs = currentPrefs?.imagine;
const projectPrefs = imaginePrefs?.[projectId] ?? ({} as ProjectPrefs);
return projectPrefs;
};
export function getChatWidthFromPrefs(projectId: string): number {
const projectPrefs = getProjectPrefs(projectId);
console.log(projectPrefs);
if (projectPrefs?.studioChatWidth) {
if (window) {
const maxSize = page.data?.subNavigation
@@ -64,20 +63,21 @@ export function getStudioView(projectId: string) {
return projectPrefs?.studioView as 'editor' | 'preview' | null;
}
export function saveProjectPrefs(
export function saveImagineProjectPrefs(
projectId: string,
key: string,
value: string | number | boolean
): void {
const currentPrefs = userPreferences();
const imaginePrefs = getImaginePrefs();
const imaginePrefs = currentPrefs?.imagine as unknown as ImaginePrefs;
const projectPrefs = getProjectPrefs(projectId);
const newPrefs = {
...currentPrefs,
imagine: {
...imaginePrefs,
[projectId]: {
...imaginePrefs[projectId],
...projectPrefs,
[key]: value
}
}
@@ -19,7 +19,7 @@
getStudioView,
getTerminalHeightFromPrefs,
getTerminalOpenFromPrefs,
saveProjectPrefs
saveImagineProjectPrefs
} from '$lib/helpers/studioLayout';
import { showChat } from '$lib/stores/chat';
import { default as IconChatLayout } from '$routes/(console)/project-[region]-[project]/studio/assets/chat-layout.svelte';
@@ -39,7 +39,7 @@
function changeView(newView: 'preview' | 'editor') {
view = newView;
saveProjectPrefs(data.project.$id, 'studioView', newView);
saveImagineProjectPrefs(data.project.$id, 'studioView', newView);
}
$effect(() => {
@@ -62,7 +62,7 @@
$effect(() => {
if (terminalOpen !== undefined) {
//saveImaginePrefs('studioTerminalOpen', terminalOpen);
saveImagineProjectPrefs(data.project.$id, 'studioTerminalOpen', terminalOpen);
}
});
@@ -106,7 +106,7 @@
function stopResize() {
isResizing = false;
//saveImaginePrefs('studioTerminalHeight', resizerTopPosition);
saveImagineProjectPrefs(data.project.$id, 'studioTerminalHeight', resizerTopPosition);
window.removeEventListener('mousemove', resize);
window.removeEventListener('mouseup', stopResize);
window.removeEventListener('touchmove', resize);