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: modal close & navigation & code

Smaug6739ead7fe986faa
diff --git a/frontend/app/components/CommandCenter/SearchResultsList.vue b/frontend/app/components/CommandCenter/SearchResultsList.vue
index 5f9780e3..484a7fea 100644
--- a/frontend/app/components/CommandCenter/SearchResultsList.vue
+++ b/frontend/app/components/CommandCenter/SearchResultsList.vue
@@ -13,6 +13,7 @@
class="search-result-item"
:to="item.path"
:class="{ selected: selectedIndex === item.globalIndex }"
+ @click="close"
@mouseenter="$emit('updateSelectedIndex', item.globalIndex)"
>
<Icon :name="item.icon" class="result-icon" />
@@ -37,6 +38,8 @@ import type { ItemCommand } from './types';
const props = defineProps<{ items: ItemCommand[]; selectedIndex: number; query: string }>();
defineEmits<{ updateSelectedIndex: [index: number] }>();
+const { close } = useCommandCenter();
+
const groupedItems = computed(() => {
return props.items.reduce(
(acc, item) => {
diff --git a/frontend/app/components/CommandCenter/TabNavigation.vue b/frontend/app/components/CommandCenter/TabNavigation.vue
index 6bae9e03..400778c3 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="handleClick(tab.id)">
+ <button v-for="tab in tabs" :key="tab.id" class="tab-button" :class="{ active: activeTab === tab.id }" @click="changeTab(tab.id as 'quick' | 'advanced')">
<Icon :name="tab.icon" class="tab-icon" />
<span class="tab-label">{{ tab.label }}</span>
</button>
@@ -8,57 +8,34 @@
</template>
<script setup lang="ts">
-const emit = defineEmits<{ 'change-tab': [tabId: string] }>();
-
-const handleClick = (tabId: string) => emit('change-tab', tabId);
const { changeTab, activeTab } = useCommandCenter();
-interface Tab {
- id: string;
- label: string;
- icon: string;
-}
-
-const tabs: Tab[] = [
- {
- id: 'quick',
- label: 'Quick Search',
- icon: 'search',
- },
- {
- id: 'advanced',
- label: 'Advanced Search',
- icon: 'layers',
- },
-];
+const tabs = [
+ { id: 'quick', label: 'Quick Search', icon: 'search' },
+ { id: 'advanced', label: 'Advanced Search', icon: 'layers' },
+] as const;
-const handleKeydown = (e: KeyboardEvent) => {
+function handleKeydown(e: KeyboardEvent) {
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
e.stopImmediatePropagation();
e.preventDefault();
changeTab(activeTab.value === 'quick' ? 'advanced' : 'quick');
}
-};
+}
-// Add global keydown listener for tab switching (priority capture to override other handlers)
-onMounted(() => {
- window.addEventListener('keydown', handleKeydown, { capture: true });
-});
-onUnmounted(() => {
- window.removeEventListener('keydown', handleKeydown, { capture: true });
-});
+onMounted(() => window.addEventListener('keydown', handleKeydown, { capture: true }));
+onUnmounted(() => window.removeEventListener('keydown', handleKeydown, { capture: true }));
</script>
<style scoped lang="scss">
.tab-navigation {
display: flex;
- background: var(--surface-base);
border-bottom: 1px solid var(--border);
}
.tab-button {
display: flex;
- padding: 16px 20px;
+ padding: 14px 20px;
border: none;
border-radius: 0;
font-size: 14px;
@@ -81,8 +58,4 @@ onUnmounted(() => {
width: 16px;
height: 16px;
}
-
-.tab-label {
- white-space: nowrap;
-}
</style>
diff --git a/frontend/app/components/CommandCenter/index.vue b/frontend/app/components/CommandCenter/index.vue
index 82ca09b2..2db537e9 100644
--- a/frontend/app/components/CommandCenter/index.vue
+++ b/frontend/app/components/CommandCenter/index.vue
@@ -1,6 +1,5 @@
<template>
- <div class="command-center-modal" @click="handleOverlayClick">
- <!-- Header -->
+ <div class="command-center">
<div class="search-header">
<div class="search-input-wrapper">
<Icon name="search" class="search-icon" />
@@ -11,38 +10,26 @@
placeholder="Search for a page, action, or document..."
class="search-input"
@input="handleSearchInput"
- @keydown="handleSearchKeydown"
+ @keydown="handleKeydown"
/><tag yellow class="tag">Beta</tag>
</div>
</div>
- <!-- Tab Navigation -->
- <TabNavigation @change-tab="handleTabChange" />
+ <TabNavigation />
- <!-- Tab Content -->
<div class="tab-content">
<QuickSearchTab
v-if="activeTab === 'quick'"
ref="quickSearchTab"
:search-query="searchQuery"
:selected-index="selectedIndex"
- @select-item="handleQuickSelect"
- @update-selected-index="setSelectedIndex"
- />
-
- <AdvancedSearchTab
- v-else-if="activeTab === 'advanced'"
- ref="advancedSearchTab"
- :query="searchQuery"
- :selected-index="selectedIndex"
- @select-document="handleDocumentSelect"
@update-selected-index="setSelectedIndex"
/>
+ <AdvancedSearchTab v-else ref="advancedSearchTab" :query="searchQuery" :selected-index="selectedIndex" @update-selected-index="setSelectedIndex" />
</div>
- <!-- Footer -->
<div class="search-footer">
- <div class="shortcuts"><kbd>↑↓</kbd> or <kbd>Tab</kbd>Navigate <kbd>Enter</kbd> Select <kbd>⇄</kbd> Switch tabs <kbd>Escape</kbd> Close</div>
+ <div class="shortcuts"><kbd>↑↓</kbd> Navigate <kbd>Enter</kbd> Select <kbd>⇄</kbd> Switch tabs <kbd>Esc</kbd> Close</div>
</div>
</div>
</template>
@@ -51,86 +38,46 @@
import TabNavigation from './TabNavigation.vue';
import QuickSearchTab from './QuickSearchTab.vue';
import AdvancedSearchTab from './AdvancedSearchTab.vue';
-import type { Node } from '~/stores';
-const { searchQuery, selectedIndex, activeTab, close, changeTab, setSearchQuery, setSelectedIndex } = useCommandCenter();
+const { searchQuery, selectedIndex, activeTab, close, setSearchQuery, setSelectedIndex } = useCommandCenter();
const searchInput = ref<HTMLInputElement>();
-const quickSearchTab = ref();
-const advancedSearchTab = ref();
-
-// Focus input when opening
-onMounted(() => {
- nextTick(() => searchInput.value?.focus());
-});
-
-// --- Methods ---
-function handleSearchInput(e: Event) {
- setSearchQuery((e.target as HTMLInputElement).value);
-}
-
-function handleTabChange(tabId: string) {
- changeTab(tabId as 'quick' | 'advanced');
- if (tabId === 'quick') {
- nextTick(() => searchInput.value?.focus());
- }
-}
+const quickSearchTab = ref<InstanceType<typeof QuickSearchTab>>();
+const advancedSearchTab = ref<InstanceType<typeof AdvancedSearchTab>>();
-function handleOverlayClick(e: MouseEvent) {
- if (
- e.target &&
- (e.target as Element).closest('.command-center-modal') &&
- !(e.target as Element).closest('.close-btn') &&
- !(e.target as Element).closest('.search-results-list')
- )
- return;
+onMounted(() => nextTick(() => searchInput.value?.focus()));
- close();
+function getItems() {
+ return activeTab.value === 'quick' ? quickSearchTab.value?.flattenedItems || [] : advancedSearchTab.value?.flattenedItems || [];
}
-function handleQuickSelect() {
- const selectedItem = quickSearchTab.value?.flattenedItems?.[selectedIndex.value];
- if (selectedItem) {
- navigateTo(selectedItem.path);
- close();
- }
+function handleSearchInput(e: Event) {
+ setSearchQuery((e.target as HTMLInputElement).value);
}
-function handleDocumentSelect(document: Node) {
- navigateTo(`/dashboard/docs/${document.id}`);
- close();
-}
+function handleKeydown(e: KeyboardEvent) {
+ const items = getItems();
+ const max = items.length - 1;
-function handleSearchKeydown(e: KeyboardEvent) {
- let items = [];
- if (activeTab.value === 'quick') {
- items = quickSearchTab.value?.flattenedItems || [];
- } else if (activeTab.value === 'advanced') {
- items = advancedSearchTab.value?.flattenedItems || [];
- }
- const maxIndex = items.length - 1;
- if ((e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) && selectedIndex.value < maxIndex) {
+ if (e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) {
e.preventDefault();
- setSelectedIndex((selectedIndex.value + 1) % Math.max(maxIndex + 1, 1));
- } else if (e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey && selectedIndex.value > 0)) {
+ setSelectedIndex(selectedIndex.value < max ? selectedIndex.value + 1 : 0);
+ } else if (e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey)) {
e.preventDefault();
- setSelectedIndex((selectedIndex.value - 1 + Math.max(maxIndex + 1, 1)) % Math.max(maxIndex + 1, 1));
- } else if (e.key === 'Enter' && items.length > 0) {
+ setSelectedIndex(selectedIndex.value > 0 ? selectedIndex.value - 1 : max);
+ } else if (e.key === 'Enter' && items.length) {
e.preventDefault();
- if (activeTab.value === 'quick') {
- handleQuickSelect();
- } else if (activeTab.value === 'advanced') {
- const selectedItem = items[selectedIndex.value];
- if (selectedItem) {
- handleDocumentSelect(selectedItem);
- }
+ const item = items[selectedIndex.value];
+ if (item?.path) {
+ close();
+ navigateTo(item.path);
}
}
}
</script>
<style scoped lang="scss">
-.command-center-modal {
+.command-center {
display: flex;
border-radius: 16px;
flex-direction: column;
@@ -142,7 +89,6 @@ function handleSearchKeydown(e: KeyboardEvent) {
padding: 20px;
align-items: center;
border-bottom: 1px solid var(--border);
- flex-shrink: 0;
gap: 12px;
}
@@ -163,21 +109,19 @@ function handleSearchKeydown(e: KeyboardEvent) {
}
.search-input {
+ width: 100%;
padding: 12px 12px 12px 44px;
border: none;
font-size: 16px;
background: transparent;
- flex: 1;
outline: none;
}
.tag {
- height: fit-content;
- margin-right: 20px;
+ margin-right: 25px;
}
.tab-content {
- position: relative;
min-height: 0;
flex: 1;
overflow: auto;
@@ -186,7 +130,6 @@ function handleSearchKeydown(e: KeyboardEvent) {
.search-footer {
padding: 16px 20px;
border-top: 1px solid var(--border);
- flex-shrink: 0;
}
.shortcuts {
@@ -197,16 +140,4 @@ function handleSearchKeydown(e: KeyboardEvent) {
flex-wrap: wrap;
gap: 10px;
}
-
-@media (width <= 768px) {
- .command-center-modal {
- width: 95%;
- max-height: 80vh;
- margin: 20px;
- }
-
- .shortcuts {
- gap: 8px;
- }
-}
</style>
diff --git a/frontend/app/components/Navbar.vue b/frontend/app/components/Navbar.vue
index 22f75d17..37d773e6 100644
--- a/frontend/app/components/Navbar.vue
+++ b/frontend/app/components/Navbar.vue
@@ -28,7 +28,7 @@
const { toggleSidebar, isOpened } = useSidebar();
const preferences = usePreferences();
-const openCommandCenter = () => window.dispatchEvent(new CustomEvent('command-center-open'));
+const openCommandCenter = () => useCommandCenter().open();
</script>
<style lang="scss" scoped>
diff --git a/frontend/app/composables/useCommandCenter.ts b/frontend/app/composables/useCommandCenter.ts
index 9d938d7f..41cde178 100644
--- a/frontend/app/composables/useCommandCenter.ts
+++ b/frontend/app/composables/useCommandCenter.ts
@@ -7,37 +7,49 @@ interface CommandCenterState {
searchQuery: string;
selectedIndex: number;
activeTab: TabType;
+ isOpen: boolean;
}
-// Singleton state shared across all component instances
const state = reactive<CommandCenterState>({
searchQuery: '',
selectedIndex: 0,
activeTab: 'quick',
+ isOpen: false,
});
let isInitialized = false;
+// Singleton modal instance
+let modal: Modal | null = null;
+
+function reset() {
+ state.searchQuery = '';
+ state.selectedIndex = 0;
+ state.activeTab = 'quick';
+ state.isOpen = false;
+}
+
+function getModal() {
+ if (!modal) {
+ modal = new Modal(shallowRef(CommandCenter), { noPadding: true, onClose: reset });
+ }
+ return modal;
+}
+
export function useCommandCenter() {
const router = useRouter();
const modalManager = useModal();
- const modal = new Modal(shallowRef(CommandCenter), { noPadding: true, onClose: afterClose });
- // --- Methods ---
function open() {
- state.selectedIndex = 0;
- state.searchQuery = '';
- state.activeTab = 'quick';
- modalManager.add(modal);
+ if (state.isOpen) return;
+ reset();
+ state.isOpen = true;
+ modalManager.add(getModal());
}
function close() {
- modalManager.close(modal);
- }
-
- function afterClose() {
- state.searchQuery = '';
- state.selectedIndex = 0;
+ if (!state.isOpen) return;
+ modalManager.close(getModal());
}
function changeTab(tabId: TabType) {
@@ -54,12 +66,12 @@ export function useCommandCenter() {
state.selectedIndex = index;
}
- // --- Global keyboard shortcuts handler ---
+ // --- Global keyboard shortcuts ---
function handleGlobalKeydown(e: KeyboardEvent) {
- if (e.key === '/') {
- const target = e.target as HTMLElement;
- const isTyping = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
- if (isTyping) return;
+ const target = e.target as HTMLElement;
+ const isTyping = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
+
+ if (e.key === '/' && !isTyping) {
e.preventDefault();
return open();
}
@@ -77,24 +89,22 @@ export function useCommandCenter() {
}
if ((e.ctrlKey || e.metaKey) && e.altKey && e.key.toLowerCase() === 'n') {
e.preventDefault();
- return useModal().add(new Modal(shallowRef(CreateCategoryModal), { props: { role: 1 } }));
+ return modalManager.add(new Modal(shallowRef(CreateCategoryModal), { props: { role: 1 } }));
}
}
- // --- Initialize global listeners (called once) ---
function initGlobalListeners() {
if (isInitialized) return;
isInitialized = true;
document.addEventListener('keydown', handleGlobalKeydown);
- window.addEventListener('command-center-open', open as EventListener);
}
- // --- Cleanup global listeners ---
function destroyGlobalListeners() {
+ if (!isInitialized) return;
isInitialized = false;
+
document.removeEventListener('keydown', handleGlobalKeydown);
- window.removeEventListener('command-center-open', open as EventListener);
}
return {