mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
adjustments
This commit is contained in:
39
dashboard/composables/Projects.ts
Normal file
39
dashboard/composables/Projects.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { TProject } from "@schema/ProjectSchema";
|
||||
|
||||
const projects = useFetch<TProject[]>('/api/project/list', {
|
||||
key: 'projectslist', ...signHeaders()
|
||||
});
|
||||
|
||||
|
||||
|
||||
export function useProjectsList() {
|
||||
return { ...projects, projects: projects.data }
|
||||
}
|
||||
|
||||
|
||||
const activeProjectId = useFetch<string>(`/api/user/active_project`, {
|
||||
key: 'activeProjectId', ...signHeaders(),
|
||||
});
|
||||
|
||||
export function useActiveProjectId() {
|
||||
return { ...activeProjectId, pid: activeProjectId.data }
|
||||
}
|
||||
|
||||
export function useActiveProject() {
|
||||
if (isLiveDemo()) {
|
||||
const { data: liveDemoProject } = useLiveDemo();
|
||||
return liveDemoProject;
|
||||
}
|
||||
return computed(() => {
|
||||
if (!projects.data.value) return;
|
||||
if (!activeProjectId.data.value) return;
|
||||
const target = projects.data.value.find(e => e._id.toString() == activeProjectId.data.value);
|
||||
return target;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export async function setActiveProject(project_id: string) {
|
||||
await $fetch<string>(`/api/user/set_active_project?project_id=${project_id}`, signHeaders());
|
||||
await activeProjectId.refresh();
|
||||
}
|
||||
Reference in New Issue
Block a user