diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index a0715129..dbb1ebde 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -750,6 +750,7 @@ export class MockTransport implements Transport { return json(200, [ { repo: `${root}\\shop`, id: 'shop-3f9a1c', name: 'shop', error: null, registered: true, added: false }, { repo: `${root}\\billing`, id: 'b111', name: 'billing', error: null, registered: add, added: add }, + { repo: `${root}\\worker`, id: 'w333', name: 'worker', error: null, registered: add, added: add }, { repo: `${root}\\legacy`, id: 'l222', name: null, error: 'devstack.toml: unknown field `biuld`', registered: false, added: false }, ]); } diff --git a/ui/src/components/AddStackDialog.vue b/ui/src/components/AddStackDialog.vue index 10d21538..b50ecd44 100644 --- a/ui/src/components/AddStackDialog.vue +++ b/ui/src/components/AddStackDialog.vue @@ -9,8 +9,8 @@ import { computed, ref, watch } from 'vue'; import { useRouter } from 'vue-router'; import { api, paths } from '@/api'; import { act } from '@/lib/actions'; -import { useUi } from '@/stores/ui'; import AgentPrompt from './AgentPrompt.vue'; +import FolderField from './FolderField.vue'; import Modal from './Modal.vue'; import Icon from './icons/Icon.vue'; import ScanStacks from './ScanStacks.vue'; @@ -18,7 +18,6 @@ import { stackPage } from '@/lib/stackRoutes'; const props = defineProps<{ open: boolean }>(); const emit = defineEmits<{ close: [] }>(); -const ui = useUi(); const router = useRouter(); type Inspect = { repo: string; is_dir: boolean; has_stack_file: boolean; valid: { Ok?: null; Err?: string } | null; registered: string | null; id: string }; @@ -41,35 +40,23 @@ watch( }, ); -// The hub shows the operating system's folder dialog (a page cannot learn a -// folder's path). Where it cannot (no desktop), the text field stays. -const canPick = ref(true); -const picking = ref(false); -async function pick() { - picking.value = true; - problem.value = null; - try { - const res = await api().request<{ path: string | null } | { error: string }>('POST', paths.pickFolder); - const b = typeof res.body === 'object' ? res.body : null; - if (res.status === 501) { - canPick.value = false; - ui.toast('info', 'No folder dialog on this machine', 'Paste the folder path instead.'); - } else if (res.ok && b && 'path' in b) { - if (b.path) { - path.value = b.path; - await check(); - } - } else { - problem.value = b && 'error' in b ? b.error : `HTTP ${res.status}`; - } - } catch { - problem.value = 'The hub does not answer.'; - } finally { - picking.value = false; - } -} +// A typed or pasted path is checked once typing pauses; a picked one, Enter +// or a click at once. An answer for a path the field no longer holds is +// dropped. +let timer: ReturnType | undefined; +watch( + path, + () => { + clearTimeout(timer); + info.value = null; + problem.value = null; + if (path.value.trim()) timer = setTimeout(check, 450); + }, + { flush: 'sync' }, +); async function check() { + clearTimeout(timer); const p = path.value.trim(); if (!p) return; checking.value = true; @@ -77,6 +64,7 @@ async function check() { info.value = null; try { const res = await api().request('GET', paths.inspect(p)); + if (p !== path.value.trim()) return; const b = typeof res.body === 'object' ? res.body : null; if (res.ok && b && 'repo' in b) info.value = b; else problem.value = b && 'error' in b ? b.error : `HTTP ${res.status}`; @@ -112,11 +100,11 @@ async function add() { diff --git a/ui/src/components/ScanStacks.vue b/ui/src/components/ScanStacks.vue index 98df5c20..89236f99 100644 --- a/ui/src/components/ScanStacks.vue +++ b/ui/src/components/ScanStacks.vue @@ -1,11 +1,12 @@