Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 86 additions & 6 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useConnectionsStore } from "./stores/connections";
import { useShellNavStore } from "./stores/shellNav";
import { initTheme } from "./theme/queryaTheme";
import { provideQueryaMotion } from "./motion";
import { buildCoreCommands, type AppCommand } from "./commands/registry";
import TitleBar from "./ui/TitleBar.vue";
import ConnectionsPanel from "./ui/ConnectionsPanel.vue";
import StatusBar from "./ui/StatusBar.vue";
Expand All @@ -17,13 +18,23 @@ import QueryaDivider from "./ui/QueryaDivider.vue";
import ConnectionHome from "./ui/ConnectionHome.vue";
import TableObjectView from "./ui/TableObjectView.vue";
import PreferencesDialog from "./ui/PreferencesDialog.vue";
import CommandPalette from "./ui/CommandPalette.vue";
import QuickSwitcher from "./ui/QuickSwitcher.vue";
import WelcomeTourDialog from "./ui/WelcomeTourDialog.vue";
import AboutDialog from "./ui/AboutDialog.vue";

const shell = useShellStore();
const status = useShellStatusStore();
const connections = useConnectionsStore();
const nav = useShellNavStore();
const { surface } = storeToRefs(nav);

const prefsOpen = ref(false);
const paletteOpen = ref(false);
const switcherOpen = ref(false);
const tourOpen = ref(false);
const aboutOpen = ref(false);

provideQueryaMotion();

const showEmpty = computed(() => surface.value === "empty");
Expand Down Expand Up @@ -67,27 +78,76 @@ function onLaunchDemo() {
}

function onOpenTour() {
status.setQueryMetrics({ message: "Tour stub", busy: false });
tourOpen.value = true;
}

function onOpenPreferences() {
prefsOpen.value = true;
}

function onOpenPalette() {
paletteOpen.value = true;
}

function onOpenQuickSwitcher() {
switcherOpen.value = true;
}

function onOpenAbout() {
aboutOpen.value = true;
}

function onCheckUpdates() {
status.setQueryMetrics({
message: "Updater stub — check for updates lands with packaging epic",
busy: false,
});
}

function onGoHome() {
if (nav.selectedConnectionId) nav.clearObject();
else nav.reset();
}

function onOpenRecent(id: string) {
connections.select(id);
}

const commands = computed<AppCommand[]>(() =>
buildCoreCommands({
openPreferences: onOpenPreferences,
toggleSidebar: () => shell.toggleSidebar(),
openTour: onOpenTour,
openAbout: onOpenAbout,
openPalette: onOpenPalette,
openQuickSwitcher: onOpenQuickSwitcher,
launchDemo: onLaunchDemo,
openSqlite: () => void onOpenSqlite(),
newConnection: onNewConnection,
checkUpdates: onCheckUpdates,
goHome: onGoHome,
}),
);

