implementing snapshots

This commit is contained in:
Emily
2024-07-26 01:29:58 +02:00
parent 2c9f5c45f8
commit e9505e24a0
12 changed files with 238 additions and 45 deletions

View File

@@ -0,0 +1,26 @@
import type { TProjectSnapshot } from "@schema/ProjectSnapshot";
const snapshots = useFetch<TProjectSnapshot[]>('/api/project/snapshots', {
...signHeaders(),
immediate: false
});
const snapshot = ref<TProjectSnapshot>();
watch(snapshots.data, () => {
if (!snapshots.data.value) return;
snapshot.value = snapshots.data.value[0];
});
const safeSnapshotDates = computed(() => {
const from = new Date(snapshot.value?.from || 0).toISOString();
const to = new Date(snapshot.value?.to || Date.now()).toISOString();
return { from, to }
})
export function useSnapshot() {
if (snapshots.status.value === 'idle') {
snapshots.execute();
}
return { snapshot, snapshots, safeSnapshotDates }
}