feat: add note width modes

This commit is contained in:
lucaronin
2026-04-27 05:34:11 +02:00
parent fb39c6679a
commit f8721f2a1b
34 changed files with 353 additions and 233 deletions

View File

@@ -1,33 +0,0 @@
import { useCallback, useEffect, useState } from 'react'
import type { NoteLayout } from '../types'
import { getVaultConfig, subscribeVaultConfig, updateVaultConfigField } from '../utils/vaultConfigStore'
function isNoteLayout(value: string | null | undefined): value is NoteLayout {
return value === 'centered' || value === 'left'
}
function loadNoteLayout(): NoteLayout {
const stored = getVaultConfig().note_layout
return isNoteLayout(stored) ? stored : 'centered'
}
export function useNoteLayout() {
const [noteLayout, setNoteLayoutState] = useState<NoteLayout>(loadNoteLayout)
useEffect(() => {
return subscribeVaultConfig(() => {
setNoteLayoutState(loadNoteLayout())
})
}, [])
const setNoteLayout = useCallback((layout: NoteLayout) => {
setNoteLayoutState(layout)
updateVaultConfigField('note_layout', layout)
}, [])
const toggleNoteLayout = useCallback(() => {
setNoteLayout(noteLayout === 'left' ? 'centered' : 'left')
}, [noteLayout, setNoteLayout])
return { noteLayout, setNoteLayout, toggleNoteLayout }
}