This commit is contained in:
Emily
2024-10-09 15:30:59 +02:00
parent 126296d28f
commit e953af2c1b
27 changed files with 271 additions and 209 deletions

View File

@@ -1,13 +1,11 @@
export function isLiveDemo() {
const route = useRoute();
const route = useRoute();
export const isLiveDemo = computed(() => {
return route.path == '/live_demo';
}
})
const liveDemoData = useFetch('/api/live_demo');
export function useLiveDemo() {
return liveDemoData;
}
export function useLiveDemo() { return liveDemoData; }

View File

@@ -43,24 +43,31 @@ const setActiveProject = (project_id: string) => {
}
const project = computed(() => {
if (!projectList.value) return;
if (projectList.value.length == 0) return;
if (isLiveDemo.value) return useLiveDemo().data.value;
if (!allProjectList.value) return;
if (allProjectList.value.length == 0) return;
if (activeProjectId.value) {
const target = projectList.value.find(e => e._id.toString() == activeProjectId.value);
const target = allProjectList.value.find(e => e._id.toString() == activeProjectId.value);
if (target) return target;
}
const savedActive = localStorage.getItem('active_pid');
if (savedActive) {
const target = projectList.value.find(e => e._id.toString() == savedActive);
const target = allProjectList.value.find(e => e._id.toString() == savedActive);
if (target) {
activeProjectId.value = savedActive;
return target;
}
}
activeProjectId.value = projectList.value[0]._id.toString();
return projectList.value[0];
activeProjectId.value = allProjectList.value[0]._id.toString();
return allProjectList.value[0];
})
const projectId = computed(() => project.value?._id.toString())
const isGuest = computed(() => {
return (projectList.value || []).find(e => e._id.toString() === activeProjectId.value) == undefined;
@@ -73,5 +80,5 @@ export function useProject() {
setActiveProject
}
return { project, allProjectList, guestProjectList, projectList, actions, projectId: activeProjectId, isGuest }
return { project, allProjectList, guestProjectList, projectList, actions, projectId, isGuest }
}

View File

@@ -15,7 +15,7 @@ const remoteSnapshots = useFetch<TProjectSnapshot[]>('/api/project/snapshots', {
watch(project, async () => {
await remoteSnapshots.refresh();
snapshot.value = isLiveDemo() ? snapshots.value[0] : snapshots.value[1];
snapshot.value = isLiveDemo.value ? snapshots.value[0] : snapshots.value[1];
});
const snapshots = computed(() => {
@@ -61,7 +61,7 @@ const snapshots = computed(() => {
];
})
const snapshot = ref<TProjectSnapshot>(isLiveDemo() ? snapshots.value[0] : snapshots.value[1]);
const snapshot = ref<TProjectSnapshot>(isLiveDemo.value ? snapshots.value[0] : snapshots.value[1]);
const safeSnapshotDates = computed(() => {
const from = new Date(snapshot.value?.from || 0).toISOString();