This commit is contained in:
Emily
2024-06-22 15:08:16 +02:00
parent 3e36e23b37
commit 67c027d720
4 changed files with 19 additions and 56 deletions

View File

@@ -1,34 +1,19 @@
<script lang="ts" setup>
import { onMounted } from 'vue';
import dayjs from 'dayjs';
import DateService, { type Slice } from '@services/DateService';
const data = ref<number[]>([]);
const labels = ref<string[]>([]);
const ready = ref<boolean>(false);
const props = defineProps<{ slice: SliceName, referrer: string }>();
const activeProject = useActiveProject();
const props = defineProps<{ slice: Slice, referrer: string }>();
async function loadData() {
const response = await $fetch(`/api/metrics/${activeProject.value?._id.toString()}/timeline/referrers`, {
method: 'POST',
...signHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify({
slice: 'hour',
from: Date.now() - 1000 * 60 * 60 * 12,
to: Date.now(),
referrer: props.referrer
})
});
const response = await useReferrersTimeline(props.referrer, props.slice);
if (!response) return;
data.value = response.map(e => e.count);
labels.value = response.map(e => dayjs(e._id).locale(navigator.language));
labels.value = response.map(e => DateService.getChartLabelFromISO(e._id, navigator.language, props.slice));
ready.value = true;
}
onMounted(async () => {