fix: apply wide page preference instantly
This commit is contained in:
1 parent
c097383d3a
commit
08a6d7bd1d
3 files changed
+28
-9
No files matched your search
@@ -4,7 +4,11 @@ const STORAGE_KEY = 'collabtable-wide-layout';
|
||||
|
||||
function loadInitialWide() {
|
||||
if (!browser) return false;
|
||||
return localStorage.getItem(STORAGE_KEY) === 'true';
|
||||
try {
|
||||
return localStorage.getItem(STORAGE_KEY) === 'true';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let wide = $state(loadInitialWide());
|
||||
@@ -15,17 +19,18 @@ export const layoutState = {
|
||||
},
|
||||
setWide(next) {
|
||||
wide = next;
|
||||
if (browser) localStorage.setItem(STORAGE_KEY, String(next));
|
||||
if (!browser) return;
|
||||
|
||||
document.documentElement.toggleAttribute('data-wide-layout', next);
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, String(next));
|
||||
} catch {
|
||||
// Ignore storage failures; the current page can still use the selected layout width.
|
||||
}
|
||||
},
|
||||
toggle() {
|
||||
layoutState.setWide(!wide);
|
||||
},
|
||||
};
|
||||
|
||||
if (browser) {
|
||||
$effect.root(() => {
|
||||
$effect(() => {
|
||||
document.documentElement.toggleAttribute('data-wide-layout', wide);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (browser) document.documentElement.toggleAttribute('data-wide-layout', wide);
|
||||
@@ -34,6 +34,13 @@
|
||||
padding: 1rem 0 1rem;
|
||||
}
|
||||
|
||||
/* The page-width preference is owned by each consumer application. The shared shell only
|
||||
provides the common width cap, so this global hook lets the current app widen that shell as
|
||||
soon as its settings checkbox updates the document attribute. */
|
||||
html[data-wide-layout='true'] .sc-main {
|
||||
width: calc(100% - 2rem);
|
||||
}
|
||||
|
||||
.sc-header {
|
||||
position: sticky;
|
||||
z-index: 20;
|
||||
|
||||
@@ -36,6 +36,13 @@
|
||||
padding: 1rem 0 1rem;
|
||||
}
|
||||
|
||||
/* The page-width preference is owned by each consumer application. The shared shell only
|
||||
provides the common width cap, so this global hook lets the current app widen that shell as
|
||||
soon as its settings checkbox updates the document attribute. */
|
||||
html[data-wide-layout='true'] .sc-main {
|
||||
width: calc(100% - 2rem);
|
||||
}
|
||||
|
||||
.sc-header {
|
||||
position: sticky;
|
||||
z-index: 20;
|
||||
|
||||
Reference in new issue
Block a user