From 893a6ce9fba76261c9501a5f851e6849c514b735 Mon Sep 17 00:00:00 2001
From: Pascal Syma
Date: Fri, 12 Sep 2025 15:44:17 +0200
Subject: [PATCH] Add share button
---
src/pages/HomeView.vue | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/pages/HomeView.vue b/src/pages/HomeView.vue
index 97cf973..ae63243 100644
--- a/src/pages/HomeView.vue
+++ b/src/pages/HomeView.vue
@@ -53,6 +53,40 @@ function add() {
number.value = undefined;
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
+ });
+}
@@ -101,6 +135,7 @@ function add() {
Mehr Statistiken
+ Statistiken teilen