Browse Source

move isFirstCopy to global store

pull/2252/head
yuWorm 8 months ago
parent
commit
4fb2a4a5c4
  1. 6
      src/app/components/ClientCard/OneTimeLinkBtn.vue
  2. 7
      src/app/stores/global.ts

6
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;
}

7
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<boolean>('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,
};
});

Loading…
Cancel
Save