Live video on the AT Protocol
1import {
2 formatHandleWithAt,
3 Text,
4 useLivestream,
5 zero,
6} from "@streamplace/components";
7import { useLiveUser } from "hooks/useLiveUser";
8import { useEffect, useState } from "react";
9import { Pressable, ScrollView, TextInput, View } from "react-native";
10import { useStore } from "store";
11import { useNewLivestream, useUserProfile } from "store/hooks";
12
13export default function UpdateLivestream() {
14 const updateLivestreamRecord = useStore(
15 (state) => state.updateLivestreamRecord,
16 );
17
18 // Note: Toast functionality removed, would need simple alert replacement
19 const userIsLive = useLiveUser();
20 const [title, setTitle] = useState("");
21 const [loading, setLoading] = useState(false);
22 const profile = useUserProfile();
23 const livestream = useLivestream();
24 const newLivestream = useNewLivestream();
25
26 useEffect(() => {
27 if (newLivestream?.record) {
28 // Would show toast: "Livestream title updated" with newLivestream.record.title
29 setTitle("");
30 }
31 }, [newLivestream?.record]);
32
33 useEffect(() => {
34 if (newLivestream?.error) {
35 // Would show toast: "Error updating livestream" with error message
36 }
37 }, [newLivestream?.error]);
38
39 const disabled = !userIsLive || loading || title === "";
40
41 const handleSubmit = async () => {
42 setLoading(true);
43 try {
44 await updateLivestreamRecord(title, livestream);
45 } catch (error) {
46 console.error("Error updating livestream:", error);
47 // Would show toast: "Error updating livestream"
48 } finally {
49 setLoading(false);
50 }
51 };
52
53 const buttonText = loading
54 ? "Loading..."
55 : !userIsLive
56 ? "Waiting for stream to start..."
57 : "Update Livestream!";
58
59 return (
60 <ScrollView
61 style={{ width: "60%" }}
62 contentContainerStyle={{
63 flexGrow: 1,
64 justifyContent: "flex-start",
65 paddingVertical: 40,
66 }}
67 showsVerticalScrollIndicator={false}
68 >
69 <Text style={[{ fontSize: 20, fontWeight: "bold" }, zero.pl[4]]}>
70 Change your Current Livestream Title
71 </Text>
72 <View
73 style={[
74 { width: "100%" },
75 { alignSelf: "center" },
76 zero.p[4],
77 { justifyContent: "center" },
78 ]}
79 >
80 <View style={[{ flex: 2, minWidth: 0 }, { gap: 12 }]}>
81 <View
82 style={[
83 { flexDirection: "row" },
84 { alignItems: "center" },
85 { width: "100%" },
86 ]}
87 >
88 <Text
89 style={[{ paddingBottom: 8, minWidth: 100, textAlign: "left" }]}
90 >
91 Streamer
92 </Text>
93 <Text style={[{ paddingBottom: 8, fontWeight: "bold" }]}>
94 {profile && formatHandleWithAt(profile)}
95 </Text>
96 </View>
97
98 <View
99 style={[
100 { flexDirection: "row" },
101 { alignItems: "center" },
102 { width: "100%" },
103 ]}
104 >
105 <Text
106 style={[{ paddingBottom: 8, minWidth: 100, textAlign: "left" }]}
107 >
108 Title
109 </Text>
110 <View style={zero.flex.values[1]}>
111 <TextInput
112 value={title}
113 onChangeText={setTitle}
114 maxLength={140}
115 style={[
116 {
117 minHeight: 100,
118 width: "100%",
119 borderWidth: 1,
120 borderColor: "#ccc",
121 borderRadius: 8,
122 padding: 12,
123 textAlignVertical: "top",
124 },
125 ]}
126 multiline
127 />
128 </View>
129 </View>
130
131 <View
132 style={[
133 { flexDirection: "row" },
134 { alignItems: "center" },
135 { width: "100%", marginTop: -16 },
136 ]}
137 >
138 <Text style={[{ minWidth: 100, textAlign: "left" }]}></Text>
139 <View style={zero.flex.values[1]}>
140 <Text style={[{ fontSize: 12, color: "#666" }]}>
141 Updating will not send out notifications to viewers or create a
142 new social media post.
143 </Text>
144 </View>
145 </View>
146
147 <View
148 style={[
149 { width: "100%" },
150 { alignItems: "center" },
151 { marginTop: -16 },
152 ]}
153 >
154 <Pressable
155 disabled={disabled}
156 style={[
157 {
158 opacity: disabled ? 0.5 : 1,
159 width: "100%",
160 backgroundColor: "#0066cc",
161 padding: 16,
162 borderRadius: 8,
163 alignItems: "center",
164 },
165 ]}
166 onPress={handleSubmit}
167 >
168 <Text
169 style={{ color: "white", fontSize: 16, fontWeight: "bold" }}
170 >
171 {buttonText}
172 </Text>
173 </Pressable>
174 </View>
175 </View>
176 </View>
177 </ScrollView>
178 );
179}