Make visibleIf async in SpecialNavModel (#2684)

Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
Denis Bunakalya
2023-02-27 10:03:03 +07:00
committed by GitHub
parent 96f0fef450
commit 8f0f69f144
6 changed files with 26 additions and 19 deletions
@@ -107,20 +107,27 @@
requestIndex: number
): Promise<[Map<string, SpecialNavModel[]>, number]> {
const result = new Map<string, SpecialNavModel[]>()
const promises = specials.map(async (sp) => {
const pos = sp.position ?? 'top'
let visible = true
if (sp.visibleIf !== undefined) {
const f = await getResource(sp.visibleIf)
visible = f(spaces)
}
if (visible) {
const list = result.get(pos) ?? []
list.push(sp)
result.set(pos, list)
}
})
await Promise.all(promises)
const spHandlers = await Promise.all(
specials.map(async (sp) => {
const pos = sp.position ?? 'top'
let visible = true
if (sp.visibleIf !== undefined) {
const f = await getResource(sp.visibleIf)
visible = await f(spaces)
}
return () => {
if (visible) {
const list = result.get(pos) ?? []
list.push(sp)
result.set(pos, list)
}
}
})
)
spHandlers.forEach((spHandler) => spHandler())
return [result, requestIndex]
}
</script>
+1 -1
View File
@@ -23,7 +23,7 @@ import SpecialView from './components/SpecialView.svelte'
import WorkbenchApp from './components/WorkbenchApp.svelte'
import { doNavigate } from './utils'
function hasArchiveSpaces (spaces: Space[]): boolean {
async function hasArchiveSpaces (spaces: Space[]): Promise<boolean> {
return spaces.find((sp) => sp.archived) !== undefined
}
export { default as SpaceBrowser } from './components/SpaceBrowser.svelte'