Skip to content

Commit 272921a

Browse files
committed
Fix User linking
Former-commit-id: 8f0329b Former-commit-id: 5833c72
1 parent 3a1bca5 commit 272921a

File tree

2 files changed

+139
-30
lines changed

2 files changed

+139
-30
lines changed

App.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export default function App() {
3030
item: (item) => item.id,
3131
},
3232
},
33-
},
34-
User: {
35-
path: "user/:id",
36-
parse: {
37-
id: (id) => Number(id),
38-
},
33+
// User: {
34+
// path: "user/:uid",
35+
// parse: {
36+
// uid: (uid) => uid,
37+
// },
38+
// },
3939
},
4040
},
4141
}}
@@ -47,6 +47,7 @@ export default function App() {
4747
<Stack.Screen name="ResetPassword" component={ResetPassword} />
4848
<Stack.Screen name="Home" component={Home} />
4949
<Stack.Screen name="Detail" component={Detail} />
50+
{/* <Stack.Screen name="User" component={User} /> */}
5051
</Stack.Navigator>
5152
</NavigationContainer>
5253
</ActionSheetProvider>

screens/Partner.js

Lines changed: 132 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,151 @@
1+
import { Ionicons } from "@expo/vector-icons";
2+
import to from "await-to-js";
13
import * as Clipboard from "expo-clipboard";
2-
import React from "react";
3-
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
4+
import {
5+
onSnapshot,
6+
doc,
7+
collection,
8+
query,
9+
orderBy,
10+
} from "firebase/firestore";
11+
import React, { useState, useEffect } from "react";
12+
import {
13+
View,
14+
Text,
15+
StyleSheet,
16+
TouchableOpacity,
17+
FlatList,
18+
Pressable,
19+
} from "react-native";
420

5-
import { auth } from "../config";
21+
import { auth, db } from "../config";
622

723
const WEB_API_KEY = "AIzaSyCJ2FY69u3jR8WMVLCT_TDrkKyqkUE2Y3k";
824

925
const copyInvitationUrl = async () => {
10-
try {
11-
const payload = {
12-
dynamicLinkInfo: {
13-
domainUriPrefix: "https://dogether.page.link",
14-
link: `https://dogether-78b6f.web.app/user/${auth.currentUser.uid}`,
15-
androidInfo: {
16-
androidPackageName: "gg.dogether.app",
17-
},
18-
socialMetaTagInfo: {
19-
socialTitle: `New invite from ${auth.currentUser.displayName}`,
20-
socialDescription: `${auth.currentUser.displayName} is using Dogether to stay accountable and motivated. Join them on their journey!`,
21-
// socialImageLink: "<image-url>",
22-
},
26+
const payload = {
27+
dynamicLinkInfo: {
28+
domainUriPrefix: "https://dogether.page.link",
29+
link: `https://dogether-78b6f.web.app/user/${auth.currentUser.uid}`,
30+
androidInfo: {
31+
androidPackageName: "gg.dogether.app",
2332
},
24-
};
33+
socialMetaTagInfo: {
34+
socialTitle: `New invite from ${auth.currentUser.displayName}`,
35+
socialDescription: `${auth.currentUser.displayName} is using Dogether to stay accountable and motivated. Join them on their journey!`,
36+
// socialImageLink: "<image-url>",
37+
},
38+
},
39+
};
2540

26-
const url = `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${WEB_API_KEY}`;
27-
const response = await fetch(url, {
41+
const url = `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${WEB_API_KEY}`;
42+
const [error, response] = await to(
43+
fetch(url, {
2844
method: "POST",
2945
headers: {
3046
"Content-Type": "application/json",
3147
},
3248
body: JSON.stringify(payload),
33-
});
34-
const json = await response.json();
35-
await Clipboard.setStringAsync(json.shortLink);
36-
alert("Copied to Clipboard!");
37-
} catch (error) {
49+
})
50+
);
51+
if (error) {
3852
alert(error.message);
53+
return;
3954
}
55+
const json = await response.json();
56+
await Clipboard.setStringAsync(json.shortLink);
57+
alert("Copied to Clipboard!");
4058
};
59+
4160
const Partner = () => {
61+
const [hasPartner, setHasPartner] = useState(false);
62+
const [todos, setTodos] = useState([]);
63+
64+
useEffect(() => {
65+
const unsubHasPartner = onSnapshot(
66+
doc(db, `users/${auth.currentUser.uid}`),
67+
(doc) => {
68+
const { partner } = doc.data();
69+
setHasPartner(!!partner);
70+
},
71+
(error) => {
72+
console.log(error);
73+
}
74+
);
75+
76+
const unsubPartnerTodos = onSnapshot(
77+
query(
78+
collection(db, `users/${auth.currentUser.uid}/todos`),
79+
orderBy("createdAt", "desc")
80+
),
81+
(querySnapshot) => {
82+
const todos = [];
83+
querySnapshot.forEach((doc) => {
84+
const { title, status } = doc.data();
85+
todos.push({
86+
id: doc.id,
87+
title,
88+
status,
89+
});
90+
});
91+
setTodos(todos);
92+
console.log("todos: ", todos, "todos.length: ", todos.length);
93+
},
94+
(error) => {
95+
console.log(error);
96+
}
97+
);
98+
99+
return () => {
100+
unsubHasPartner();
101+
unsubPartnerTodos();
102+
};
103+
}, []);
104+
105+
const showImage = (item) => {
106+
alert("Show image");
107+
};
108+
109+
if (hasPartner) {
110+
return (
111+
<View style={{ flex: 1 }}>
112+
<FlatList
113+
data={todos}
114+
numColumns={1}
115+
keyExtractor={(item) => item.id}
116+
renderItem={({ item }) => (
117+
<View style={styles.container}>
118+
<Ionicons
119+
name={
120+
{
121+
unfinished: "md-square-outline",
122+
finished: "md-alert-circle-outline",
123+
verified: "md-checkmark-circle-outline",
124+
}[item.status]
125+
}
126+
size={24}
127+
color="black"
128+
style={styles.todoIcon}
129+
/>
130+
<Pressable
131+
style={styles.innerContainer}
132+
onPress={() => {
133+
if (item.status === "finished") {
134+
showImage(item);
135+
}
136+
}}
137+
>
138+
<Text style={styles.itemHeading}>
139+
{item.title.charAt(0).toUpperCase() + item.title.slice(1)}
140+
</Text>
141+
</Pressable>
142+
</View>
143+
)}
144+
/>
145+
</View>
146+
);
147+
}
148+
42149
return (
43150
<View style={styles.container}>
44151
<Text style={styles.message}>Oops! You don't have a partner yet!</Text>
@@ -50,6 +157,7 @@ const Partner = () => {
50157
};
51158

52159
export default Partner;
160+
53161
const styles = StyleSheet.create({
54162
message: {
55163
fontWeight: "bold",

0 commit comments

Comments
 (0)