Repository navigation
Expand file tree
/
Copy pathprofile-live-button.tsx
More file actions
59 lines (56 loc) · 1.88 KB
/
Copy pathprofile-live-button.tsx
File metadata and controls
59 lines (56 loc) · 1.88 KB
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
import { Radio, RadioOff } from 'lucide-react';
import { useState } from 'react';
import { endStream, GoLiveDialog } from '@/components/go-live-dialog';
import { Button } from '@/components/ui/button';
import { useLiveStream } from '@/hooks/use-live-stream';
import type { User } from '@/types';
/**
* Going live, or ending the stream, from your own profile, where other people's profiles have the mute and block menu.
*/
export function ProfileLiveButton({
user,
}: {
user: Pick<User, 'id' | 'live'>;
}) {
const [isGoingLive, setIsGoingLive] = useState(false);
const stream = useLiveStream(user);
const [isEnding, setIsEnding] = useState(false);
return (
<>
{stream ? (
<Button
type="button"
variant="outline"
size="icon"
className="shrink-0"
disabled={isEnding}
onClick={() =>
endStream({
onStart: () => setIsEnding(true),
onFinish: () => setIsEnding(false),
})
}
aria-label="End stream"
title="End stream"
data-test="end-stream"
>
<RadioOff />
</Button>
) : (
<Button
type="button"
variant="outline"
size="icon"
className="shrink-0"
onClick={() => setIsGoingLive(true)}
aria-label="Go live"
title="Go live"
data-test="go-live"
>
<Radio />
</Button>
)}
<GoLiveDialog open={isGoingLive} onOpenChange={setIsGoingLive} />
</>
);
}