feat(dashboard): add copy link button
This commit is contained in:
parent
6468068ca4
commit
42064c66b0
@ -67,6 +67,38 @@
|
|||||||
cardIndexArray[index].classList.remove("collapsed");
|
cardIndexArray[index].classList.remove("collapsed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getShortLink(id: string) {
|
||||||
|
let url = "https://pk.mt"
|
||||||
|
|
||||||
|
if (itemType === "member") url += "/m/"
|
||||||
|
else if (itemType === "group") url += "/g/"
|
||||||
|
|
||||||
|
url += id;
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
let copiedArray = [];
|
||||||
|
|
||||||
|
async function copyShortLink(index: number, id: string, event?) {
|
||||||
|
if (event) {
|
||||||
|
if (event.key !== "Tab") event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
let ctrlDown = event.ctrlKey||event.metaKey; // mac support
|
||||||
|
if (!(ctrlDown && event.key === "c") && event.key !== "Enter") return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(getShortLink(id));
|
||||||
|
|
||||||
|
copiedArray[index] = true;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
copiedArray[index] = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if settings && settings.accessibility ? (!settings.accessibility.expandedcards && !settings.accessibility.pagelinks) : true}
|
{#if settings && settings.accessibility ? (!settings.accessibility.expandedcards && !settings.accessibility.pagelinks) : true}
|
||||||
@ -76,7 +108,7 @@
|
|||||||
<h2 class="accordion-header">
|
<h2 class="accordion-header">
|
||||||
<button class="w-100 accordion-button collapsed" bind:this={cardIndexArray[index]} on:click={() => toggleCard(index)} on:keydown={(e) => skipToNextItem(e, index)}>
|
<button class="w-100 accordion-button collapsed" bind:this={cardIndexArray[index]} on:click={() => toggleCard(index)} on:keydown={(e) => skipToNextItem(e, index)}>
|
||||||
<CardsHeader {item}>
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon" style="cursor: pointer;" id={`copy-${item.id}-${index}`} on:click|stopPropagation={() => copyShortLink(index, item.id)} on:keydown={(e) => copyShortLink(index, item.id, e)} tabindex={0} >
|
||||||
{#if isPublic || item.privacy.visibility === "public"}
|
{#if isPublic || item.privacy.visibility === "public"}
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
<FaUserCircle />
|
<FaUserCircle />
|
||||||
@ -88,6 +120,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
|
<Tooltip placement="top" target={`copy-${item.id}-${index}`}>{copiedArray[index] ? "Copied!" : "Copy public link"}</Tooltip>
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<Collapse isOpen={isOpenArray[index]}>
|
<Collapse isOpen={isOpenArray[index]}>
|
||||||
@ -108,7 +141,7 @@
|
|||||||
<div class="accordion-button collapsed p-0" bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} tabindex={0}>
|
<div class="accordion-button collapsed p-0" bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} tabindex={0}>
|
||||||
<CardHeader class="w-100">
|
<CardHeader class="w-100">
|
||||||
<CardsHeader {item}>
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon" style="cursor: pointer;" id={`copy-${item.id}-${index}`} on:click|stopPropagation={() => copyShortLink(index, item.id)} on:keydown|stopPropagation={(e) => copyShortLink(index, item.id, e)} tabindex={0} >
|
||||||
{#if isPublic || item.privacy.visibility === "public"}
|
{#if isPublic || item.privacy.visibility === "public"}
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
<FaUserCircle />
|
<FaUserCircle />
|
||||||
@ -120,6 +153,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
|
<Tooltip placement="top" target={`copy-${item.id}-${index}`}>{copiedArray[index] ? "Copied!" : "Copy public link"}</Tooltip>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
</div>
|
</div>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
@ -137,7 +171,7 @@
|
|||||||
<Card>
|
<Card>
|
||||||
<a class="accordion-button collapsed" style="text-decoration: none;" href={getItemLink(item)} bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} use:link >
|
<a class="accordion-button collapsed" style="text-decoration: none;" href={getItemLink(item)} bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} use:link >
|
||||||
<CardsHeader {item}>
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon" style="cursor: pointer;" id={`copy-${item.id}-${index}`} on:click|stopPropagation={() => copyShortLink(index, item.id)} on:keydown|stopPropagation={(e) => copyShortLink(index, item.id, e)} tabindex={0} >
|
||||||
{#if isPublic || item.privacy.visibility === "public"}
|
{#if isPublic || item.privacy.visibility === "public"}
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
<FaUserCircle />
|
<FaUserCircle />
|
||||||
@ -149,6 +183,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
|
<Tooltip placement="top" target={`copy-${item.id}-${index}`}>{copiedArray[index] ? "Copied!" : "Copy public link"}</Tooltip>
|
||||||
</a>
|
</a>
|
||||||
</Card>
|
</Card>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Card, CardBody, CardHeader } from 'sveltestrap';
|
import { Card, CardBody, CardHeader, Tooltip } from 'sveltestrap';
|
||||||
import FaAddressCard from 'svelte-icons/fa/FaAddressCard.svelte'
|
import FaAddressCard from 'svelte-icons/fa/FaAddressCard.svelte'
|
||||||
import CardsHeader from '../CardsHeader.svelte';
|
import CardsHeader from '../CardsHeader.svelte';
|
||||||
import Body from './Body.svelte';
|
import Body from './Body.svelte';
|
||||||
@ -12,13 +12,32 @@
|
|||||||
export let isPublic = true;
|
export let isPublic = true;
|
||||||
|
|
||||||
let editMode = false;
|
let editMode = false;
|
||||||
|
let copied = false;
|
||||||
|
|
||||||
|
async function copyShortLink(event?) {
|
||||||
|
if (event) {
|
||||||
|
let ctrlDown = event.ctrlKey||event.metaKey; // mac support
|
||||||
|
if (!(ctrlDown && event.key === "c") && event.key !== "Enter") return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(`https://pk.mt/s/${user.id}`);
|
||||||
|
copied = true;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
copied = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card class="mb-4">
|
<Card class="mb-4">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardsHeader bind:item={user}>
|
<CardsHeader bind:item={user}>
|
||||||
<FaAddressCard slot="icon" />
|
<div slot="icon" style="cursor: pointer;" id={`copy-${user.id}`} on:click|stopPropagation={() => copyShortLink()} on:keydown|stopPropagation={(e) => copyShortLink(e)} tabindex={0} >
|
||||||
|
<FaAddressCard />
|
||||||
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
|
<Tooltip placement="top" target={`copy-${user.id}`}>{copied ? "Copied!" : "Copy public link"}</Tooltip>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody style="border-left: 4px solid #{user.color}">
|
<CardBody style="border-left: 4px solid #{user.color}">
|
||||||
{#if !editMode}
|
{#if !editMode}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user