Live video on the AT Protocol
1import { useNavigation } from "@react-navigation/native";
2import { storage, Text, useTheme, zero } from "@streamplace/components";
3import { Redirect } from "components/aqlink";
4import Loading from "components/loading/loading";
5import { useEffect, useState } from "react";
6import { KeyboardAvoidingView, Platform, ScrollView, View } from "react-native";
7import { useStore } from "store";
8import { useIsReady, useUserProfile } from "store/hooks";
9import { navigateToRoute } from "../../utils/navigation";
10import LoginForm from "./login-form";
11
12export default function Login() {
13 const { theme } = useTheme();
14 const closeLoginModal = useStore((state) => state.closeLoginModal);
15 const userProfile = useUserProfile();
16 const navigation = useNavigation();
17 const isReady = useIsReady();
18 const [localReturnRoute, setLocalReturnRoute] = useState<
19 | {
20 name: string;
21 params?: any;
22 }
23 | null
24 | undefined
25 >();
26
27 // check for stored return route on mount
28 useEffect(() => {
29 storage.getItem("returnRoute").then((stored) => {
30 if (stored) {
31 try {
32 const route = JSON.parse(stored);
33 console.log("Login page - found stored returnRoute:", route);
34 setLocalReturnRoute(route);
35 storage.removeItem("returnRoute");
36 closeLoginModal();
37 navigateToRoute(navigation, route);
38 } catch (e) {
39 console.error("Failed to parse returnRoute from storage", e);
40 setLocalReturnRoute(null);
41 }
42 } else {
43 setLocalReturnRoute(null);
44 }
45 });
46 }, [navigation, closeLoginModal]);
47
48 if (!isReady || localReturnRoute === undefined) {
49 return (
50 <View
51 style={[
52 zero.flex.values[1],
53 { justifyContent: "center", alignItems: "stretch" },
54 zero.gap.all[3],
55 ]}
56 >
57 <Loading />
58 </View>
59 );
60 }
61
62 if (userProfile) {
63 // if return route is set, go there
64 if (localReturnRoute) {
65 <Redirect
66 to={{ screen: localReturnRoute.name, params: localReturnRoute.params }}
67 />;
68 }
69 return (
70 <Redirect
71 to={{ screen: "Settings", params: { screen: "AccountCategory" } }}
72 />
73 );
74 }
75
76 return (
77 <KeyboardAvoidingView
78 style={{ flex: 1 }}
79 behavior={Platform.OS === "ios" ? "padding" : "height"}
80 >
81 <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
82 <View
83 style={[
84 zero.flex.values[1],
85 { justifyContent: "center", alignItems: "center" },
86 zero.p[4],
87 { width: "100%" },
88 { marginHorizontal: "auto" },
89 ]}
90 >
91 <View
92 style={[
93 zero.px[8],
94 zero.pt[10],
95 zero.pb[6],
96 zero.r.lg,
97 { backgroundColor: theme.colors.card },
98 { width: "100%" },
99 { maxWidth: 600 },
100 zero.gap.all[4],
101 ]}
102 >
103 <Text style={[{ fontSize: 36, fontWeight: "200", color: "white" }]}>
104 Log in
105 </Text>
106 <LoginForm />
107 </View>
108 </View>
109 </ScrollView>
110 </KeyboardAvoidingView>
111 );
112}