UNPKG

@owdproject/core

Version:

<p align="center"> <img width="160" height="160" src="https://avatars.githubusercontent.com/u/65117737?s=160&v=4" /> </p> <h1 align="center">Open Web Desktop</h1> <h3 align="center"> A modular framework for building web-based desktop experiences. </h3

52 lines (44 loc) 1.41 kB
import { useApplicationManager } from './useApplicationManager' import { computed } from '@vue/reactivity' type SortBy = | 'title' | 'category' | (( a: ApplicationEntryWithInherited, b: ApplicationEntryWithInherited, ) => number) type Visibility = | 'primary' | 'all' | ((entry: ApplicationEntryWithInherited) => boolean) export function useApplicationEntries() { const applicationManager = useApplicationManager() const sortedAppEntries = function ( sortBy: SortBy = 'title', visibility: Visibility = 'primary', ): Ref<ApplicationEntryWithInherited[]> { return computed(() => { const currentEntries = [...applicationManager.appsEntries.value] // filtering const filtered = typeof visibility === 'function' ? currentEntries.filter(visibility) : visibility === 'primary' ? currentEntries.filter((e) => e.visibility !== 'secondary') : currentEntries // sorting const sorted = typeof sortBy === 'function' ? filtered.sort(sortBy) : sortBy === 'title' ? filtered.sort((a, b) => (a.title || '').localeCompare(b.title || ''), ) : filtered.sort((a, b) => (a.category || '').localeCompare(b.category || ''), ) return sorted }) } return { sortedAppEntries } }