-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shares.tsx
86 lines (80 loc) · 2.25 KB
/
Shares.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {useEffect, useState} from 'react';
import {type PresentationAndId} from '../../functions/src/presentation';
import RoundButton from './toolbar/RoundButton';
export default function Shares({
presentation,
slideIndex,
}: {
readonly presentation: PresentationAndId;
readonly slideIndex: number;
}) {
// TODO: should this parse window.location for the host?
const shareUrl = `https://slidr.app/v/${presentation?.id ?? ''}?slide=${
slideIndex + 1
}`;
const tweetText =
presentation.data === undefined
? ''
: `${
presentation.data.title.length > 0
? presentation?.data.title
: 'presentation'
}${
presentation.data.username.length > 0
? ' by ' + presentation.data.username
: ''
}${
presentation.data.twitterHandle.length > 0
? ' ' + presentation.data.twitterHandle
: ''
} ${shareUrl}`;
const [copied, setCopied] = useState(false);
useEffect(() => {
if (!copied) {
return;
}
let handle: NodeJS.Timeout | undefined;
handle = setTimeout(() => {
handle = undefined;
setCopied(false);
}, 2000);
return () => {
if (handle !== undefined) {
clearTimeout(handle);
}
};
}, [copied]);
return (
<div className="flex flex-row justify-center gap-4 relative flex-wrap">
<RoundButton
newTab
to={`https://twitter.com/intent/tweet?text=${encodeURIComponent(
tweetText,
)}`}
icon="i-tabler-brand-twitter w-[2rem] h-[2rem]"
label="tweet"
title="Tweet this slide"
/>
<RoundButton
newTab
to={`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(
shareUrl,
)}`}
icon="i-tabler-brand-linkedin w-[2rem] h-[2rem]"
label="post"
title="Post slide to LinkedIn"
/>
<RoundButton
to={shareUrl}
icon="i-tabler-link w-[2rem] h-[2rem]"
label={copied ? 'copied!' : 'copy'}
title="Copy link to slide"
onClick={(event) => {
event.preventDefault();
void window.navigator.clipboard.writeText(shareUrl);
setCopied(true);
}}
/>
</div>
);
}