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.

Improve command center code style

Smaug6739f040419f9a12
diff --git a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
index dfdbb449..4f0094db 100644
--- a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
+++ b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
@@ -48,8 +48,8 @@
placeholder="Add tag filter..."
class="tag-input"
@keydown.enter="handleEnter"
- @keydown.arrow-up="handleArrowUp"
- @keydown.arrow-down="handleArrowDown"
+ @keydown.arrow-up="tagHandleArrowUp"
+ @keydown.arrow-down="tagHandleArrowDown"
@keydown.escape="hideSuggestions"
@input="handleTagInput"
@focus="showSuggestions = true"
@@ -76,8 +76,8 @@
<div class="selected-tags">
<span v-for="tag in selectedTags" :key="tag" class="tag-chip">
{{ tag }}
- <button class="remove-tag" @click="removeTag(tag)">
- <Icon name="close" fill="var(--font-color)" />
+ <button class="remove-tag" @click.stop="removeTag(tag)">
+ <Icon name="close" fill="var(--font-color)" class="no-close" />
</button>
</span>
</div>
@@ -97,41 +97,27 @@
</div>
<div class="search-results">
- <div v-if="filteredDocuments.length === 0" class="no-results">
- <Icon name="search" class="no-results-icon" />
- <p>No documents match your filters</p>
- </div>
-
- <div v-else class="documents-list">
- <div v-for="doc in filteredDocuments" :key="doc.id" class="document-item" @click="selectDocument(doc)">
- <Icon :name="getDocumentIcon(doc)" class="document-icon" fill="var(--font-color)" />
- <div class="document-info">
- <div class="document-title">{{ doc.name }}</div>
- <div class="document-meta">
- <span class="document-category">{{ getCategoryName(doc.category) }}</span>
- <span class="document-date">{{ formatDate(doc[dateType === 'created' ? 'created_timestamp' : 'updated_timestamp']) }}</span>
- </div>
- <div v-if="doc.tags" class="document-tags">
- <span v-for="tag in parseTags(doc.tags)" :key="tag" class="tag">{{ tag }}</span>
- </div>
- </div>
- <Icon name="new_tab" class="navigate-icon" fill="var(--font-color)" />
- </div>
- </div>
+ <SearchResultsList
+ :items="flattenedItems"
+ :selected-index="selectedIndex"
+ empty-text="No documents match your filters"
+ empty-icon="search"
+ @update-selected-index="$emit('updateSelectedIndex', $event)"
+ />
</div>
</div>
</template>
<script setup lang="ts">
+import SearchResultsList from './SearchResultsList.vue';
import type { Document } from '~/stores';
-import Icon from '~/components/Icon.vue';
-
const props = defineProps<{
- documents: Document[];
+ query: string;
+ selectedIndex: number;
}>();
-const emit = defineEmits<{
- selectDocument: [document: Document];
+defineEmits<{
+ updateSelectedIndex: [index: number];
}>();
const dateFrom = ref('');
@@ -144,63 +130,38 @@ const showFilters = ref(true);
const showSuggestions = ref(false);
const selectedSuggestionIndex = ref(0);
-const categoryStore = useCategoriesStore();
+const documentStore = useDocumentsStore();
const categoriesTree = new TreeStructure(useSidebarTree().categories.value).generateTree().filter(i => i.data.type === 'category' && i.data.role == 2);
-const allTags = computed(() => {
- const tags = new Set<string>();
- props.documents.forEach(doc => {
- if (doc.tags) {
- parseTags(doc.tags).forEach(tag => tags.add(tag));
- }
- });
- return Array.from(tags).sort();
-});
-
const filteredTagSuggestions = computed(() => {
if (!tagInput.value) return [];
const input = tagInput.value.toLowerCase();
- return allTags.value.filter(tag => tag.toLowerCase().includes(input) && !selectedTags.value.includes(tag)).slice(0, 5);
+ return documentStore.allTags.filter(tag => tag.toLowerCase().includes(input) && !selectedTags.value.includes(tag)).slice(0, 5);
});
const filteredDocuments = computed(() => {
- let filtered = [...props.documents];
-
- if (selectedCategory.value) {
- filtered = filtered.filter(doc => doc.category === selectedCategory.value);
- }
-
- if (dateFrom.value) {
- const fromDate = new Date(dateFrom.value).getTime();
- filtered = filtered.filter(doc => {
- const docDate = parseInt(doc[dateType.value === 'created' ? 'created_timestamp' : 'updated_timestamp']);
- return docDate >= fromDate;
- });
- }
-
- if (dateTo.value) {
- const toDate = new Date(dateTo.value).getTime();
- filtered = filtered.filter(doc => {
- const docDate = parseInt(doc[dateType.value === 'created' ? 'created_timestamp' : 'updated_timestamp']);
- return docDate <= toDate;
- });
- }
-
- if (selectedTags.value.length > 0) {
- filtered = filtered.filter(doc => {
- if (!doc.tags) return false;
- const docTags = parseTags(doc.tags);
- return selectedTags.value.some(tag => docTags.includes(tag));
- });
- }
-
- return filtered.sort((a, b) => {
- const aDate = parseInt(a[dateType.value === 'created' ? 'created_timestamp' : 'updated_timestamp']);
- const bDate = parseInt(b[dateType.value === 'created' ? 'created_timestamp' : 'updated_timestamp']);
- return bDate - aDate;
+ return documentStore.search({
+ query: props.query,
+ category: selectedCategory.value,
+ dateType: dateType.value,
+ fromDate: dateFrom.value ? new Date(dateFrom.value) : undefined,
+ toDate: dateTo.value ? new Date(dateTo.value) : undefined,
+ tags: selectedTags.value,
});
});
+const flattenedItems = computed(() => {
+ return filteredDocuments.value.map((doc, idx) => ({
+ id: doc.id,
+ icon: getDocumentIcon(doc),
+ title: doc.name,
+ description: doc.tags ? `#${String(doc.tags)}` : 'Document',
+ path: `/dashboard/docs/${doc.id}`,
+ section: '',
+ globalIndex: idx,
+ }));
+});
+
function addTag() {
const tag = tagInput.value.trim();
if (tag && !selectedTags.value.includes(tag)) {
@@ -237,14 +198,14 @@ function handleEnter(event: KeyboardEvent) {
}
}
-function handleArrowUp(event: KeyboardEvent) {
+function tagHandleArrowUp(event: KeyboardEvent) {
event.preventDefault();
if (showSuggestions.value && filteredTagSuggestions.value.length > 0) {
selectedSuggestionIndex.value = selectedSuggestionIndex.value > 0 ? selectedSuggestionIndex.value - 1 : filteredTagSuggestions.value.length - 1;
}
}
-function handleArrowDown(event: KeyboardEvent) {
+function tagHandleArrowDown(event: KeyboardEvent) {
event.preventDefault();
if (showSuggestions.value && filteredTagSuggestions.value.length > 0) {
selectedSuggestionIndex.value = selectedSuggestionIndex.value < filteredTagSuggestions.value.length - 1 ? selectedSuggestionIndex.value + 1 : 0;
@@ -266,36 +227,13 @@ function clearFilters() {
selectedCategory.value = '';
}
-function selectDocument(doc: Document) {
- emit('selectDocument', doc);
-}
-
function getDocumentIcon(doc: Document) {
if (doc.pinned === 1) return 'pin';
if (doc.pinned === 2) return 'pin';
return 'files';
}
-function getCategoryName(categoryId?: string) {
- if (!categoryId) return 'Uncategorized';
- const category = categoryStore.getById(categoryId);
- return category?.name || 'Unknown';
-}
-
-function formatDate(timestamp: string) {
- const date = new Date(parseInt(timestamp));
- return date.toLocaleDateString();
-}
-
-function parseTags(tags: string): string[] {
- if (typeof tags === 'string') {
- return tags
- .split(',')
- .map(tag => tag.trim())
- .filter(Boolean);
- }
- return [];
-}
+defineExpose({ flattenedItems });
</script>
<style scoped lang="scss">
@@ -458,7 +396,6 @@ function parseTags(tags: string): string[] {
}
.tag-suggestions {
- position: absolute;
top: 100%;
right: 48px;
left: 0;
@@ -520,7 +457,6 @@ function parseTags(tags: string): string[] {
&:hover {
color: white;
- background: var(--text-muted);
}
}
}
@@ -600,7 +536,7 @@ function parseTags(tags: string): string[] {
}
}
-.documents-list {
+.search-results-list {
max-height: 100%;
padding: 8px 0;
overflow-y: auto;
diff --git a/frontend/app/components/CommandCenter/QuickSearchTab.vue b/frontend/app/components/CommandCenter/QuickSearchTab.vue
index 22b40e60..c57c77d2 100644
--- a/frontend/app/components/CommandCenter/QuickSearchTab.vue
+++ b/frontend/app/components/CommandCenter/QuickSearchTab.vue
@@ -1,48 +1,26 @@
<template>
<div class="quick-search-tab">
- <div class="search-results">
- <div v-if="searchQuery && flattenedItems.length === 0" class="no-results">
- <Icon fill="var(--font-color)" name="search" class="no-results-icon" />
- <p>No results found for "{{ searchQuery }}"</p>
- </div>
-
- <div v-else class="search-results-list">
- <div v-for="(items, section) in groupedResults" :key="section" class="section">
- <div class="section-title">{{ section }}</div>
- <NuxtLink
- v-for="item in items"
- :key="item.id"
- class="search-result-item"
- :to="item.path"
- :class="{ selected: selectedIndex === item.globalIndex }"
- @click="$emit('selectItem')"
- @mouseenter="$emit('updateSelectedIndex', item.globalIndex)"
- >
- <Icon :name="item.icon" class="result-icon" fill="var(--font-color)" />
- <div class="result-content">
- <span class="result-title">{{ item.title }}</span>
- <span class="result-description">{{ item.description }}</span>
- </div>
- <Icon name="new_tab" class="navigate-icon" fill="var(--font-color)" />
- </NuxtLink>
- </div>
- </div>
- </div>
+ <SearchResultsList
+ :items="flattenedItems"
+ :selected-index="selectedIndex"
+ empty-text='No results found for "{{ searchQuery }}"'
+ empty-icon="search"
+ @update-selected-index="$emit('updateSelectedIndex', $event)"
+ />
</div>
</template>
<script setup lang="ts">
import { quickActions, availablePages, type SearchResult, type BaseCommand } from '@/helpers/navigation';
-import Icon from '~/components/Icon.vue';
-import type { Document } from '~/stores';
+import SearchResultsList from './SearchResultsList.vue';
const props = defineProps<{
searchQuery: string;
selectedIndex: number;
- documents: Document[];
}>();
+const documentStore = useDocumentsStore();
-defineEmits<{ selectItem: []; updateSelectedIndex: [index: number] }>();
+defineEmits<{ updateSelectedIndex: [index: number] }>();
function tokenize(text: string) {
return text.trim().toLowerCase().split(/\s+/).filter(Boolean);
@@ -62,11 +40,8 @@ function filterByTokens<T>(items: T[], getText: (item: T) => string): T[] {
const filteredActions = computed(() => filterByTokens(quickActions, a => `${a.title} ${a.description}`));
const filteredDocuments = computed<SearchResult[]>(() =>
- filterByTokens(props.documents, d => {
- const name = d.name || '';
- const tags = Array.isArray(d.tags) ? d.tags.join(' ') : String(d.tags || '');
- return `${name} ${tags}`;
- })
+ documentStore
+ .search({ query: props.searchQuery })
.slice(0, 5)
.map(d => ({
id: d.id,
@@ -132,13 +107,6 @@ const flattenedItems = computed(() => {
return items;
});
-const groupedResults = computed(() => {
- return flattenedItems.value.reduce((acc, item) => {
- (acc[item.section] ||= []).push(item);
- return acc;
- }, {} as Record<string, typeof flattenedItems.value>);
-});
-
defineExpose({ flattenedItems });
</script>
diff --git a/frontend/app/components/CommandCenter/SearchResultsList.vue b/frontend/app/components/CommandCenter/SearchResultsList.vue
new file mode 100644
index 00000000..4191295c
--- /dev/null
+++ b/frontend/app/components/CommandCenter/SearchResultsList.vue
@@ -0,0 +1,150 @@
+<template>
+ <div>
+ <div v-if="items.length === 0" class="no-results">
+ <Icon :name="emptyIcon" class="no-results-icon" fill="var(--font-color)" />
+ <p>{{ emptyText }}</p>
+ </div>
+ <div v-else class="search-results-list">
+ <div v-for="(group, section) in groupedItems" :key="section" class="section">
+ <div v-if="section" class="section-title">{{ section }}</div>
+ <NuxtLink
+ v-for="item in group"
+ :key="item.id"
+ class="search-result-item"
+ :to="item.path"
+ :class="{ selected: selectedIndex === item.globalIndex }"
+ @mouseenter="$emit('updateSelectedIndex', item.globalIndex)"
+ >
+ <Icon :name="item.icon" class="result-icon" fill="var(--font-color)" />
+ <div class="result-content">
+ <span class="result-title">{{ item.title }}</span>
+ <span class="result-description">{{ item.description }}</span>
+ </div>
+ <Icon name="new_tab" class="navigate-icon" fill="var(--font-color)" />
+ </NuxtLink>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Item } from './types';
+const props = defineProps<{
+ items: Item[];
+ selectedIndex: number;
+ emptyText: string;
+ emptyIcon: string;
+}>();
+
+defineEmits<{
+ updateSelectedIndex: [index: number];
+}>();
+
+const groupedItems = computed(() => {
+ return props.items.reduce((acc, item) => {
+ (acc[item.section || ''] ||= []).push(item);
+ return acc;
+ }, {} as Record<string, typeof props.items>);
+});
+</script>
+
+<style scoped lang="scss">
+.search-results {
+ position: relative;
+ min-height: 0;
+ flex: 1;
+ -webkit-overflow-scrolling: touch;
+ overflow-y: auto;
+ overscroll-behavior: contain;
+}
+
+.search-results-list {
+ max-height: 100%;
+ padding: 8px 0;
+ overflow-y: auto;
+}
+
+.search-result-item {
+ display: flex;
+ margin: 0 5px;
+ padding: 8px 20px;
+ border-radius: 8px;
+ color: inherit;
+ align-items: center;
+ cursor: pointer;
+ gap: 10px;
+ text-decoration: none;
+
+ &:hover,
+ &.selected {
+ background: var(--border-color);
+ }
+}
+
+.result-icon {
+ width: 20px;
+ height: 20px;
+ color: var(--primary);
+ flex-shrink: 0;
+}
+
+.result-content {
+ display: flex;
+ min-width: 0;
+ flex: 1;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.result-title {
+ font-weight: 600;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.result-description {
+ font-size: 13px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.navigate-icon {
+ width: 16px;
+ height: 16px;
+ flex-shrink: 0;
+}
+
+.section {
+ padding: 8px 0 4px;
+}
+
+.section-title {
+ position: sticky;
+ top: 0;
+ z-index: 1;
+ padding: 6px 20px;
+ font-size: 12px;
+ background: var(--bg-color);
+ text-transform: uppercase;
+}
+
+.no-results {
+ display: flex;
+ padding: 40px 20px;
+ text-align: center;
+ align-items: center;
+ gap: 5px;
+ justify-content: center;
+
+ .no-results-icon {
+ opacity: 0.5;
+ }
+
+ p {
+ margin: 0;
+ font-size: 14px;
+ }
+}
+</style>
diff --git a/frontend/app/components/CommandCenter/TabNavigation.vue b/frontend/app/components/CommandCenter/TabNavigation.vue
index c6e556f6..0b0e85f3 100644
--- a/frontend/app/components/CommandCenter/TabNavigation.vue
+++ b/frontend/app/components/CommandCenter/TabNavigation.vue
@@ -1,6 +1,6 @@
<template>
<div class="tab-navigation">
- <button v-for="tab in tabs" :key="tab.id" class="tab-button" :class="{ active: activeTab === tab.id }" @click="$emit('changeTab', tab.id)">
+ <button v-for="tab in tabs" :key="tab.id" class="tab-button" :class="{ active: activeTab === tab.id }" @click="handleClick(tab.id)">
<Icon :name="tab.icon" class="tab-icon" fill="var(--font-color)" />
<span class="tab-label">{{ tab.label }}</span>
</button>
@@ -8,8 +8,6 @@
</template>
<script setup lang="ts">
-import Icon from '~/components/Icon.vue';
-
interface Tab {
id: string;
label: string;
@@ -20,10 +18,14 @@ defineProps<{
activeTab: string;
}>();
-defineEmits<{
- changeTab: [tabId: string];
+const emit = defineEmits<{
+ 'change-tab': [tabId: string];
}>();
+const handleClick = (tabId: string) => {
+ emit('change-tab', tabId);
+};
+
const tabs: Tab[] = [
{
id: 'quick',
diff --git a/frontend/app/components/CommandCenter/index.vue b/frontend/app/components/CommandCenter/index.vue
index ace0540a..6d4a4c80 100644
--- a/frontend/app/components/CommandCenter/index.vue
+++ b/frontend/app/components/CommandCenter/index.vue
@@ -30,12 +30,18 @@
ref="quickSearchTab"
:search-query="searchQuery"
:selected-index="selectedIndex"
- :documents="documentsStore.getAll"
- @select-item="closeSearch"
+ @select-item="handleQuickSelect"
@update-selected-index="updateSelectedIndex"
/>
- <AdvancedSearchTab v-else-if="activeTab === 'advanced'" :documents="documentsStore.getAll" @select-document="handleDocumentSelect" />
+ <AdvancedSearchTab
+ v-else-if="activeTab === 'advanced'"
+ ref="advancedSearchTab"
+ :query="searchQuery"
+ :selected-index="selectedIndex"
+ @select-document="handleDocumentSelect"
+ @update-selected-index="updateSelectedIndex"
+ />
</div>
<!-- Footer -->
@@ -57,12 +63,12 @@ import type { Document } from '~/stores';
const router = useRouter();
const isOpen = ref(false);
-const documentsStore = useDocumentsStore();
const searchQuery = ref('');
const selectedIndex = ref(0);
const activeTab = ref('quick');
const searchInput = ref<HTMLInputElement>();
const quickSearchTab = ref();
+const advancedSearchTab = ref();
// *********** Lifecycle ***********
onMounted(() => {
@@ -121,7 +127,14 @@ function openSearch() {
}
function closeSearch(e?: MouseEvent) {
- if (e && e.target && (e.target as Element).closest('.command-center-modal') && !(e.target as Element).classList.contains('close-btn')) return;
+ if (
+ e &&
+ e.target &&
+ (e.target as Element).closest('.command-center-modal') &&
+ !(e.target as Element).classList.contains('close-btn') &&
+ !(e.target as Element).closest('.search-results-list')
+ )
+ return;
isOpen.value = false;
searchQuery.value = '';
selectedIndex.value = 0;
@@ -140,30 +153,42 @@ function updateSelectedIndex(index: number) {
selectedIndex.value = index;
}
+function handleQuickSelect() {
+ const selectedItem = quickSearchTab.value.flattenedItems[selectedIndex.value];
+ if (selectedItem) {
+ navigateTo(selectedItem.path);
+ closeSearch();
+ }
+}
+
function handleDocumentSelect(document: Document) {
navigateTo(`/dashboard/docs/${document.id}`);
closeSearch();
}
function handleSearchKeydown(e: KeyboardEvent) {
- if (activeTab.value === 'advanced') {
- return;
+ let items = [];
+ if (activeTab.value === 'quick') {
+ items = quickSearchTab.value?.flattenedItems || [];
+ } else if (activeTab.value === 'advanced') {
+ items = advancedSearchTab.value?.flattenedItems || [];
}
-
- if ((e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) && selectedIndex.value < (quickSearchTab.value?.flattenedItems?.length || 0) - 1) {
+ const maxIndex = items.length - 1;
+ if ((e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) && selectedIndex.value < maxIndex) {
e.preventDefault();
- const maxIndex = (quickSearchTab.value?.flattenedItems?.length || 0) - 1;
selectedIndex.value = (selectedIndex.value + 1) % Math.max(maxIndex + 1, 1);
} else if (e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey && selectedIndex.value > 0)) {
e.preventDefault();
- const maxIndex = (quickSearchTab.value?.flattenedItems?.length || 0) - 1;
selectedIndex.value = (selectedIndex.value - 1 + Math.max(maxIndex + 1, 1)) % Math.max(maxIndex + 1, 1);
- } else if (e.key === 'Enter' && quickSearchTab.value?.flattenedItems?.length > 0) {
+ } else if (e.key === 'Enter' && items.length > 0) {
e.preventDefault();
- const selectedItem = quickSearchTab.value.flattenedItems[selectedIndex.value];
- if (selectedItem) {
- navigateTo(selectedItem.path);
- closeSearch();
+ if (activeTab.value === 'quick') {
+ handleQuickSelect();
+ } else if (activeTab.value === 'advanced') {
+ const selectedItem = items[selectedIndex.value];
+ if (selectedItem) {
+ handleDocumentSelect(selectedItem);
+ }
}
}
}
diff --git a/frontend/app/components/CommandCenter/types.ts b/frontend/app/components/CommandCenter/types.ts
new file mode 100644
index 00000000..e5249c6d
--- /dev/null
+++ b/frontend/app/components/CommandCenter/types.ts
@@ -0,0 +1,9 @@
+export interface Item {
+ id: string;
+ icon: string;
+ title: string;
+ description: string;
+ path: string;
+ section: string;
+ globalIndex: number;
+}
diff --git a/frontend/app/stores/documents.store.ts b/frontend/app/stores/documents.store.ts
index cfc269e9..b7de4f2e 100644
--- a/frontend/app/stores/documents.store.ts
+++ b/frontend/app/stores/documents.store.ts
@@ -1,12 +1,23 @@
import { makeRequest, type FetchOptions } from './_utils';
import type { DB_Document, Document } from './db_strustures';
+interface SearchOptions {
+ query?: string;
+ fromDate?: Date;
+ toDate?: Date;
+ dateType?: 'created' | 'modified';
+ tags?: string[];
+ category?: string;
+}
+
export const useDocumentsStore = defineStore('documents', {
state: () => ({
documents: [] as Document[],
+ allTags: [] as string[],
}),
getters: {
getAll: state => state.documents,
+ getAllTags: state => state.allTags,
getById: state => (id: string) => state.documents.find((d: Document) => d.id == id),
getByCategories: state => (category: string) => state.documents.filter(d => d.category == category),
@@ -37,8 +48,55 @@ export const useDocumentsStore = defineStore('documents', {
if (parent) getChildrens(parent);
return childrens;
},
+ search: state => (options: SearchOptions) => {
+ const { query, fromDate, toDate, dateType, tags, category } = options;
+ let filtered = [...state.documents];
+ if (query) {
+ filtered = filtered.filter(doc => {
+ const docContent = `${doc.name} ${doc.description}`.toLowerCase();
+ return docContent.includes(query.toLowerCase());
+ });
+ }
+
+ if (fromDate) {
+ filtered = filtered.filter(doc => {
+ const docDate = new Date(doc[dateType === 'created' ? 'created_timestamp' : 'updated_timestamp']);
+ return docDate >= fromDate;
+ });
+ }
+
+ if (toDate) {
+ filtered = filtered.filter(doc => {
+ const docDate = new Date(doc[dateType === 'created' ? 'created_timestamp' : 'updated_timestamp']);
+ return docDate <= toDate;
+ });
+ }
+
+ if (tags && tags.length > 0) {
+ filtered = filtered.filter(doc => {
+ if (!doc.tags) return false;
+ const docTags = parseTags(doc.tags);
+ return tags.some(tag => docTags.includes(tag));
+ });
+ }
+
+ if (category) {
+ filtered = filtered.filter(doc => doc.category === category);
+ }
+
+ return filtered;
+ },
},
actions: {
+ recomputeTags() {
+ const tags = new Set<string>();
+ this.documents.forEach(doc => {
+ if (doc.tags) {
+ parseTags(doc.tags).forEach(tag => tags.add(tag));
+ }
+ });
+ this.allTags = Array.from(tags).sort();
+ },
async fetch<T extends FetchOptions>(opts?: T): Promise<'id' extends keyof T ? Document : Document[]> {
console.log(`[store/documents] Fetching documents with options: ${JSON.stringify(opts)}`);
const request = await makeRequest(`documents/@me/${opts?.id || ''}`, 'GET', {});
@@ -51,6 +109,7 @@ export const useDocumentsStore = defineStore('documents', {
return updatedDocument as 'id' extends keyof T ? Document : Document[];
} else {
this.documents = (request.result as DB_Document[]).map((d: DB_Document) => ({ ...d, partial: true, type: 'document' }));
+ this.recomputeTags();
return this.documents as 'id' extends keyof T ? Document : Document[];
}
} else throw request;
@@ -80,3 +139,13 @@ export const useDocumentsStore = defineStore('documents', {
},
},
});
+
+function parseTags(tags: string): string[] {
+ if (typeof tags === 'string') {
+ return tags
+ .split(',')
+ .map(tag => tag.trim())
+ .filter(Boolean);
+ }
+ return [];
+}