mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
implementing domain selector
This commit is contained in:
36
dashboard/composables/useDomain.ts
Normal file
36
dashboard/composables/useDomain.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
const { token } = useAccessToken();
|
||||
const { projectId } = useProject();
|
||||
|
||||
const domainsRequest = useFetch<{ _id: string }[]>('/api/domains/list', {
|
||||
headers: computed(() => {
|
||||
return {
|
||||
'Authorization': `Bearer ${token.value}`,
|
||||
'x-pid': projectId.value || ''
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const domainList = computed(() => {
|
||||
return domainsRequest.data.value?.map(e => e._id);
|
||||
})
|
||||
|
||||
const activeDomain = ref<string>();
|
||||
|
||||
const domain = computed(() => {
|
||||
if (activeDomain.value) return activeDomain.value;
|
||||
if (!domainList.value) return;
|
||||
if (domainList.value.length == 0) return;
|
||||
activeDomain.value = domainList.value[0];
|
||||
return domainList.value[0];
|
||||
})
|
||||
|
||||
function setActiveDomain(domain: string) {
|
||||
activeDomain.value = domain;
|
||||
}
|
||||
|
||||
export function useDomain() {
|
||||
|
||||
return { domainList, domain, setActiveDomain }
|
||||
}
|
||||
Reference in New Issue
Block a user