Skip to content

Commit cdcbe2b

Browse files
authored
Merge pull request #279 from COSCUP/session-share-button-v2
2 parents 4b5fb72 + 79dce46 commit cdcbe2b

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<script setup lang="ts">
2+
import { useClipboard } from '@vueuse/core'
3+
import { useI18n } from 'vue-i18n'
4+
5+
const { title } = defineProps<{
6+
title: string
7+
}>()
8+
9+
const { t } = useI18n()
10+
const { copy, copied } = useClipboard()
11+
12+
function currentUrl() {
13+
const url = new URL(window.location.href)
14+
url.hash = ''
15+
url.search = ''
16+
return url.toString()
17+
}
18+
19+
async function share() {
20+
const url = currentUrl()
21+
22+
if (typeof navigator.share === 'function') {
23+
try {
24+
await navigator.share({
25+
text: title,
26+
title,
27+
url,
28+
})
29+
return
30+
} catch (error) {
31+
// Closing the native share sheet is not a failed share and should not copy.
32+
if (error instanceof Error && error.name === 'AbortError') {
33+
return
34+
}
35+
}
36+
}
37+
38+
await copy(url)
39+
}
40+
</script>
41+
42+
<template>
43+
<button
44+
:aria-label="copied ? t('copied') : t('share')"
45+
class="text-sm font-500 px-3 border-2 border-gray-300 rounded bg-gray-100 flex gap-1 h-8 cursor-pointer transition-colors items-center hover:bg-gray-200"
46+
type="button"
47+
@click="share"
48+
>
49+
<Icon
50+
class="text-gray-500 h-4 w-4"
51+
:name="copied ? 'tabler:check' : 'tabler:share-2'"
52+
/>
53+
<span class="hidden sm:inline">{{ copied ? t('copied') : t('share') }}</span>
54+
</button>
55+
</template>
56+
57+
<i18n lang="yaml">
58+
en:
59+
share: 'Share'
60+
copied: 'Link copied'
61+
zh:
62+
share: '分享'
63+
copied: '已複製連結'
64+
</i18n>

app/components/feature/CpSessionInfoCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const speakerNames = computed(() =>
4141
<header class="px-4 sm:px-6">
4242
<h1
4343
class="text-xl leading-tight font-bold mb-4 break-words sm:text-2xl"
44-
:class="hasTitleMarginRight ? 'mr-24 sm:mr-34' : ''"
44+
:class="hasTitleMarginRight ? 'mr-36 sm:mr-60' : ''"
4545
>
4646
{{ title }}
4747
</h1>

app/pages/session/[id].vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Ad } from '#shared/types/ad'
33
import type { SessionDetail } from '#shared/types/session'
44
import { useMediaQuery } from '@vueuse/core'
55
import { useI18n } from 'vue-i18n'
6+
import CpSessionDetailShareButton from '~/components/feature/CpSessionDetailShareButton.vue'
67
import CpSessionInfoCard from '~/components/feature/CpSessionInfoCard.vue'
78
import { useFavorites } from '~/composables/useFavorites'
89
import { DEFAULT_TRACK_COLOR } from '~/utils/tracks'
@@ -237,6 +238,10 @@ onUnmounted(() => {
237238
</div>
238239

239240
<div class="mr-4 flex gap-2 h-0 top-5 justify-end relative z-content overflow-visible sm:mr-6">
241+
<CpSessionDetailShareButton
242+
v-if="sessionInfo"
243+
:title="sessionInfo.title"
244+
/>
240245
<button
241246
:aria-label="isFavorite(sessionId) ? t('removeFavorite') : t('addFavorite')"
242247
class="text-sm font-500 px-3 border-2 rounded flex gap-1 h-8 cursor-pointer transition-colors items-center"

0 commit comments

Comments
 (0)