From 46774bd1148bef4aacd99771a662d259c64a725e Mon Sep 17 00:00:00 2001 From: Emily Date: Tue, 6 Aug 2024 03:00:24 +0200 Subject: [PATCH] fix reactivity --- .../components/dashboard/BrowsersBarCard.vue | 44 +++++++++++----- .../components/dashboard/DevicesBarCard.vue | 42 ++++++++++----- .../components/dashboard/EventsBarCard.vue | 44 ++++++++++------ dashboard/components/dashboard/OssBarCard.vue | 42 ++++++++++----- .../components/dashboard/ReferrersBarCard.vue | 51 +++++++++++-------- dashboard/composables/useAccessToken.ts | 5 ++ dashboard/pages/index.vue | 32 +++++++----- 7 files changed, 167 insertions(+), 93 deletions(-) diff --git a/dashboard/components/dashboard/BrowsersBarCard.vue b/dashboard/components/dashboard/BrowsersBarCard.vue index eec3b0c..ef3bff9 100644 --- a/dashboard/components/dashboard/BrowsersBarCard.vue +++ b/dashboard/components/dashboard/BrowsersBarCard.vue @@ -1,30 +1,46 @@ diff --git a/dashboard/components/dashboard/DevicesBarCard.vue b/dashboard/components/dashboard/DevicesBarCard.vue index c577243..cbb3ea1 100644 --- a/dashboard/components/dashboard/DevicesBarCard.vue +++ b/dashboard/components/dashboard/DevicesBarCard.vue @@ -1,32 +1,46 @@ diff --git a/dashboard/components/dashboard/EventsBarCard.vue b/dashboard/components/dashboard/EventsBarCard.vue index 9c4eefe..dcee8ba 100644 --- a/dashboard/components/dashboard/EventsBarCard.vue +++ b/dashboard/components/dashboard/EventsBarCard.vue @@ -1,31 +1,42 @@ @@ -33,7 +44,8 @@ function showMore() { diff --git a/dashboard/components/dashboard/OssBarCard.vue b/dashboard/components/dashboard/OssBarCard.vue index 1c45417..191ba05 100644 --- a/dashboard/components/dashboard/OssBarCard.vue +++ b/dashboard/components/dashboard/OssBarCard.vue @@ -1,30 +1,44 @@ diff --git a/dashboard/components/dashboard/ReferrersBarCard.vue b/dashboard/components/dashboard/ReferrersBarCard.vue index 7cd9bac..2c7ed8a 100644 --- a/dashboard/components/dashboard/ReferrersBarCard.vue +++ b/dashboard/components/dashboard/ReferrersBarCard.vue @@ -3,9 +3,6 @@ import type { IconProvider } from './BarsCard.vue'; import ReferrerBarChart from '../referrer/ReferrerBarChart.vue'; -const { data: events, pending, refresh } = useReferrersData(10); - - function iconProvider(id: string): ReturnType { if (id === 'self') return ['icon', 'fas fa-link']; return ['img', `https://s2.googleusercontent.com/s2/favicons?domain=${id}&sz=64`] @@ -16,6 +13,24 @@ function elementTextTransformer(element: string) { return element; } +const activeProject = useActiveProject(); + +const { safeSnapshotDates } = useSnapshot() + +const isShowMore = ref(false); + +const headers = computed(() => { + return { + 'x-from': safeSnapshotDates.value.from, + 'x-to': safeSnapshotDates.value.to, + Authorization: authorizationHeaderComputed.value, + limit: isShowMore.value === true ? '200' : '10' + } +}); + +const referrersData = useFetch(`/api/metrics/${activeProject.value?._id}/data/referrers`, { + method: 'POST', headers, lazy: true, immediate: false +}); const { showDialog, dialogBarData, isDataLoading } = useBarCardDialog(); @@ -25,35 +40,29 @@ function onShowDetails(referrer: string) { customDialog.openDialog(ReferrerBarChart, { slice: 'day', referrer }); } - - - function showMore() { + isShowMore.value = true; showDialog.value = true; - dialogBarData.value = []; - isDataLoading.value = true; - - - const moreRes = useReferrersData(200); - - moreRes.onResponse(data => { - dialogBarData.value = data.value?.map(e => { - return { ...e, icon: iconProvider(e._id) } - }) || []; - isDataLoading.value = false; - }) + dialogBarData.value = referrersData.data.value?.map(e => { + return { ...e, icon: iconProvider(e._id) } + }) || []; } +onMounted(async () => { + referrersData.execute(); +}); + diff --git a/dashboard/composables/useAccessToken.ts b/dashboard/composables/useAccessToken.ts index 7cf2aa0..e3cb1da 100644 --- a/dashboard/composables/useAccessToken.ts +++ b/dashboard/composables/useAccessToken.ts @@ -9,6 +9,11 @@ export function signHeaders(headers?: Record) { return { headers: { ...(headers || {}), 'Authorization': 'Bearer ' + token.value } } } +export const authorizationHeaderComputed = computed(() => { + const { token } = useAccessToken() + return token.value ? 'Bearer ' + token.value : ''; +}); + export function useAccessToken() { const tokenCookie = useCookie(ACCESS_TOKEN_COOKIE_KEY, { expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30) }) diff --git a/dashboard/pages/index.vue b/dashboard/pages/index.vue index 16f135e..b6b9ba3 100644 --- a/dashboard/pages/index.vue +++ b/dashboard/pages/index.vue @@ -100,30 +100,32 @@ const refreshKey = computed(() => `${snapshot.value._id.toString()}`); --> -
+
-
- Limit reached +
+ Limit reached +
+
+ Litlyx has stopped to collect yur data. Please upgrade the plan for a minimal data loss. +
-
- Litlyx has stopped to collect yur data. Please upgrade the plan for a minimal data loss. +
+ Upgrade
-
-
- Upgrade -
- +
- +