implementing snapshots + change ui

This commit is contained in:
Emily
2024-07-31 16:02:00 +02:00
parent 7cb10f5aa1
commit 6c32b64ac6
8 changed files with 125 additions and 116 deletions

View File

@@ -109,7 +109,7 @@ export function usePagesData(website: string, limit: number = 10) {
export function useWebsitesData(limit: number = 10) {
const res = useCustomFetch<ReferrersAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/websites`,
const res = useCustomFetch<VisitsWebsiteAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/websites`,
() => signHeaders(createFromToHeaders({ 'x-query-limit': limit.toString() })).headers,
{ lazy: false, watchProps: [snapshot] }
);

View File

@@ -6,8 +6,9 @@ const remoteSnapshots = useFetch<TProjectSnapshot[]>('/api/project/snapshots', {
});
const activeProject = useActiveProject();
watch(activeProject, () => {
remoteSnapshots.refresh();
watch(activeProject, async () => {
await remoteSnapshots.refresh();
snapshot.value = snapshots.value[1];
});
const snapshots = computed(() => {
@@ -57,19 +58,14 @@ const snapshots = computed(() => {
const snapshot = ref<TProjectSnapshot>(snapshots.value[1]);
// watch(remoteSnapshots.data, () => {
// if (!remoteSnapshots.data.value) return;
// snapshot.value = remoteSnapshots.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 }
})
function updateSnapshots() {
remoteSnapshots.refresh();
async function updateSnapshots() {
await remoteSnapshots.refresh();
}
export function useSnapshot() {