Add share button
This commit is contained in:
@@ -53,6 +53,40 @@ function add() {
|
|||||||
number.value = undefined;
|
number.value = undefined;
|
||||||
resetValidation();
|
resetValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function share() {
|
||||||
|
const text = `Ich habe bei TramTrack schon ${tramStore.shortStats.found} BSAG Fahrzeuge gesehen, davon ${tramStore.shortStats.trams} Trams und ${tramStore.shortStats.busses} Busse!${tramStore.shortStats.specials > 0 ? ` Besondere Fahrzeuge habe ich schon ${tramStore.shortStats.specials} gesehen!` : ''}
|
||||||
|
|
||||||
|
Sammle auch du Fahrzeuge auf ${window.location.href}`;
|
||||||
|
if (navigator.share) {
|
||||||
|
const shareResult = await navigator
|
||||||
|
.share({
|
||||||
|
title: 'Statistik teilen',
|
||||||
|
text,
|
||||||
|
url: window.location.href
|
||||||
|
})
|
||||||
|
.then(() => true)
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error sharing', error);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shareResult) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const clipboardItem = new ClipboardItem({
|
||||||
|
'text/plain': text
|
||||||
|
});
|
||||||
|
await navigator.clipboard.write([clipboardItem]);
|
||||||
|
|
||||||
|
init({
|
||||||
|
title: 'Statistik teilen',
|
||||||
|
message: 'Der Text wurde in deine Zwischenablage kopiert!',
|
||||||
|
color: 'success',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -101,6 +135,7 @@ function add() {
|
|||||||
</VaCardContent>
|
</VaCardContent>
|
||||||
<VaCardActions>
|
<VaCardActions>
|
||||||
<VaButton to="/stats" icon="arrow_outward">Mehr Statistiken</VaButton>
|
<VaButton to="/stats" icon="arrow_outward">Mehr Statistiken</VaButton>
|
||||||
|
<VaButton color="info" icon="share" @click="share">Statistiken teilen</VaButton>
|
||||||
</VaCardActions>
|
</VaCardActions>
|
||||||
</VaCard>
|
</VaCard>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
Reference in New Issue
Block a user