mirror of
https://github.com/directus/directus.git
synced 2026-02-17 01:31:48 -05:00
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
37 lines
734 B
TypeScript
37 lines
734 B
TypeScript
import { ref, Ref } from '@vue/composition-api';
|
|
|
|
import api from '@/api';
|
|
import { Role } from '@/types';
|
|
|
|
let roles: Ref<Role[] | null> | null = null;
|
|
let loading: Ref<boolean> | null = null;
|
|
|
|
export default function useNavigation(): Record<string, Ref> {
|
|
if (roles === null) {
|
|
roles = ref<Role[] | null>(null);
|
|
}
|
|
|
|
if (loading === null) {
|
|
loading = ref(false);
|
|
}
|
|
|
|
if (roles.value === null && loading?.value === false) {
|
|
fetchRoles();
|
|
}
|
|
|
|
return { roles, loading };
|
|
|
|
async function fetchRoles() {
|
|
if (!loading || !roles) return;
|
|
loading.value = true;
|
|
|
|
const rolesResponse = await api.get(`/roles`, {
|
|
params: {
|
|
sort: 'name',
|
|
},
|
|
});
|
|
roles.value = rolesResponse.data.data;
|
|
loading.value = false;
|
|
}
|
|
}
|