Files
veridian/app/composables/useSidebar.ts
T
zoeissleeping 59bb7fbc12 Performance enhancements galore! New themining system
This is once again a huge commit, but its mostly performance
improvements along with some bug fixes and refactoring. It also includes
changes to the theming systems. I'm still not 100% happy with the
theming system, but its better than before.

Model fetching has been dramatically improved! Nearly all the important
computation and pre-processing has been moved to the server. This has
also somehow fixed the way model details are loaded, which was causing
many models to be missing their details despite models.dev having them.

The markdown renderer has once again been changed, but I'm mostly
certain that this is the last time major changes will be made to it. The
renderer is not spamming components, bloating memory usage, and its not
using a bug prone custom written chunking system.

There's also a lot more that I haven't mentioned and honestly forgot. I
need to get better commit hygiene tbh.
2026-02-20 00:20:50 -06:00

50 lines
1.4 KiB
TypeScript

export const useSidebar = () => {
const open = useState<boolean>('sidebar:open', () => true);
const sidebarWidth = useState<number>('sidebar:width', () => {
return Number(
useCookie('sidebar:width', {
default: () => '250',
maxAge: 60 * 60 * 24 * 30,
}).value,
);
});
// I still want the state to update when the cookie change, like it does for the theme cookies
// but I dont want to use the cookie value as the state value because then when we change the
// cookie value, we thrash the hell out of the cookie and gobble CPU cycles
watch(useCookie('sidebar:width'), (value) => {
sidebarWidth.value = Number(value);
});
const toggle = () => {
open.value = !open.value;
};
const close = () => {
open.value = false;
};
const openSidebar = () => {
open.value = true;
};
const resize = (width: number) => {
const minWidth = 200;
const maxWidth = 400;
const clampedWidth = Math.max(minWidth, Math.min(maxWidth, width));
sidebarWidth.value = clampedWidth;
};
const saveWidth = () => {
useCookie('sidebar:width').value = sidebarWidth.value.toString();
};
return {
open: readonly(open),
toggle,
close,
openSidebar,
sidebarWidth: readonly(sidebarWidth),
resize,
saveWidth,
};
};