Skip to content

Commit

Permalink
Copy URL to clipboard upon clicking QR code. Fix missing origin in li…
Browse files Browse the repository at this point in the history
…nk generation.
  • Loading branch information
mross-ua committed Sep 23, 2023
1 parent 968aa91 commit a9591e5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const menuPassThroughOptions = {
<NuxtPage />
</div>
</div>

<Toast />
</template>

<style>
Expand Down
40 changes: 35 additions & 5 deletions components/share/ShareButton.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script setup lang="ts">
import { useToast } from "primevue/usetoast";
import { scoreboardMenuItem } from '~~/nav';
import type { ID, Team } from '~~/types';
const toast = useToast();
const props = defineProps<{
teamId: ID
team: Team
Expand All @@ -14,6 +18,30 @@ const buttonPassThroughOptions = {
};
const isDialogVisible = ref(false);
function getScoreboardPath(path: string) {
return location.origin.concat(path, '/', props.teamId);
}
function clickQrCode(path: string) {
const scoreboardPath = getScoreboardPath(path);
if (navigator.share) {
navigator.share({
title: `${props.team.name}'s Scoreboard`,
url: scoreboardPath
}).catch(console.error);
} else if (navigator.clipboard) {
navigator.clipboard.writeText(scoreboardPath).then(
() => {
toast.add({ severity: 'info', detail: 'Scoreboard URL copied to clipboard!', life: 2000 });
},
() => {
toast.add({ severity: 'error', detail: 'Scoreboard URL not copied to clipboard!', life: 2000 });
},
);
}
}
</script>


Expand All @@ -39,14 +67,16 @@ const isDialogVisible = ref(false);
}"
>
<RouterLink :to="scoreboardMenuItem.to!" v-slot="{ href, route, navigate, isActive, isExactActive }" custom>
<a :href="href.concat('/', props.teamId)" v-bind="props.action" @click="navigate" class="block">
<button type="button" @click="clickQrCode(href)" class="block mx-auto mb-3">
<VueQrcode
:value="href.concat('/', props.teamId)"
:value="getScoreboardPath(href)"
type="image/png"
:color="{ dark: '#000000ff', light: '#ffffffff' }"
class="block mx-auto"
/>
</a>
</RouterLink>
</button>
<p class="text-center">
Click or scan the QR code, or use <a :href="`${getScoreboardPath(href)}`" class="underline">this link</a>.
</p>
</RouterLink>
</Dialog>
</template>

0 comments on commit a9591e5

Please sign in to comment.