Browse Source

add format onetimelink helper

pull/2252/head
Bernd Storath 8 months ago
parent
commit
17760d2f43
  1. 4
      src/app/components/ClientCard/OneTimeLink.vue
  2. 10
      src/app/components/ClientCard/OneTimeLinkBtn.vue
  3. 7
      src/app/stores/clients.ts
  4. 6
      src/app/utils/format.ts

4
src/app/components/ClientCard/OneTimeLink.vue

@ -22,7 +22,7 @@ onMounted(() => {
new Date(props.client.oneTimeLink.expiresAt).getTime() - Date.now();
if (timeLeft <= 0) {
path.value = `${props.client.oneTimeConfigUrl} (00:00)`;
path.value = `${formatOneTimeLink(document.location, props.client.oneTimeLink)} (00:00)`;
return;
}
@ -39,7 +39,7 @@ onMounted(() => {
date.setMinutes(minutes);
date.setSeconds(seconds);
path.value = `${props.client.oneTimeConfigUrl} (${formatter.format(date)})`;
path.value = `${formatOneTimeLink(document.location, props.client.oneTimeLink)} (${formatter.format(date)})`;
}, 1000);
});

10
src/app/components/ClientCard/OneTimeLinkBtn.vue

@ -39,15 +39,7 @@ async function copyOneTimeLink() {
}
await nextTick();
if (!props.client.oneTimeConfigUrl) {
toast.showToast({
type: 'error',
message: $t('copy.error'),
});
return;
}
await copy(props.client.oneTimeConfigUrl);
await copy(formatOneTimeLink(document.location, props.client.oneTimeLink));
if (!copied.value) {
toast.showToast({

7
src/app/stores/clients.ts

@ -15,7 +15,6 @@ export type LocalClient = WGClientReturn & {
export type ClientPersist = {
transferRxHistory: number[];
oneTimeConfigUrl?: string;
transferRxPrevious: number;
transferRxCurrent: number;
transferRxSeries: { name: string; data: number[] }[];
@ -60,7 +59,6 @@ export const useClientsStore = defineStore('Clients', () => {
transferTxCurrent: 0,
transferRxSeries: [],
transferTxSeries: [],
oneTimeConfigUrl: '',
};
}
@ -112,10 +110,6 @@ export const useClientsStore = defineStore('Clients', () => {
);
}
if (client.oneTimeLink !== null) {
clientPersist.oneTimeConfigUrl = `${document?.location?.protocol}//${document?.location?.host}/cnf/${client.oneTimeLink.oneTimeLink}`;
}
return {
...client,
avatar,
@ -128,7 +122,6 @@ export const useClientsStore = defineStore('Clients', () => {
transferRxCurrent: clientPersist.transferRxCurrent,
hoverTx: clientPersist.hoverTx,
hoverRx: clientPersist.hoverRx,
oneTimeConfigUrl: clientPersist.oneTimeConfigUrl,
};
});

6
src/app/utils/format.ts

@ -0,0 +1,6 @@
export function formatOneTimeLink(
location: Location,
oneTimeLink: { oneTimeLink: string }
) {
return `${location.protocol}//${location.host}/cnf/${oneTimeLink.oneTimeLink}`;
}
Loading…
Cancel
Save