From 4fb2a4a5c41a171b715de6660a89be4c93f744da Mon Sep 17 00:00:00 2001 From: yuWorm Date: Tue, 4 Nov 2025 15:18:22 +0800 Subject: [PATCH] move isFirstCopy to global store --- src/app/components/ClientCard/OneTimeLinkBtn.vue | 6 +++--- src/app/stores/global.ts | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/components/ClientCard/OneTimeLinkBtn.vue b/src/app/components/ClientCard/OneTimeLinkBtn.vue index c24fe0fe..f98bc58b 100644 --- a/src/app/components/ClientCard/OneTimeLinkBtn.vue +++ b/src/app/components/ClientCard/OneTimeLinkBtn.vue @@ -13,8 +13,8 @@ const props = defineProps<{ client: LocalClient }>(); const clientsStore = useClientsStore(); const toast = useToast(); +const globalStore = useGlobalStore(); const { copy, copied, isSupported } = useClipboard(); -const isFirstCopy = ref(true); const _showOneTimeLink = useSubmit( `/api/client/${props.client.id}/generateOneTimeLink`, @@ -33,12 +33,12 @@ const _showOneTimeLink = useSubmit( async function copyOneTimeLink() { // only copy when using https, since the browser blocks clipboard access on http. if (window.location.protocol !== 'https:') { - if (isFirstCopy.value) { + if (globalStore.isFirstCopyOneTimeLink) { toast.showToast({ type: 'error', message: $t('copy.onlyHttps'), }); - isFirstCopy.value = false; + globalStore.setFirstCopyOneTimeLink(false); } return; } diff --git a/src/app/stores/global.ts b/src/app/stores/global.ts index aee45d54..bc9c53fb 100644 --- a/src/app/stores/global.ts +++ b/src/app/stores/global.ts @@ -4,6 +4,7 @@ export const useGlobalStore = defineStore('Global', () => { }); const sortClient = ref(true); // Sort clients by name, true = asc, false = desc + const isFirstCopyOneTimeLink = ref(true); // Flag to track if it's the first time the copy one-time link is clicked const uiShowCharts = useCookie('uiShowCharts', { default: () => false, @@ -14,6 +15,10 @@ export const useGlobalStore = defineStore('Global', () => { uiShowCharts.value = !uiShowCharts.value; } + function setFirstCopyOneTimeLink(value: boolean) { + isFirstCopyOneTimeLink.value = value; + } + const uiChartType = useCookie<'area' | 'bar' | 'line'>('uiChartType', { default: () => 'area', maxAge: 365 * 24 * 60 * 60, @@ -25,5 +30,7 @@ export const useGlobalStore = defineStore('Global', () => { uiShowCharts, toggleCharts, uiChartType, + isFirstCopyOneTimeLink, + setFirstCopyOneTimeLink, }; });