feat: add support for sharing via WhatsApp Messenger and WhatsApp Business
This commit is contained in:
parent
b3184de155
commit
76c24dc909
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Copy, MessageCircle, Share2 } from '@lucide/vue';
|
import { Briefcase, Copy, MessageCircle, Share2 } from '@lucide/vue';
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@ -67,12 +67,26 @@ async function copyLink() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shareViaWhatsApp() {
|
function openWALink(url: string) {
|
||||||
const encodedText = encodeURIComponent(whatsappText.value);
|
|
||||||
const url = `https://wa.me/?text=${encodedText}`;
|
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
open.value = false;
|
open.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shareViaWhatsAppMessenger() {
|
||||||
|
const text = encodeURIComponent(whatsappText.value);
|
||||||
|
const webUrl = `https://wa.me/?text=${text}`;
|
||||||
|
const intentUrl = `intent://send?text=${text}#Intent;scheme=whatsapp;package=com.whatsapp;end`;
|
||||||
|
const url = /android/i.test(navigator.userAgent) ? intentUrl : webUrl;
|
||||||
|
openWALink(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shareViaWhatsAppBusiness() {
|
||||||
|
const text = encodeURIComponent(whatsappText.value);
|
||||||
|
const webUrl = `https://wa.me/?text=${text}`;
|
||||||
|
const intentUrl = `intent://send?text=${text}#Intent;scheme=whatsapp;package=com.whatsapp.w4b;end`;
|
||||||
|
const url = /android/i.test(navigator.userAgent) ? intentUrl : webUrl;
|
||||||
|
openWALink(url);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -94,9 +108,13 @@ function shareViaWhatsApp() {
|
|||||||
<Copy class="size-4" />
|
<Copy class="size-4" />
|
||||||
{{ copied ? 'Tersalin!' : 'Salin Link' }}
|
{{ copied ? 'Tersalin!' : 'Salin Link' }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" class="w-full justify-start gap-2" @click="shareViaWhatsApp">
|
<Button variant="ghost" size="sm" class="w-full justify-start gap-2" @click="shareViaWhatsAppMessenger">
|
||||||
<MessageCircle class="size-4" />
|
<MessageCircle class="size-4" />
|
||||||
WhatsApp
|
WhatsApp Messenger
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" size="sm" class="w-full justify-start gap-2" @click="shareViaWhatsAppBusiness">
|
||||||
|
<Briefcase class="size-4" />
|
||||||
|
WhatsApp Business
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user