Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat + refactor: added messenger sharing #1070

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions frontend/components/btn/BtnShareIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<template>
<component
v-if="type == 'vueSocials'"
@popup-close="nativeBehaviorOptions.onClose"
@popup-open="nativeBehaviorOptions.onOpen"
@popup-block="nativeBehaviorOptions.onBlock"
@popup-focus="nativeBehaviorOptions.onFocus"
:is="vueSocials[socialComponent]"
class="focus-brand"
:window-features="windowFeatures"
:share-options="shareOptions"
:use-native-behavior="useNativeBehavior"
:native-behavior-options="nativeBehaviorOptions"
>
<MetaTagSocialMedia
class="dark:hover:distinct-text text-primary-text hover:text-distinct-text"
:iconName="iconName"
:text="text"
:iconSize="iconSize"
/>
</component>
<component
v-else-if="type == 'redirect'"
@click="copyToClipboardThenOpenUrl(name, urlLink, redirectLink)"
@keypress.space="copyToClipboardThenOpenUrl(name, urlLink, redirectLink)"
@keypress.enter="copyToClipboardThenOpenUrl(name, urlLink, redirectLink)"
:is="vueSocials[socialComponent]"
class="focus-brand"
tabindex="0"
role="button"
>
<MetaTagSocialMedia
v-if="!contentCopied"
class="dark:hover:distinct-text text-primary-text hover:text-distinct-text"
:iconName="iconName"
:text="text"
:iconSize="iconSize"
/>
<MetaTagSocialMedia
v-if="contentCopied"
class="text-accepted-green hover:text-accepted-green dark:text-accepted-green dark:hover:text-accepted-green"
:iconName="IconMap.SQUARE_CHECK"
:text="$t('components.btn_share_icon.url_copied')"
:iconSize="iconSize"
/>
</component>
</template>

<script setup lang="ts">
import {
SEmail,
SFacebook,
SMastodon,
STelegram,
STwitter,
SFacebookMessenger,
} from "vue-socials";
import { ref, type Component } from "vue";
import { IconMap } from "~/types/icon-map";
import { toast } from "vue-sonner";
import { useI18n } from "vue-i18n";

const vueSocials: { [key: string]: Component } = {
SEmail,
SFacebook,
SMastodon,
STelegram,
STwitter,
SFacebookMessenger,
};

const props = defineProps({
type: String,
socialComponent: {
type: String,
default: "",
},
iconName: {
type: String,
default: "",
},
text: {
type: String,
default: "",
},
iconSize: String,
shareOptions: Object,
windowFeatures: Object,
useNativeBehavior: Boolean,
nativeBehaviorOptions: {
type: Object,
default: () => ({}),
},
name: {
type: String,
default: "",
},
urlLink: {
type: String,
default: "",
},
redirectLink: {
type: String,
default: null,
},
});

const { t } = useI18n();
const contentCopied = ref(false);

const getCurrentI18n: { [key: string]: string } = {
signal: "components.btn_share_icon.opening_signal",
};

const copyToClipboardThenOpenUrl = async (
name: string,
url: string,
redirectUrl?: string
) => {
try {
await navigator.clipboard.writeText(url);
contentCopied.value = true;
if (redirectUrl) {
toast(t(getCurrentI18n[props.text.toLowerCase()]));
setTimeout(() => {
contentCopied.value = false;
window.open(redirectUrl, "_blank");
}, 2000);
} else {
setTimeout(() => {
contentCopied.value = false;
}, 2000);
}
} catch (error) {
console.error(`Could not copy text: ${error}`);
contentCopied.value = false;
}
};
</script>
Loading
Loading