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
29 changes: 25 additions & 4 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useShellStatusStore } from "./stores/shellStatus";
import { useConnectionsStore } from "./stores/connections";
import { useShellNavStore } from "./stores/shellNav";
import { usePreferencesStore } from "./stores/preferences";
import { useFoldersStore } from "./stores/folders";
import { initTheme } from "./theme/queryaTheme";
import { provideQueryaMotion } from "./motion";
import { buildCoreCommands, type AppCommand } from "./commands/registry";
Expand All @@ -23,10 +24,12 @@ import CommandPalette from "./ui/CommandPalette.vue";
import QuickSwitcher from "./ui/QuickSwitcher.vue";
import WelcomeTourDialog from "./ui/WelcomeTourDialog.vue";
import AboutDialog from "./ui/AboutDialog.vue";
import NewFolderDialog from "./ui/NewFolderDialog.vue";

const shell = useShellStore();
const status = useShellStatusStore();
const connections = useConnectionsStore();
const folders = useFoldersStore();
const nav = useShellNavStore();
usePreferencesStore(); // hydrate prefs + --q-ui-scale on boot
const { surface } = storeToRefs(nav);
Expand All @@ -36,6 +39,7 @@ const paletteOpen = ref(false);
const switcherOpen = ref(false);
const tourOpen = ref(false);
const aboutOpen = ref(false);
const newFolderOpen = ref(false);

provideQueryaMotion();

Expand Down Expand Up @@ -69,10 +73,22 @@ function onNewConnection() {
}

function onNewFolder() {
status.setQueryMetrics({
message: "New folder — LocalDb folders land next",
busy: false,
});
newFolderOpen.value = true;
}

function onCreateFolder(name: string) {
try {
folders.create(name);
status.setQueryMetrics({
message: `Folder “${name}” created`,
busy: false,
});
} catch (err) {
status.setQueryMetrics({
message: err instanceof Error ? err.message : String(err),
busy: false,
});
}
}

function onLaunchDemo() {
Expand Down Expand Up @@ -226,6 +242,11 @@ onUnmounted(() => {
@open-preferences="onOpenPreferences"
/>
<AboutDialog :open="aboutOpen" @close="aboutOpen = false" />
<NewFolderDialog
:open="newFolderOpen"
@close="newFolderOpen = false"
@create="onCreateFolder"
/>
</div>
</template>

Expand Down
25 changes: 24 additions & 1 deletion apps/tauri/src/stores/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
formatConnectionError,
} from "../api/connection";
import { DEMO_CONNECTION } from "../mock/demoCatalog";
import { useFoldersStore } from "./folders";
import { useShellNavStore } from "./shellNav";
import { useShellStatusStore } from "./shellStatus";

Expand All @@ -16,6 +17,8 @@ export type LiveConnection = {
path: string;
/** Offline UI demo — no Rust session. */
mock?: boolean;
/** Optional SERVERS folder id. */
folderId?: string | null;
};

function fileName(path: string): string {
Expand All @@ -42,14 +45,18 @@ export const useConnectionsStore = defineStore("connections", () => {
function launchDemo() {
const nav = useShellNavStore();
const status = useShellStatusStore();
const folders = useFoldersStore();
const samples = folders.ensureDemoFolder();
const conn: LiveConnection = {
id: DEMO_CONNECTION.id,
driver: "sqlite",
name: DEMO_CONNECTION.name,
path: DEMO_CONNECTION.path,
mock: true,
folderId: samples.id,
};
upsert(conn);
folders.setExpanded(samples.id, true);
nav.setExpanded(conn.id, true);
nav.selectConnection(conn.id);
status.setConnection(conn.name, "Demo (offline)");
Expand All @@ -60,7 +67,7 @@ export const useConnectionsStore = defineStore("connections", () => {
return conn;
}

async function connectSqlite(path: string) {
async function connectSqlite(path: string, folderId?: string | null) {
const status = useShellStatusStore();
const nav = useShellNavStore();
status.setQueryMetrics({
Expand All @@ -74,6 +81,7 @@ export const useConnectionsStore = defineStore("connections", () => {
driver: "sqlite",
name: fileName(path),
path,
folderId: folderId ?? null,
};
upsert(conn);
nav.setExpanded(id, true);
Expand Down Expand Up @@ -127,12 +135,27 @@ export const useConnectionsStore = defineStore("connections", () => {
});
}

function moveToFolder(connectionId: string, folderId: string | null) {
const conn = items.value.find((c) => c.id === connectionId);
if (!conn) return;
conn.folderId = folderId;
}

/** Detach all connections from a folder (Flutter: folder delete keeps connections). */
function detachFolder(folderId: string) {
for (const c of items.value) {
if (c.folderId === folderId) c.folderId = null;
}
}

return {
items,
byId,
launchDemo,
connectSqlite,
disconnect,
select,
moveToFolder,
detachFolder,
};
});
110 changes: 110 additions & 0 deletions apps/tauri/src/stores/folders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { defineStore } from "pinia";
import { computed, reactive, watch } from "vue";

const STORAGE_KEY = "querya.folders.v1";

export type ConnectionFolder = {
id: string;
name: string;
/** Expanded in the SERVERS tree. */
expanded: boolean;
};

type Stored = { folders: { id: string; name: string }[] };

function load(): ConnectionFolder[] {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return [];
const parsed = JSON.parse(raw) as Stored;
return (parsed.folders ?? []).map((f) => ({
id: f.id,
name: f.name,
expanded: true,
}));
} catch {
return [];
}
}

function newId(): string {
return `folder-${crypto.randomUUID()}`;
}

/** In-memory folders for the SERVERS tree (LocalDb persistence later). */
export const useFoldersStore = defineStore("folders", () => {
const folders = reactive<ConnectionFolder[]>(load());

watch(
folders,
() => {
const payload: Stored = {
folders: folders.map(({ id, name }) => ({ id, name })),
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(payload));
},
{ deep: true },
);

const byId = computed(() => {
const map = new Map<string, ConnectionFolder>();
for (const f of folders) map.set(f.id, f);
return map;
});

function create(name: string): ConnectionFolder {
const trimmed = name.trim();
if (!trimmed) throw new Error("Folder name is empty");
if (folders.some((f) => f.name.toLowerCase() === trimmed.toLowerCase())) {
throw new Error(`Folder "${trimmed}" already exists`);
}
const folder: ConnectionFolder = {
id: newId(),
name: trimmed,
expanded: true,
};
folders.push(folder);
return folder;
}

function remove(id: string) {
const i = folders.findIndex((f) => f.id === id);
if (i >= 0) folders.splice(i, 1);
}

function rename(id: string, name: string) {
const f = folders.find((x) => x.id === id);
if (!f) return;
const trimmed = name.trim();
if (!trimmed) return;
f.name = trimmed;
}

function toggleExpanded(id: string) {
const f = folders.find((x) => x.id === id);
if (f) f.expanded = !f.expanded;
}

function setExpanded(id: string, expanded: boolean) {
const f = folders.find((x) => x.id === id);
if (f) f.expanded = expanded;
}

/** Seed a sample folder once for Demo UX if none exist. */
function ensureDemoFolder(): ConnectionFolder {
const existing = folders.find((f) => f.name === "Samples");
if (existing) return existing;
return create("Samples");
}

return {
folders,
byId,
create,
remove,
rename,
toggleExpanded,
setExpanded,
ensureDemoFolder,
};
});
Loading
Loading