Browse Source

refactor(nc-gui): use shared composable instead of injection state for roles

pull/3703/head
braks 2 years ago
parent
commit
8bfe3cbb95
  1. 16
      packages/nc-gui/composables/useRoles/index.ts

16
packages/nc-gui/composables/useRoles/index.ts

@ -1,8 +1,8 @@
import { isString } from '@vueuse/core' import { isString } from '@vueuse/core'
import { computed, ref, useApi, useGlobal, useInjectionState } from '#imports' import { computed, createSharedComposable, ref, useApi, useGlobal } from '#imports'
import type { ProjectRole, Role, Roles } from '~/lib' import type { ProjectRole, Role, Roles } from '~/lib'
const [setup, use] = useInjectionState(() => { export const useRoles = createSharedComposable(() => {
const { user } = useGlobal() const { user } = useGlobal()
const { api } = useApi() const { api } = useApi()
@ -49,14 +49,4 @@ const [setup, use] = useInjectionState(() => {
})) }))
return { allRoles, userRoles, projectRoles, loadProjectRoles } return { allRoles, userRoles, projectRoles, loadProjectRoles }
}, 'useRoles') })
export function useRoles() {
const roles = use()
if (!roles) {
return setup()
}
return roles
}

Loading…
Cancel
Save