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.

Code improvment, bugs fixes

Smaug673901159afb62ff
diff --git a/frontend/components/Notification.vue b/frontend/components/Notification.vue
index aee6f66b..540d8db8 100644
--- a/frontend/components/Notification.vue
+++ b/frontend/components/Notification.vue
@@ -13,9 +13,7 @@
</template>
<script setup lang="ts">
-import { useNotifications } from '~/stores';
-
-const notifications = computed(() => [...useNotifications().getAll].reverse()); // Create a copy before reversing
+const notifications = computed(() => [...useNotifications().notifications.value].reverse()); // Create a copy before reversing
const close = (id: number) => useNotifications().remove(id);
</script>
<style scoped lang="scss">
diff --git a/frontend/composables/NotificationBus.ts b/frontend/composables/NotificationBus.ts
index e69de29b..3453fb00 100644
--- a/frontend/composables/NotificationBus.ts
+++ b/frontend/composables/NotificationBus.ts
@@ -0,0 +1,28 @@
+export interface Notification {
+ id: number;
+ title: string;
+ message?: string;
+ type: 'success' | 'error' | 'warning' | 'info';
+ timeout?: number;
+}
+
+const notifications = ref<Notification[]>([]);
+
+function add(notification: Omit<Notification, 'id'>) {
+ const id = Math.floor(Math.random() * 100000);
+ notifications.value.push({ id: id, ...notification });
+ setTimeout(() => remove(id), notification.timeout || 3000);
+}
+function remove(id: number) {
+ const index = notifications.value.findIndex(n => n.id == id);
+ if (index == -1) return;
+ notifications.value.splice(index, 1);
+}
+
+export function useNotifications() {
+ return {
+ add,
+ remove,
+ notifications,
+ };
+}
diff --git a/frontend/composables/user.ts b/frontend/composables/user.ts
index f92e8bae..6ab3b2fd 100644
--- a/frontend/composables/user.ts
+++ b/frontend/composables/user.ts
@@ -3,13 +3,11 @@ function logoutUser() {
store
.logout()
.then(() => {
- useNotifications().add({ title: 'Success:', message: 'Logged out', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Logged out' });
store.post_logout();
useRouter().push('/login');
})
- .catch(e => {
- useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });
- });
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
}
function logoutUserAll() {
@@ -17,15 +15,13 @@ function logoutUserAll() {
store
.logout_all()
.then(() => {
- useNotifications().add({ title: 'Success:', message: 'Logged out', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Logged out:' });
setTimeout(() => {
store.post_logout();
useRouter().push('/login');
}, 3000);
})
- .catch(e => {
- useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });
- });
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
}
export { logoutUser, logoutUserAll };
diff --git a/frontend/pages/dashboard/categories/[id]/edit.vue b/frontend/pages/dashboard/categories/[id]/edit.vue
index 941ba2e1..55cbb13c 100644
--- a/frontend/pages/dashboard/categories/[id]/edit.vue
+++ b/frontend/pages/dashboard/categories/[id]/edit.vue
@@ -62,10 +62,10 @@ const updateCategory = async () => {
categoriesStore
.update(category.value)
.then(() => {
- useNotifications().add({ title: 'Success:', message: 'Category updated', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Category updated' });
useRouter().push('/dashboard/categories');
})
- .catch(e => useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 }));
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
};
const deleteCategory = async () => {
useModal().add(new Modal(shallowRef(DeleteModal), { categoryId: category.value?.id || '' }));
diff --git a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
index 172ab270..a3ccdde3 100644
--- a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
+++ b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
@@ -39,12 +39,10 @@ const createCategory = () => {
categoriesStore
.post(category.value)
.then(() => {
- useNotifications().add({ title: 'Category successfully created', message: '', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Category successfully created' });
emit('close');
})
- .catch(e => {
- useNotifications().add({ title: 'Error during creation ', message: e, type: 'error', timeout: 3000 });
- });
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error during creation ', message: e }));
};
</script>
diff --git a/frontend/pages/dashboard/categories/_modals/DeleteCategoryModal.vue b/frontend/pages/dashboard/categories/_modals/DeleteCategoryModal.vue
index 0ab29c9f..d0822e65 100644
--- a/frontend/pages/dashboard/categories/_modals/DeleteCategoryModal.vue
+++ b/frontend/pages/dashboard/categories/_modals/DeleteCategoryModal.vue
@@ -17,11 +17,11 @@ const deleteDoc = () => {
useCategoriesStore()
.delete(props.categoryId)
.then(() => {
- useNotifications().add({ title: 'Category successfully deleted', message: '', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Category successfully deleted' });
emit('close');
})
.catch(e => {
- useNotifications().add({ title: 'Error during deletion', message: e, type: 'error', timeout: 3000 });
+ useNotifications().add({ type: 'error', title: 'Error during deletion', message: e });
});
};
const emit = defineEmits(['close']);
diff --git a/frontend/pages/dashboard/cdn.vue b/frontend/pages/dashboard/cdn.vue
index 70ecbcca..8a2fc0fb 100644
--- a/frontend/pages/dashboard/cdn.vue
+++ b/frontend/pages/dashboard/cdn.vue
@@ -63,7 +63,7 @@ const submitFile = async () => {
await ressourcesStore
.post(body)
.then(r => (fileLink.value = `${CDN}${(r as DB_Ressource).author_id}/${(r as DB_Ressource).transformed_path}`))
- .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e, timeout: 3000 }))
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }))
.finally(() => (isLoading.value = false));
};
@@ -96,8 +96,8 @@ const deleteRessource = async (id: string) => {
if (!id) return;
await ressourcesStore
.delete(id)
- .then(() => useNotifications().add({ type: 'success', title: 'Success', message: 'Ressource deleted successfully', timeout: 3000 }))
- .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e, timeout: 3000 }));
+ .then(() => useNotifications().add({ type: 'success', title: 'Ressource deleted successfully' }))
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
};
</script>
diff --git a/frontend/pages/dashboard/docs/_modals/DeleteDocumentModal.vue b/frontend/pages/dashboard/docs/_modals/DeleteDocumentModal.vue
index 93f6440d..05a0ea87 100644
--- a/frontend/pages/dashboard/docs/_modals/DeleteDocumentModal.vue
+++ b/frontend/pages/dashboard/docs/_modals/DeleteDocumentModal.vue
@@ -17,13 +17,11 @@ const deleteDoc = () => {
useDocumentsStore()
.delete(props.documentId)
.then(() => {
- useNotifications().add({ title: 'Success:', message: 'Document deleted', type: 'success', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Document deleted' });
emit('close');
useRouter().push('/dashboard');
})
- .catch(e => {
- useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });
- });
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
};
const emit = defineEmits(['close']);
const allChildren = useSidebarTree().getSubTreeById(props.documentId);
diff --git a/frontend/pages/dashboard/docs/edit/[id].vue b/frontend/pages/dashboard/docs/edit/[id].vue
index d879966d..3407e1ef 100644
--- a/frontend/pages/dashboard/docs/edit/[id].vue
+++ b/frontend/pages/dashboard/docs/edit/[id].vue
@@ -29,8 +29,8 @@ definePageMeta({ breadcrumb: 'Edit' });
function save(doc: Document) {
store
.update(doc)
- .then(() => notifications.add({ title: 'Document successfully updated', message: '', type: 'success', timeout: 3000 }))
- .catch(e => notifications.add({ title: 'Error:', message: e, type: 'error', timeout: 3000 }));
+ .then(() => notifications.add({ type: 'success', title: 'Document successfully updated' }))
+ .catch(e => notifications.add({ type: 'error', title: 'Error', message: e }));
}
function exit() {
useRouter().push(`/dashboard/docs/${doc_id}`);
diff --git a/frontend/pages/dashboard/docs/new.vue b/frontend/pages/dashboard/docs/new.vue
index 7fc226eb..e7a80615 100644
--- a/frontend/pages/dashboard/docs/new.vue
+++ b/frontend/pages/dashboard/docs/new.vue
@@ -18,10 +18,10 @@ function save(doc: Document) {
store
.post(doc)
.then(d => {
- notifications.add({ title: 'Document successfully posted', message: '', type: 'success', timeout: 3000 });
+ notifications.add({ type: 'success', title: 'Document successfully posted' });
useRouter().push(`/dashboard/docs/edit/${d.id}`);
})
- .catch(e => notifications.add({ title: 'Error: ' + e, message: '', type: 'error', timeout: 3000 }));
+ .catch(e => notifications.add({ type: 'error', title: 'Error', message: e }));
}
function exit() {
useRouter().push('/dashboard');
diff --git a/frontend/pages/dashboard/import.vue b/frontend/pages/dashboard/import.vue
index f9880c77..4a111289 100644
--- a/frontend/pages/dashboard/import.vue
+++ b/frontend/pages/dashboard/import.vue
@@ -67,28 +67,25 @@ async function submit() {
const file = selectedFile.value;
const fileContent = await analyseFile(file);
const valid = validateFileStructure(fileContent);
- if (!valid) useNotifications().add({ type: 'error', title: 'Invalid file structure', timeout: 3000 });
- else useNotifications().add({ type: 'success', title: 'File structure is valid', timeout: 3000 });
+ if (!valid) useNotifications().add({ type: 'error', title: 'Invalid file structure' });
+ else useNotifications().add({ type: 'success', title: 'File structure is valid' });
files_to_import.value = compareDocumentsAndLocal(fileContent);
} catch (e) {
- if (e instanceof Error) useNotifications().add({ type: 'error', title: 'Error while analysing file', message: e.message, timeout: 3000 });
- else useNotifications().add({ type: 'error', title: 'Error while analysing file', message: 'Unknown error', timeout: 3000 });
+ if (e instanceof Error) useNotifications().add({ type: 'error', title: 'Error while analysing file', message: e.message });
+ else useNotifications().add({ type: 'error', title: 'Error while analysing file', message: 'Unknown error' });
selectedFile.value = null;
}
}
function importDoc(file: DB_Document) {
const fileContent = files_to_import.value.find(i => i.id === file.id);
- if (!fileContent) {
- useNotifications().add({ type: 'error', title: 'File not found', timeout: 3000 });
- return;
- }
+ if (!fileContent) return useNotifications().add({ type: 'error', title: 'File not found' });
prepareNewDocuments([fileContent]);
uploadDocument(fileContent)
.then(() => {
- useNotifications().add({ type: 'success', title: 'Document imported successfully', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Document imported successfully' });
files_to_import.value = files_to_import.value.filter(i => i.id !== file.id);
})
- .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing document', message: e, timeout: 3000 }));
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing document', message: e }));
}
function importAllDocs() {
if (!files_to_import.value.length) return;
@@ -96,10 +93,10 @@ function importAllDocs() {
prepareNewDocuments(files);
uploadDocuments(files)
.then(() => {
- useNotifications().add({ type: 'success', title: 'Documents imported successfully', timeout: 3000 });
+ useNotifications().add({ type: 'success', title: 'Documents imported successfully' });
files_to_import.value = [];
})
- .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing documents', message: e, timeout: 3000 }));
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing documents', message: e }));
}
</script>
diff --git a/frontend/pages/dashboard/settings/_views/backups.vue b/frontend/pages/dashboard/settings/_views/backups.vue
index 84341908..9681d569 100644
--- a/frontend/pages/dashboard/settings/_views/backups.vue
+++ b/frontend/pages/dashboard/settings/_views/backups.vue
@@ -30,9 +30,7 @@ async function submitFile() {
isLoading.value = true;
const result = await makeRequest<{ link: string }>('ressources/backup', 'GET', {});
isLoading.value = false;
- if (result.status != 'success') {
- return useNotifications().add({ type: 'error', title: 'Error', message: result.message, timeout: 3000 });
- }
+ if (result.status != 'success') return useNotifications().add({ type: 'error', title: 'Error', message: result.message });
downloadLink.value = `${CDN}${result.result?.link || ''}`;
}
diff --git a/frontend/pages/dashboard/settings/_views/profile.vue b/frontend/pages/dashboard/settings/_views/profile.vue
index ed94f470..94163559 100644
--- a/frontend/pages/dashboard/settings/_views/profile.vue
+++ b/frontend/pages/dashboard/settings/_views/profile.vue
@@ -58,8 +58,8 @@ const updateUser = async () => {
await uploadAvatar();
userStore
.update(userStore.user)
- .then(() => useNotifications().add({ title: 'Success:', message: 'User updated', type: 'success', timeout: 3000 }))
- .catch(e => useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 }));
+ .then(() => useNotifications().add({ type: 'success', title: 'User updated' }))
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
};
</script>
diff --git a/frontend/pages/dashboard/settings/_views/security.vue b/frontend/pages/dashboard/settings/_views/security.vue
index 8b0e7e1e..55636771 100644
--- a/frontend/pages/dashboard/settings/_views/security.vue
+++ b/frontend/pages/dashboard/settings/_views/security.vue
@@ -39,29 +39,31 @@
<script setup lang="ts">
import { parseUserAgent } from '~/helpers/utils';
-const route = useRoute();
-const currentPage = ref(route.query.p || 'profile');
const store = useUserStore();
const passwordValue = ref('');
const passwordConfirmValue = ref('');
const err_password_not_match = ref(false);
-watchEffect(() => (currentPage.value = route.query.p || 'profile'));
-
const changePassword = async () => {
if (!store.user) return;
if (passwordValue.value !== passwordConfirmValue.value) return (err_password_not_match.value = true);
- store.updatePassword(passwordValue.value);
+ store
+ .updatePassword(passwordValue.value)
+ .then(() => {
+ passwordValue.value = '';
+ passwordConfirmValue.value = '';
+ err_password_not_match.value = false;
+ useNotifications().add({ type: 'success', title: 'Password changed successfully' });
+ })
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error during password saving', message: e.message }));
};
-
-watchEffect(() => (currentPage.value = route.query.p || 'profile'));
</script>
<style scoped lang="scss">
.last_connection {
align-items: center;
padding: 0.3rem 0.5rem;
- border-radius: 15px;
+ border-radius: 10px;
background-color: var(--bg-contrast-2);
}
p {
diff --git a/frontend/pages/dashboard/settings/index.vue b/frontend/pages/dashboard/settings/index.vue
index 6f3fcf0f..de80f486 100644
--- a/frontend/pages/dashboard/settings/index.vue
+++ b/frontend/pages/dashboard/settings/index.vue
@@ -10,6 +10,7 @@
<div class="email">{{ store.user.email }}</div>
</div>
</div>
+ <span>General</span>
<NuxtLink to="?p=profile"><Icon fill="var(--font-color)" name="profil" />My profile</NuxtLink>
<NuxtLink to="?p=preferences"><Icon fill="var(--font-color)" name="settings" />Preferences</NuxtLink>
<NuxtLink to="?p=security"><Icon fill="var(--font-color)" name="security" />Security</NuxtLink>
diff --git a/frontend/stores/index.ts b/frontend/stores/index.ts
index 6d2c0d89..a15080c6 100644
--- a/frontend/stores/index.ts
+++ b/frontend/stores/index.ts
@@ -1,6 +1,5 @@
export * from './documents.store';
export * from './categories.store';
-export * from './notifications.store';
export * from './ressources.store';
export * from './user.store';
export type * from './db_strustures';
diff --git a/frontend/stores/notifications.store.ts b/frontend/stores/notifications.store.ts
deleted file mode 100644
index fff05a75..00000000
--- a/frontend/stores/notifications.store.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-export interface Notification {
- id: number;
- title: string;
- message?: string;
- type: 'success' | 'error' | 'warning' | 'info';
- timeout: number;
-}
-
-export const useNotifications = defineStore('notifications', {
- state: () => ({
- notifications: ref<Notification[]>([]),
- }),
-
- getters: {
- getAll: state => state.notifications,
- },
-
- actions: {
- // Add a notification
- add: function (notification: Omit<Notification, 'id'>) {
- const id = Math.floor(Math.random() * 100000);
- this.notifications.push({ id: id, ...notification });
- setTimeout(() => this.remove(id), notification.timeout);
- },
-
- // Remove a notification
- remove: function (id: number) {
- const index = this.notifications.findIndex(n => n.id == id);
- if (index == -1) return;
- this.notifications.splice(index, 1);
- },
- },
-});
diff --git a/frontend/stores/user.store.ts b/frontend/stores/user.store.ts
index fffc440b..f82c0e8f 100644
--- a/frontend/stores/user.store.ts
+++ b/frontend/stores/user.store.ts
@@ -58,8 +58,7 @@ export const useUserStore = defineStore('user', {
if (!this.user) return;
const request = await makeRequest(`users/${this.user.id}/password`, 'PATCH', { password: newPassword });
if (request.status === 'success') {
- this.user = request.result as User;
- return resolve(this.user);
+ return resolve(true);
} else reject(request.message);
});
},