MCPcopy Create free account
hub / github.com/VadimNotJustDev/SignalClone / App

Function App

App.tsx:32–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30console.log(obj, encrypted, decrypted);
31
32function App() {
33 const isLoadingComplete = useCachedResources();
34 const colorScheme = useColorScheme();
35
36 const [user, setUser] = useState<User | null>(null);
37
38 useEffect(() => {
39 const listener = Hub.listen("datastore", async (hubData) => {
40 const { event, data } = hubData.payload;
41 if (
42 event === "outboxMutationProcessed" &&
43 data.model === Message &&
44 !["DELIVERED", "READ"].includes(data.element.status)
45 ) {
46 // set the message status to delivered
47 DataStore.save(
48 Message.copyOf(data.element, (updated) => {
49 updated.status = "DELIVERED";
50 })
51 );
52 }
53 });
54
55 // Remove listener
56 return () => listener();
57 }, []);
58
59 useEffect(() => {
60 if (!user) {
61 return;
62 }
63
64 const subscription = DataStore.observe(User, user.id).subscribe((msg) => {
65 if (msg.model === User && msg.opType === "UPDATE") {
66 setUser(msg.element);
67 }
68 });
69
70 return () => subscription.unsubscribe();
71 }, [user?.id]);
72
73 useEffect(() => {
74 fetchUser();
75 }, []);
76
77 useEffect(() => {
78 const interval = setInterval(async () => {
79 await updateLastOnline();
80 }, 1 * 60 * 1000);
81 return () => clearInterval(interval);
82 }, [user]);
83
84 const fetchUser = async () => {
85 const userData = await Auth.currentAuthenticatedUser();
86 const user = await DataStore.query(User, userData.attributes.sub);
87 if (user) {
88 setUser(user);
89 }

Callers

nothing calls this directly

Calls 4

useCachedResourcesFunction · 0.85
useColorSchemeFunction · 0.85
fetchUserFunction · 0.85
updateLastOnlineFunction · 0.85

Tested by

no test coverage detected