Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

fix: fix errors with new preferences system & fix types

Smaug6739d030b03ce9e4
diff --git a/frontend/app/App.vue b/frontend/app/App.vue
index 4fff8138..2b820421 100644
--- a/frontend/app/App.vue
+++ b/frontend/app/App.vue
@@ -8,7 +8,6 @@
</template>
<script setup lang="ts">
-// @ts-expect-error ignore missing types
import 'virtual:svg-icons-register';
useFavicon();
diff --git a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue b/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
index 9ca24df5..c8ed2a0e 100644
--- a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
+++ b/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
@@ -82,10 +82,10 @@ const uploadsHandlers = createUploadsHandlers({ resourcesStore, insertText: (t:
const state = createEditorState({
initialDoc: document.value.content || '',
- preferences,
+ spellCheck: preferences.get('editorSpellCheck'),
themeExtension: loadTheme(),
keymaps: createKeymaps(commands),
- snippetSource: createSnippetSource(preferences),
+ snippetSource: createSnippetSource(preferences.get('editorSnippetsEnabled'), preferences.get('snippets')),
onDocChanged: () => {
updateDocumentContent();
autoSaveConditional();
diff --git a/frontend/app/components/MarkdownEditor/modules/editorState.ts b/frontend/app/components/MarkdownEditor/modules/editorState.ts
index 54e1a008..6547e08e 100644
--- a/frontend/app/components/MarkdownEditor/modules/editorState.ts
+++ b/frontend/app/components/MarkdownEditor/modules/editorState.ts
@@ -7,7 +7,7 @@ import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
export interface CreateEditorStateParams {
initialDoc: string;
- preferences: ReturnType<typeof import('~/composables/usePreferences').usePreferences>;
+ spellCheck: Ref<boolean>;
themeExtension: Extension;
keymaps: readonly KeyBinding[];
snippetSource: object;
@@ -21,7 +21,6 @@ export function createEditorState(params: CreateEditorStateParams) {
const updateListener = EditorView.updateListener.of(v => {
if (v.docChanged) params.onDocChanged();
});
-
return EditorState.create({
doc: params.initialDoc,
extensions: [
@@ -42,7 +41,7 @@ export function createEditorState(params: CreateEditorStateParams) {
EditorView.lineWrapping,
EditorState.allowMultipleSelections.of(true),
EditorView.contentAttributes.of({
- spellcheck: params.preferences.get('editorSpellCheck').value ? 'true' : 'false',
+ spellcheck: params.spellCheck.value ? 'true' : 'false',
autocorrect: 'on',
autocapitalize: 'on',
}),
diff --git a/frontend/app/components/MarkdownEditor/modules/editorUtils.ts b/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
index 99453b0a..97481b76 100644
--- a/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
+++ b/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
@@ -43,10 +43,10 @@ function isInsideMath(context: CompletionContext): boolean {
return singleCountBefore % 2 === 1;
}
-export function createSnippetSource(preferences: ReturnType<typeof import('~/composables/usePreferences').usePreferences>) {
+export function createSnippetSource(enabled: Ref<boolean>, snippets: Ref<ANode<string>[]>) {
return function snippetSource(context: CompletionContext) {
- if (!preferences.get('editorSnippetsEnabled').value) return null;
- const allSnippets = preferences.get('snippets').value;
+ if (!enabled.value) return null;
+ const allSnippets = snippets.value;
const inMath = isInsideMath(context);
diff --git a/frontend/app/pages/dashboard/settings/_views/backups.vue b/frontend/app/pages/dashboard/settings/_views/backups.vue
index 26e6f60a..d312cc0e 100644
--- a/frontend/app/pages/dashboard/settings/_views/backups.vue
+++ b/frontend/app/pages/dashboard/settings/_views/backups.vue
@@ -164,7 +164,7 @@ async function startBackup() {
const result = await makeRequest<{ job_id: string; message: string }>('backup', 'POST', {
include_documents: options.includeDocuments,
include_files: options.includeFiles,
- local_data: options.includeSettings ? pref.all : null,
+ local_data: options.includeSettings ? pref.preferences : null,
include_metadata: options.includeMetadata,
});
diff --git a/frontend/app/stores/preferences/preferences.ts b/frontend/app/stores/preferences/preferences.ts
index 64811e72..0e1728e2 100644
--- a/frontend/app/stores/preferences/preferences.ts
+++ b/frontend/app/stores/preferences/preferences.ts
@@ -87,23 +87,22 @@ export const usePreferencesStore = defineStore('preferences', () => {
console.warn('[Preferences] Failed to fetch from backend', e);
}
}
-
const computedCache = new Map<PreferenceKey, WritableComputedRef<Preferences[PreferenceKey]>>();
- function get<K extends PreferenceKey>(key: K) {
- if (!computedCache.has(key)) {
- computedCache.set(
- key,
- computed({
- get: () => preferences[key] as Preferences[K],
- set: (val: Preferences[K]) => {
- preferences[key] = val;
- savePreferences();
- },
- }),
- );
+ function get<K extends PreferenceKey>(key: K): WritableComputedRef<Preferences[K]> {
+ let existing = computedCache.get(key) as WritableComputedRef<Preferences[K]> | undefined;
+
+ if (!existing) {
+ existing = computed<Preferences[K]>({
+ get: () => preferences[key],
+ set: val => {
+ preferences[key] = val;
+ savePreferences();
+ },
+ });
+
+ computedCache.set(key, existing);
}
-
- return computedCache.get(key);
+ return existing;
}
function set<K extends PreferenceKey>(key: K, value: Preferences[K]) {
diff --git a/frontend/app/types/virtual-svg-icons.d.ts b/frontend/app/types/virtual-svg-icons.d.ts
new file mode 100644
index 00000000..0b76b4c1
--- /dev/null
+++ b/frontend/app/types/virtual-svg-icons.d.ts
@@ -0,0 +1,9 @@
+declare module 'virtual:svg-icons-register' {
+ const content: Record<string, unknown>;
+ export default content;
+}
+
+declare module 'virtual:svg-icons-names' {
+ const ids: string[];
+ export default ids;
+}