diff --git a/frontend/src/lib/progress.js b/frontend/src/lib/progress.js index 311a44a..694de47 100644 --- a/frontend/src/lib/progress.js +++ b/frontend/src/lib/progress.js @@ -4,12 +4,23 @@ let taskCounter = 0; export function startProgress(taskDescription = 'Loading…') { const taskIndex = ++taskCounter; - StartProgressBar(taskIndex, taskDescription); + let started = false; + + const debouncer = setTimeout(() => { + StartProgressBar(taskIndex, taskDescription); + started = true; + }, 150); const task = { id: taskIndex, description: taskDescription, - end: () => StopProgressBar(taskIndex), + + end: () => { + clearTimeout(debouncer); + if (started) { + StopProgressBar(taskIndex); + } + }, }; return task; diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index 5c9dd1a..40446fd 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -35,6 +35,7 @@ let queryToSave; let showQueryChooser = false; let exportInfo; + let querying = false; $: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key); $: code = `db.${collection.key}.find(${form.query || '{}'}${form.fields && form.fields !== '{}' ? `, ${form.fields}` : ''}).sort(${form.sort})${form.skip ? `.skip(${form.skip})` : ''}${form.limit ? `.limit(${form.limit})` : ''};`; @@ -42,16 +43,24 @@ $: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0; async function submitQuery() { + if (querying) { + return; + } + + querying = true; const progress = startProgress('Performing query…'); activePath = []; const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form)); + if (newResult) { newResult.results = newResult.results?.map(s => EJSON.parse(s, { relaxed: false })); result = newResult; submittedForm = deepClone(form); } + progress.end(); resetFocus(); + querying = false; } async function refresh() { diff --git a/internal/ui/progress.go b/internal/ui/progress.go index fa607b0..5a8457f 100644 --- a/internal/ui/progress.go +++ b/internal/ui/progress.go @@ -6,6 +6,7 @@ import ( "github.com/ncruces/zenity" ) +// @todo: this takes ~0.5 seconds. Improve? func (u *UI) StartProgressBar(id uint, title string) { if title == "" { // default title @@ -20,13 +21,13 @@ func (u *UI) StartProgressBar(id uint, title string) { func (u *UI) StopProgressBar(id uint) { for try := 0; try < 10; try++ { - p := u.progressBars[id] - if p != nil { + if p := u.progressBars[id]; p != nil { p.Complete() p.Close() p = nil return } + println("Progress dialog not found:", id, try) time.Sleep(100 * time.Millisecond) }