function onKeydown(e: KeyboardEvent) {
const mod = e.metaKey || e.ctrlKey;
if (!mod) return;
if (e.key.toLowerCase() === "b") {
const key = e.key.toLowerCase();
if (key === "b") {
e.preventDefault();
shell.toggleSidebar();
}
if (e.key === ",") {
} else if (e.key === ",") {
e.preventDefault();
onOpenPreferences();
}
if (e.key.toLowerCase() === "n") {
} else if (key === "n") {
e.preventDefault();
onNewConnection();
} else if (key === "p") {
e.preventDefault();
onOpenPalette();
} else if (key === "k") {
e.preventDefault();
onOpenQuickSwitcher();
}
}

Expand Down Expand Up @@ -121,6 +181,11 @@ onUnmounted(() => {
<TitleBar
@open-sqlite="onOpenSqlite"
@open-preferences="onOpenPreferences"
@open-palette="onOpenPalette"
@open-quick-switcher="onOpenQuickSwitcher"
@open-tour="onOpenTour"
@open-about="onOpenAbout"
@check-updates="onCheckUpdates"
/>
<QueryaDivider />
<div class="body">
Expand All @@ -136,14 +201,29 @@ onUnmounted(() => {
@open-sqlite="onOpenSqlite"
@launch-demo="onLaunchDemo"
@open-tour="onOpenTour"
@open-recent="onOpenRecent"
/>
<ConnectionHome v-else-if="showHome" />
<TableObjectView v-else-if="showTable" />
</div>
</main>
</div>
<StatusBar @open-preferences="onOpenPreferences" />

<PreferencesDialog :open="prefsOpen" @close="prefsOpen = false" />
<CommandPalette
:open="paletteOpen"
:commands="commands"
@close="paletteOpen = false"
/>
<QuickSwitcher :open="switcherOpen" @close="switcherOpen = false" />
<WelcomeTourDialog
:open="tourOpen"
@close="tourOpen = false"
@launch-demo="onLaunchDemo"
@open-preferences="onOpenPreferences"
/>
<AboutDialog :open="aboutOpen" @close="aboutOpen = false" />
</div>
</template>

Expand Down
43 changes: 43 additions & 0 deletions apps/tauri/src/commands/registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, it, vi } from "vitest";
import { buildCoreCommands, filterCommands } from "./registry";

const noop = () => undefined;

describe("command registry", () => {
const commands = buildCoreCommands({
openPreferences: noop,
toggleSidebar: noop,
openTour: noop,
openAbout: noop,
openPalette: noop,
openQuickSwitcher: noop,
launchDemo: noop,
openSqlite: noop,
newConnection: noop,
checkUpdates: noop,
goHome: noop,
});

it("includes core built-ins", () => {
const ids = commands.map((c) => c.id);
expect(ids).toContain("prefs");
expect(ids).toContain("palette");
expect(ids).toContain("goto");
expect(ids).toContain("tour");
});

it("filters by title and keywords", () => {
expect(filterCommands(commands, "prefer").map((c) => c.id)).toContain(
"prefs",
);
expect(filterCommands(commands, "table").map((c) => c.id)).toContain(
"goto",
);
const run = vi.fn();
const patched = commands.map((c) =>
c.id === "demo" ? { ...c, run } : c,
);
filterCommands(patched, "demo")[0]?.run();
expect(run).toHaveBeenCalledOnce();
});
});
111 changes: 111 additions & 0 deletions apps/tauri/src/commands/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
export type AppCommand = {
id: string;
title: string;
subtitle?: string;
keywords?: string[];
run: () => void;
};

export type CommandHandlers = {
openPreferences: () => void;
toggleSidebar: () => void;
openTour: () => void;
openAbout: () => void;
openPalette: () => void;
openQuickSwitcher: () => void;
launchDemo: () => void;
openSqlite: () => void;
newConnection: () => void;
checkUpdates: () => void;
goHome: () => void;
};

export function buildCoreCommands(h: CommandHandlers): AppCommand[] {
return [
{
id: "prefs",
title: "Open Preferences",
subtitle: "Ctrl/Cmd+,",
keywords: ["settings", "preferences"],
run: h.openPreferences,
},
{
id: "palette",
title: "Command Palette",
subtitle: "Ctrl/Cmd+P",
keywords: ["commands"],
run: h.openPalette,
},
{
id: "goto",
title: "Go to Object…",
subtitle: "Ctrl/Cmd+K",
keywords: ["quick", "switcher", "table"],
run: h.openQuickSwitcher,
},
{
id: "sidebar",
title: "Toggle Sidebar",
subtitle: "Ctrl/Cmd+B",
keywords: ["panel", "servers"],
run: h.toggleSidebar,
},
{
id: "home",
title: "Go Home",
keywords: ["overview", "connection"],
run: h.goHome,
},
{
id: "demo",
title: "Launch Demo Playground",
keywords: ["demo", "sample"],
run: h.launchDemo,
},
{
id: "sqlite",
title: "Open SQLite File…",
keywords: ["file", "database"],
run: h.openSqlite,
},
{
id: "new-conn",
title: "New Connection",
subtitle: "Ctrl/Cmd+N",
keywords: ["connect"],
run: h.newConnection,
},
{
id: "tour",
title: "Welcome Tour",
keywords: ["onboarding", "help"],
run: h.openTour,
},
{
id: "about",
title: "About Querya",
keywords: ["version"],
run: h.openAbout,
},
{
id: "updates",
title: "Check for Updates…",
keywords: ["updater"],
run: h.checkUpdates,
},
];
}

export function filterCommands(
commands: AppCommand[],
query: string,
): AppCommand[] {
const q = query.trim().toLowerCase();
if (!q) return commands;
return commands.filter((c) => {
const hay = [c.title, c.subtitle ?? "", ...(c.keywords ?? [])]
.join(" ")
.toLowerCase();
return hay.includes(q);
});
}
Loading
Loading