Skip to content

Commit 2747f07

Browse files
[Add] comment section feature (#14)
youtube video tutorial: https://www.youtube.com/watch?v=Tcc7hL6xAzs&ab_channel=SimCoder
1 parent 251d3c0 commit 2747f07

File tree

19 files changed

+438
-110
lines changed

19 files changed

+438
-110
lines changed

backend/functions/index.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@ exports.newUser = functions.auth.user().onCreate((user) => {
1313
})
1414

1515

16-
exports.likeCreate = functions.firestore.document('post/{id}/likes/{uid}').onCreate((_, context) => {
16+
exports.likeCreate = functions.firestore.document('post/{id}/{type}/{uid}').onCreate((_, context) => {
17+
let updateObj = {}
18+
if (context.params.type == 'comments') {
19+
updateObj = {
20+
commentsCount: admin.firestore.FieldValue.increment(1)
21+
}
22+
}
23+
if (context.params.type == 'likes') {
24+
updateObj = {
25+
likesCount: admin.firestore.FieldValue.increment(1)
26+
}
27+
}
1728
return db
1829
.collection("post")
1930
.doc(context.params.id)
20-
.update({
21-
likesCount: admin.firestore.FieldValue.increment(1)
22-
})
31+
.update(updateObj)
2332
})
2433

25-
exports.likeDelete = functions.firestore.document('post/{id}/likes/{uid}').onDelete((_, context) => {
34+
exports.likeDelete = functions.firestore.document('post/{id}/{type}/{uid}').onDelete((_, context) => {
35+
let updateObj = {}
36+
if (context.params.type == 'comments') {
37+
updateObj = {
38+
commentsCount: admin.firestore.FieldValue.increment(-1)
39+
}
40+
}
41+
if (context.params.type == 'likes') {
42+
updateObj = {
43+
likesCount: admin.firestore.FieldValue.increment(-1)
44+
}
45+
}
2646
return db
2747
.collection("post")
2848
.doc(context.params.id)
29-
.update({
30-
likesCount: admin.firestore.FieldValue.increment(-1)
31-
})
49+
.update(updateObj)
3250
})

frontend/babel.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module.exports = function(api) {
1+
module.exports = function (api) {
22
api.cache(true);
33
return {
44
presets: ['babel-preset-expo'],
5+
plugins: [['react-native-reanimated/plugin']],
56
};
67
};

0 commit comments

Comments
 (0)