mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
implementig snapshots
This commit is contained in:
@@ -5,11 +5,21 @@ import type { IconProvider } from './BarsCard.vue';
|
|||||||
import ReferrerBarChart from '../referrer/ReferrerBarChart.vue';
|
import ReferrerBarChart from '../referrer/ReferrerBarChart.vue';
|
||||||
|
|
||||||
const activeProject = await useActiveProject();
|
const activeProject = await useActiveProject();
|
||||||
|
|
||||||
|
const { safeSnapshotDates, snapshot } = useSnapshot();
|
||||||
|
|
||||||
const { data: events, pending, refresh } = await useFetch<ReferrersAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/referrers`, {
|
const { data: events, pending, refresh } = await useFetch<ReferrersAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/referrers`, {
|
||||||
...signHeaders(),
|
...signHeaders({
|
||||||
|
'x-from': safeSnapshotDates.value.from,
|
||||||
|
'x-to': safeSnapshotDates.value.to
|
||||||
|
}),
|
||||||
lazy: true
|
lazy: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(snapshot,()=>{
|
||||||
|
refresh();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
function iconProvider(id: string): ReturnType<IconProvider> {
|
function iconProvider(id: string): ReturnType<IconProvider> {
|
||||||
if (id === 'self') return ['icon', 'fas fa-link'];
|
if (id === 'self') return ['icon', 'fas fa-link'];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Slice } from "@services/DateService";
|
import type { Slice } from "@services/DateService";
|
||||||
import DateService from "@services/DateService";
|
import DateService from "@services/DateService";
|
||||||
import type { MetricsCounts } from "~/server/api/metrics/[project_id]/counts";
|
import type { MetricsCounts } from "~/server/api/metrics/[project_id]/counts";
|
||||||
|
import type { ReferrersAggregated } from "~/server/api/metrics/[project_id]/data/referrers";
|
||||||
import type { VisitsWebsiteAggregated } from "~/server/api/metrics/[project_id]/data/websites";
|
import type { VisitsWebsiteAggregated } from "~/server/api/metrics/[project_id]/data/websites";
|
||||||
import type { MetricsTimeline } from "~/server/api/metrics/[project_id]/timeline/generic";
|
import type { MetricsTimeline } from "~/server/api/metrics/[project_id]/timeline/generic";
|
||||||
|
|
||||||
@@ -87,18 +88,37 @@ export function usePagesData(website: string, limit: number = 10) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { safeSnapshotDates } = useSnapshot()
|
const { safeSnapshotDates, snapshot } = useSnapshot()
|
||||||
|
const activeProject = useActiveProject();
|
||||||
|
|
||||||
|
const getFromToHeaders = (headers: Record<string, string> = {}) => ({
|
||||||
|
'x-from': safeSnapshotDates.value.from,
|
||||||
|
'x-to': safeSnapshotDates.value.to,
|
||||||
|
...headers
|
||||||
|
});
|
||||||
|
|
||||||
export function useWebsitesData(limit: number = 10) {
|
export function useWebsitesData(limit: number = 10) {
|
||||||
const activeProject = useActiveProject();
|
const activeProject = useActiveProject();
|
||||||
const res = useFetch<VisitsWebsiteAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/websites`, {
|
const res = useFetch<VisitsWebsiteAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/websites`, {
|
||||||
...signHeaders({
|
...signHeaders({
|
||||||
'x-query-limit': limit.toString(),
|
'x-query-limit': limit.toString(),
|
||||||
'x-from': safeSnapshotDates.value.from,
|
'x-from': safeSnapshotDates.value.from,
|
||||||
'x-to': safeSnapshotDates.value.to
|
'x-to': safeSnapshotDates.value.to
|
||||||
}),
|
}),
|
||||||
key: `websites_data:${limit}:${safeSnapshotDates.value.from}:${safeSnapshotDates.value.to}`,
|
key: `websites_data:${limit}:${safeSnapshotDates.value.from}:${safeSnapshotDates.value.to}`,
|
||||||
lazy: true,
|
lazy: true,
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function useReferrersData(limit: number = 10) {
|
||||||
|
|
||||||
|
const res = useCustomFetch<ReferrersAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/referrers`,
|
||||||
|
() => signHeaders(getFromToHeaders({ 'x-query-limit': limit.toString() })).headers,
|
||||||
|
{ lazy: true, watchProps: [snapshot] }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -119,7 +119,7 @@ const selectLabels = [
|
|||||||
|
|
||||||
</div> -->
|
</div> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
<div class="flex w-full justify-center mt-6 px-6">
|
<div class="flex w-full justify-center mt-6 px-6">
|
||||||
<div class="flex w-full gap-6 flex-col xl:flex-row">
|
<div class="flex w-full gap-6 flex-col xl:flex-row">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
@@ -129,7 +129,7 @@ const selectLabels = [
|
|||||||
<DashboardEventsBarCard></DashboardEventsBarCard>
|
<DashboardEventsBarCard></DashboardEventsBarCard>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
|
|
||||||
<div class="flex w-full justify-center mt-6 px-6">
|
<div class="flex w-full justify-center mt-6 px-6">
|
||||||
@@ -143,7 +143,7 @@ const selectLabels = [
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex w-full justify-center mt-6 px-6">
|
<!-- <div class="flex w-full justify-center mt-6 px-6">
|
||||||
<div class="flex w-full gap-6 flex-col xl:flex-row">
|
<div class="flex w-full gap-6 flex-col xl:flex-row">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<DashboardOssBarCard></DashboardOssBarCard>
|
<DashboardOssBarCard></DashboardOssBarCard>
|
||||||
@@ -162,7 +162,7 @@ const selectLabels = [
|
|||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user