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 06:03:03 +03:00 committed by GitHub
parent 96f0fef450
commit 8f0f69f144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 19 deletions

View File

@ -90,7 +90,7 @@ export default mergeIds(chunterId, chunter, {
Random: '' as Ref<Channel>
},
function: {
ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => boolean>
ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => Promise<boolean>>
},
filter: {
CommentsFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>,

View File

@ -32,6 +32,6 @@ export default mergeIds(workbenchId, workbench, {
HiddenApplication: '' as IntlString
},
function: {
HasArchiveSpaces: '' as Resource<(spaces: Space[]) => boolean>
HasArchiveSpaces: '' as Resource<(spaces: Space[]) => Promise<boolean>>
}
})

View File

@ -187,7 +187,7 @@ export async function DeleteMessageFromSaved (message: ChunterMessage): Promise<
export const userSearch = writable('')
export function chunterBrowserVisible (spaces: Space[]): boolean {
export async function chunterBrowserVisible (spaces: Space[]): Promise<boolean> {
return false
}

View File

@ -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>

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'

View File

@ -79,7 +79,7 @@ export interface SpecialNavModel {
componentProps?: Record<string, string>
// If not top and bottom, position will be sorted alphabetically.
position?: 'top' | 'bottom' | string // undefined == 'top
visibleIf?: Resource<(spaces: Space[]) => boolean>
visibleIf?: Resource<(spaces: Space[]) => Promise<boolean>>
// If defined, will be used to find spaces for visibleIf
spaceClass?: Ref<Class<Space>>
}