Skip to content

Commit 2ca82d4

Browse files
committed
add share copy input
1 parent 0b5195f commit 2ca82d4

5 files changed

Lines changed: 67 additions & 23 deletions

File tree

src/lib/components/CopyInput.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
value: string;
1010
class?: string;
1111
icon?: Snippet;
12+
displayValue?: string;
1213
}
1314
14-
let { value, class: className, icon }: Props = $props();
15+
let { value, class: className, icon, displayValue }: Props = $props();
1516
1617
let copied = $state(false);
1718
@@ -32,7 +33,13 @@
3233
{#if icon}
3334
{@render icon()}
3435
{/if}
35-
<input class="mx-3 grow outline-none!" type="text" bind:value readonly disabled />
36+
<input
37+
class="mx-3 grow outline-none!"
38+
type="text"
39+
value={displayValue ?? value}
40+
readonly
41+
disabled
42+
/>
3643
<span>
3744
<button
3845
onclick={copyToken}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { resolve } from '$app/paths';
2+
import type { Pathname } from '$app/types';
3+
import { getSiteURL, isShortLinkOrigin } from '$lib/utils/url';
4+
import { redirect } from '@sveltejs/kit';
5+
import type { RequestHandler } from './$types';
6+
7+
export const GET: RequestHandler = ({ url, params }) => {
8+
const target: Pathname = `/shares/public/${params.id}`;
9+
10+
if (isShortLinkOrigin(url)) {
11+
return redirect(303, getSiteURL(target));
12+
}
13+
14+
return redirect(303, resolve(target));
15+
};
File renamed without changes.

src/routes/shares/public/[shareId=guid]/ControlView.svelte

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
import { ShareLinkSignalr } from '$lib/signalr/sharelink.svelte';
88
import type { Control } from '$lib/signalr/models/Control';
99
import { onMount, untrack } from 'svelte';
10+
import { page } from '$app/state';
11+
import CopyInput from '$lib/components/CopyInput.svelte';
12+
import { getSiteShortURL } from '$lib/utils/url';
13+
import { Button } from '$lib/components/ui/button';
14+
import { Pencil } from '@lucide/svelte';
15+
import { userState } from '$lib/state/user-state.svelte';
16+
import { resolve } from '$app/paths';
1017
1118
interface Props {
1219
shareLinkRoot: PublicShareResponse;
@@ -28,10 +35,15 @@
2835
function control(control: Control) {
2936
shareLinkSignalr.control([control]);
3037
}
38+
39+
const shareId = $derived(page.params.shareId);
40+
41+
let editUrl = $derived(resolve(`/shares/public/${shareId}/edit`));
42+
const shareUrl = $derived(getSiteShortURL(`/s/${shareId}`));
3143
</script>
3244

3345
<div class="m-5 flex h-full w-full flex-col gap-15">
34-
<div class="flex w-full flex-row content-between">
46+
<div class="grid grid-cols-3 grid-rows-1">
3547
<div class="flex w-full flex-col">
3648
<h1 class="text-2xl font-bold">Public Share: {shareLinkRoot.name}</h1>
3749
<p
@@ -43,26 +55,36 @@
4355
</p>
4456
</div>
4557

46-
<Tooltip.Provider>
47-
<Tooltip.Root delayDuration={250}>
48-
<Tooltip.Trigger>
49-
<span
50-
class="mr-10 flex flex-row items-center rounded-md px-4 py-2 outline-1 outline-gray-500"
51-
>
52-
<Avatar.Root class="h-10 w-10">
53-
<Avatar.Image src={shareLinkRoot.author.image} alt="User Avatar" />
54-
<Avatar.Fallback>
55-
{shareLinkRoot.author.name.charAt(0)}
56-
</Avatar.Fallback>
57-
</Avatar.Root>
58-
<p class="ml-4">{shareLinkRoot.author.name}</p>
59-
</span>
60-
</Tooltip.Trigger>
61-
<Tooltip.Content>
62-
<p>Shared by</p>
63-
</Tooltip.Content>
64-
</Tooltip.Root>
65-
</Tooltip.Provider>
58+
<div class="items-center1 flex">
59+
<CopyInput value={shareUrl.href} displayValue={shareUrl.host + shareUrl.pathname} />
60+
</div>
61+
62+
<div class="flex items-center justify-end gap-4">
63+
{#if userState.self}
64+
<Button variant="outline" href={editUrl}><Pencil /> Edit</Button>
65+
{/if}
66+
67+
<Tooltip.Provider>
68+
<Tooltip.Root delayDuration={250}>
69+
<Tooltip.Trigger>
70+
<span
71+
class="mr-10 flex flex-row items-center rounded-md px-4 py-2 outline-1 outline-gray-500"
72+
>
73+
<Avatar.Root class="h-10 w-10">
74+
<Avatar.Image src={shareLinkRoot.author.image} alt="User Avatar" />
75+
<Avatar.Fallback>
76+
{shareLinkRoot.author.name.charAt(0)}
77+
</Avatar.Fallback>
78+
</Avatar.Root>
79+
<p class="ml-4">{shareLinkRoot.author.name}</p>
80+
</span>
81+
</Tooltip.Trigger>
82+
<Tooltip.Content>
83+
<p>Shared by</p>
84+
</Tooltip.Content>
85+
</Tooltip.Root>
86+
</Tooltip.Provider>
87+
</div>
6688
</div>
6789

6890
<div class="flex flex-row justify-center gap-5">

0 commit comments

Comments
 (0)