Skip to content

Commit

Permalink
✨ Add YouTube share link option below the video (#2610)
Browse files Browse the repository at this point in the history
* [Issue #2487] Add YouTube share link option below the video
* Add YouTube share button
* Handle non-HTTPS environment in copy operation

* [Issue #2487] Remove unused import and require the videoId prop. Fix formatting

* [Issue #2487] Use messagesStore instead raw JS alert
  • Loading branch information
chonsser authored Feb 2, 2024
1 parent c02cda5 commit daab248
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions client/components/watch/ShareOptions.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<template>
<div class="share-options">
<div class="share-options-container">
<ShareOptionEntry class="share-option" option-name="Copy Link" :click="shareCopyLink">
<ShareOptionEntry class="share-option" option-name="Copy ViewTube Link" :click="shareCopyViewTubeLink">
<VTIcon name="mdi:content-copy" class="copy-icon" />
</ShareOptionEntry>
<ShareOptionEntry class="share-option" option-name="Copy Link at Current Timestamp" :click="shareCopyLinkAtCurrentTimestamp">
<ShareOptionEntry class="share-option" option-name="Copy YouTube Link" :click="shareCopyYouTubeLink">
<VTIcon name="mdi:youtube" class="copy-icon" />
</ShareOptionEntry>
<ShareOptionEntry class="share-option" option-name="Copy ViewTube Link at Current Timestamp"
:click="shareCopyLinkAtCurrentTimestamp">
<VTIcon name="mdi:clipboard-text-time-outline" class="copy-icon" />
</ShareOptionEntry>
<ShareOptionEntry class="share-option" option-name="Open QR-Code" :click="qrOpen">
Expand All @@ -31,29 +35,53 @@
import QrPopUp from '@/components/popup/QrPopUp.vue';
import ShareOptionEntry from '@/components/list/ShareOptionEntry.vue';
import { useVideoPlayerStore } from '@/store/videoPlayer';
import { useMessagesStore } from '@/store/messages';
export default defineComponent({
name: 'ShareOptions',
components: {
ShareOptionEntry,
QrPopUp
},
setup() {
props: {
videoId: {
type: String,
required: true
}
},
setup(props) {
const messagesStore = useMessagesStore();
const qrPopUpOpen = ref(false);
const videoPlayerStore = useVideoPlayerStore();
const url = (): string => {
return window?.location.href ?? '';
};
// shareReddit() {},
const shareCopyLink = () => {
navigator.clipboard.writeText(url());
const shareCopyViewTubeLink = () => {
writeToClipboard(url());
};
const shareCopyYouTubeLink = () => {
const url = `https://youtu.be/${props.videoId}`;
writeToClipboard(url);
};
const writeToClipboard = (text: string) => {
if (!navigator.clipboard) {
messagesStore.createMessage({
title: 'Unable to copy',
message: 'Running ViewTube on non-https website.',
type: 'error',
dismissDelay: 3000
});
return;
}
navigator.clipboard.writeText(text);
};
const shareCopyLinkAtCurrentTimestamp = () => {
const currentHref = new URL(url())
currentHref.searchParams.set('t', Math.round(videoPlayerStore.currentTime).toString())
navigator.clipboard.writeText(currentHref.href);
}
const currentHref = new URL(url());
currentHref.searchParams.set('t', Math.round(videoPlayerStore.currentTime).toString());
writeToClipboard(currentHref.href);
};
const saveToPocket = () => {
window.open(`https://getpocket.com/save?url=${encodedUrl}`, '_blank');
};
Expand All @@ -75,7 +103,8 @@ export default defineComponent({
return {
qrPopUpOpen,
url,
shareCopyLink,
shareCopyViewTubeLink,
shareCopyYouTubeLink,
shareCopyLinkAtCurrentTimestamp,
qrOpen,
encodedUrl,
Expand All @@ -89,6 +118,7 @@ export default defineComponent({
<style lang="scss">
.share-options {
height: 60px;
.share-options-container {
display: flex;
flex-direction: row;
Expand Down
2 changes: 1 addition & 1 deletion client/pages/watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ const watchPageTitle = computed(() => {
</div>
<transition name="share-fade-down">
<div v-show="shareOpen">
<ShareOptions class="share-options-display" />
<ShareOptions class="share-options-display" :video-id="video.id" />
</div>
</transition>
<p v-if="video.keywords" class="video-infobox-text">Tags</p>
Expand Down

0 comments on commit daab248

Please sign in to comment.