feat: add buttons for copying invite in link and plain code forms

This commit is contained in:
SauceyRed 2025-07-13 00:40:20 +02:00
parent 6578b95704
commit 1dfb964dd2
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462

View file

@ -2,8 +2,9 @@
<Modal v-bind="props" :title="props.title || 'Create an invite'"> <Modal v-bind="props" :title="props.title || 'Create an invite'">
<div id="invite-popup"> <div id="invite-popup">
<div v-if="invite"> <div v-if="invite">
<p>{{ invite }}</p> <p id="invite-label">{{ invite }}</p>
<button @click="copyInvite">Copy Link</button> <button @click="copyInvite('link')">Copy Link</button>
<button @click="copyInvite('code')">Copy Code</button>
</div> </div>
<div v-else> <div v-else>
<button @click="generateInvite">Generate Invite</button> <button @click="generateInvite">Generate Invite</button>
@ -36,13 +37,25 @@ async function generateInvite(): Promise<void> {
return; return;
} }
function copyInvite() { function copyInvite(type: "link" | "code") {
const inviteUrl = URL.parse(`invite/${invite.value}`, `${window.location.protocol}//${window.location.host}`); if (!invite.value) return;
navigator.clipboard.writeText(inviteUrl!.href);
if (type == "link") {
const inviteUrl = URL.parse(`invite/${invite.value}`, `${window.location.protocol}//${window.location.host}`);
if (inviteUrl) {
navigator.clipboard.writeText(inviteUrl.href);
}
} else {
navigator.clipboard.writeText(invite.value);
}
} }
</script> </script>
<style> <style scoped>
#invite-label {
text-align: center;
}
</style> </style>