From 82909d6ddc4bf2b29c153af3f7573b5996b6a3e6 Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Wed, 1 Dec 2021 16:41:54 +0700 Subject: [PATCH 1/9] Feat: modify for comment component --- src/components/Forms/IconForm.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Forms/IconForm.tsx b/src/components/Forms/IconForm.tsx index eaa08ae..83348b9 100644 --- a/src/components/Forms/IconForm.tsx +++ b/src/components/Forms/IconForm.tsx @@ -16,6 +16,7 @@ type props = { password?: boolean; search?: boolean; errorMessage?: string; + comment?: boolean; onPress?: () => void; onEndEditing?: () => void; }; @@ -29,6 +30,7 @@ const IconForm = ({ iconType, password = false, search = false, + comment = false, errorMessage, onPress, onEndEditing, @@ -73,6 +75,8 @@ const IconForm = ({ let iconName: React.ComponentProps["name"]; if (search) { iconName = "search"; + } else if (comment) { + iconName = "send"; } else if (password) { if (showPass) { iconName = "visibility"; @@ -127,7 +131,7 @@ const IconForm = ({ onPress={() => password && setShowPass(!showPass)} testID="Touchable" > - {iconName === "search" && ( + {(comment || search) && ( onPress()}> )} - {iconName !== "search" && ( + {password && ( Date: Wed, 1 Dec 2021 17:50:29 +0700 Subject: [PATCH 2/9] Fix : fix the test for icon form --- src/components/Forms/IconForm.tsx | 2 +- src/components/__tests__/Forms/IconForm.test.tsx | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Forms/IconForm.tsx b/src/components/Forms/IconForm.tsx index 83348b9..83ddae4 100644 --- a/src/components/Forms/IconForm.tsx +++ b/src/components/Forms/IconForm.tsx @@ -141,7 +141,7 @@ const IconForm = ({ /> )} - {password && ( + {!(comment || search) && ( { const { getByTestId } = render(); expect(getByTestId("Touchable")).not.toBeNull(); }); - it("Should detect a MaterialIcon", () => { - const { getByTestId } = render(); + it("Should detect a MaterialIcon for password", () => { + const { getByTestId } = render(); + expect(getByTestId("MaterialIcon")).not.toBeNull(); + }); + it("Should detect a MaterialIcon for search or comment", () => { + const { getByTestId } = render(); expect(getByTestId("MaterialIcon")).not.toBeNull(); }); it("Should not detect a container title", () => { -- GitLab From 633f9cb1dacc49d0883b5f0f78e5e23dd7ab28d0 Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Thu, 2 Dec 2021 02:14:02 +0700 Subject: [PATCH 3/9] FIX: modify the iconform and other screen --- src/components/Forms/IconForm.tsx | 28 ++++++++----------- .../__tests__/Forms/IconForm.test.tsx | 16 +++++------ src/screens/auth/LoginScreen.tsx | 2 +- src/screens/auth/RegisterScreen.tsx | 2 +- .../ecosystem/CategoryEcosystemListScreen.tsx | 2 +- src/screens/ecosystem/EcosystemSearch.tsx | 2 +- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/components/Forms/IconForm.tsx b/src/components/Forms/IconForm.tsx index 83ddae4..cc078b0 100644 --- a/src/components/Forms/IconForm.tsx +++ b/src/components/Forms/IconForm.tsx @@ -13,10 +13,8 @@ type props = { placeholder: string; disabled?: boolean; iconType?: React.ComponentProps["name"]; - password?: boolean; - search?: boolean; errorMessage?: string; - comment?: boolean; + type?: "password" | "search" | "comment"; onPress?: () => void; onEndEditing?: () => void; }; @@ -28,15 +26,13 @@ const IconForm = ({ placeholder, disabled = false, iconType, - password = false, - search = false, - comment = false, + type, errorMessage, onPress, onEndEditing, }: props) => { const [isFocused, setIsFocused] = useState(false); - const [showPass, setShowPass] = useState(password); + const [showPass, setShowPass] = useState(true); const [isError, setIsError] = useState(false); let backgroundColor: string; @@ -60,7 +56,7 @@ const IconForm = ({ const endEdit = () => { setIsFocused(false); - if (search || disabled) { + if (type === "search" || disabled) { setIsError(false); } else { if (!validateEmpty(text)) { @@ -73,11 +69,11 @@ const IconForm = ({ }; let iconName: React.ComponentProps["name"]; - if (search) { + if (type === "search") { iconName = "search"; - } else if (comment) { + } else if (type === "comment") { iconName = "send"; - } else if (password) { + } else if (type === "password") { if (showPass) { iconName = "visibility"; } else if (!showPass) { @@ -124,15 +120,15 @@ const IconForm = ({ editable={!disabled} secureTextEntry={showPass} testID="Input" - autoCapitalize={password ? "none" : "sentences"} + autoCapitalize={type === "password" ? "none" : "sentences"} /> password && setShowPass(!showPass)} + onPress={() => type === "password" && setShowPass(!showPass)} testID="Touchable" > - {(comment || search) && ( - onPress()}> + {(type === "comment" || type === "search") && ( + onPress()}> )} - {!(comment || search) && ( + {!(type === "comment" || type === "search") && ( { expect(getByTestId("Touchable")).not.toBeNull(); }); it("Should detect a MaterialIcon for password", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId("MaterialIcon")).not.toBeNull(); }); it("Should detect a MaterialIcon for search or comment", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId("MaterialIcon")).not.toBeNull(); }); it("Should not detect a container title", () => { @@ -62,24 +62,24 @@ describe("Icon Form Test", () => { expect(getByTestId("Input").props.value).toEqual("Hello"); }); it("Should detect a password form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId("Icon")).not.toBeNull(); }); it("Should detect a search form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId("Icon")).not.toBeNull(); }); it("Should detect a disabled form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); expect(getByTestId("Icon")).not.toBeNull(); }); it("Should detect a visible password form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); fireEvent(getByTestId("Touchable"), "onPress"); expect(getByTestId("Icon")).not.toBeNull(); }); it("Should not detect a visible password form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); fireEvent(getByTestId("Touchable"), "onPress"); fireEvent(getByTestId("Touchable"), "onPress"); expect(getByTestId("Icon")).not.toBeNull(); @@ -107,7 +107,7 @@ describe("Icon Form Test", () => { expect(getByTestId("Icon")).not.toBeNull(); }); it("Should not detect an error on a search form", () => { - const { getByTestId } = render(); + const { getByTestId } = render(); fireEvent(getByTestId("Input"), "onEndEditing"); expect(getByTestId("Icon")).not.toBeNull(); }); diff --git a/src/screens/auth/LoginScreen.tsx b/src/screens/auth/LoginScreen.tsx index 2a7e0a8..f1463a6 100644 --- a/src/screens/auth/LoginScreen.tsx +++ b/src/screens/auth/LoginScreen.tsx @@ -55,7 +55,7 @@ const LoginScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { text={password} setText={setPassword} placeholder={"Masukkan Password"} - password + type="password" errorMessage={"Silahkan masukkan password"} /> diff --git a/src/screens/auth/RegisterScreen.tsx b/src/screens/auth/RegisterScreen.tsx index 0226cc1..1d6a4d4 100644 --- a/src/screens/auth/RegisterScreen.tsx +++ b/src/screens/auth/RegisterScreen.tsx @@ -119,7 +119,7 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { text={password} setText={setPassword} placeholder={"Masukkan Password"} - password + type="password" errorMessage={"Tolong masukkan password"} /> diff --git a/src/screens/ecosystem/CategoryEcosystemListScreen.tsx b/src/screens/ecosystem/CategoryEcosystemListScreen.tsx index 9342573..ab44725 100644 --- a/src/screens/ecosystem/CategoryEcosystemListScreen.tsx +++ b/src/screens/ecosystem/CategoryEcosystemListScreen.tsx @@ -80,7 +80,7 @@ const CategoryEcosystemListScreen = ({ text={search} setText={setSearch} placeholder={"Cari di kategori ini"} - search + type="search" onPress={onSearch} onEndEditing={onSearch} /> diff --git a/src/screens/ecosystem/EcosystemSearch.tsx b/src/screens/ecosystem/EcosystemSearch.tsx index 112bb57..8fb00c2 100644 --- a/src/screens/ecosystem/EcosystemSearch.tsx +++ b/src/screens/ecosystem/EcosystemSearch.tsx @@ -123,7 +123,7 @@ const EcosystemSearch = ({ route }: EcosystemStackScreenProps<"Search">) => { text={search} setText={setSearch} placeholder={"Cari dengan kata kunci ini.."} - search + type="search" onPress={onSearch} onEndEditing={onSearch} /> -- GitLab From df5282dc03434d8e5b3e13b499ae78519f41548e Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Fri, 3 Dec 2021 23:31:14 +0700 Subject: [PATCH 4/9] Fix: icon form condition --- src/components/Forms/IconForm.tsx | 38 +++++++++---------- .../__tests__/Forms/IconForm.test.tsx | 17 +++++---- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/components/Forms/IconForm.tsx b/src/components/Forms/IconForm.tsx index cc078b0..3f0c025 100644 --- a/src/components/Forms/IconForm.tsx +++ b/src/components/Forms/IconForm.tsx @@ -32,7 +32,7 @@ const IconForm = ({ onEndEditing, }: props) => { const [isFocused, setIsFocused] = useState(false); - const [showPass, setShowPass] = useState(true); + const [showPass, setShowPass] = useState(type === "password" ? true : false); const [isError, setIsError] = useState(false); let backgroundColor: string; @@ -56,7 +56,7 @@ const IconForm = ({ const endEdit = () => { setIsFocused(false); - if (type === "search" || disabled) { + if (type === "search" || disabled || type === "comment") { setIsError(false); } else { if (!validateEmpty(text)) { @@ -123,29 +123,29 @@ const IconForm = ({ autoCapitalize={type === "password" ? "none" : "sentences"} /> - type === "password" && setShowPass(!showPass)} - testID="Touchable" - > - {(type === "comment" || type === "search") && ( - onPress()}> - - - )} - {!(type === "comment" || type === "search") && ( + {type === "password" && ( + type === "password" && setShowPass(!showPass)} + testID="Touchable" + > - )} - + + )} + {(type === "comment" || type === "search") && ( + onPress()}> + + + )} {isError && ( diff --git a/src/components/__tests__/Forms/IconForm.test.tsx b/src/components/__tests__/Forms/IconForm.test.tsx index 223f3d6..582c37e 100644 --- a/src/components/__tests__/Forms/IconForm.test.tsx +++ b/src/components/__tests__/Forms/IconForm.test.tsx @@ -36,18 +36,21 @@ describe("Icon Form Test", () => { const { getByTestId } = render(); expect(getByTestId("Input")).not.toBeNull(); }); - it("Should detect a touchable", () => { - const { getByTestId } = render(); - expect(getByTestId("Touchable")).not.toBeNull(); - }); - it("Should detect a MaterialIcon for password", () => { + it("Should detect a touchable for password", () => { const { getByTestId } = render(); - expect(getByTestId("MaterialIcon")).not.toBeNull(); + expect(getByTestId("Touchable")).not.toBeNull(); }); - it("Should detect a MaterialIcon for search or comment", () => { + it("Should detect a touchable icon for comment", () => { const { getByTestId } = render(); expect(getByTestId("MaterialIcon")).not.toBeNull(); }); + it("Should detect an onPress function", () => { + const { getByTestId } = render( + {}} /> + ); + fireEvent(getByTestId("TouchableIcon"), "onPress"); + expect(getByTestId("TouchableIcon")).not.toBeNull(); + }); it("Should not detect a container title", () => { const { queryByTestId } = render(); expect(queryByTestId("TitleContainer")).toBeNull(); -- GitLab From 5fa7a5c1a7e1a5f8fbd3b7032f41709ea8b8283d Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Sat, 4 Dec 2021 16:52:28 +0700 Subject: [PATCH 5/9] FEAT: add comment function --- src/service/firestore/ecosystem/addComment.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/service/firestore/ecosystem/addComment.ts diff --git a/src/service/firestore/ecosystem/addComment.ts b/src/service/firestore/ecosystem/addComment.ts new file mode 100644 index 0000000..752ab64 --- /dev/null +++ b/src/service/firestore/ecosystem/addComment.ts @@ -0,0 +1,15 @@ +import firebase from "firebase"; +import { getEnv } from "../../../helpers/getEnv"; +export const addComments = async ( + threadId: string, + comment: string, + userId: string +) => { + const db = firebase.firestore(); + return await db.collection("threads_comments_" + getEnv()).add({ + threadId: threadId, + timestamp: firebase.firestore.Timestamp.now(), + content: comment, + userId: userId, + }); +}; -- GitLab From 7799222a803ef7bb5a793d9cd775271005de0159 Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Sat, 4 Dec 2021 17:24:28 +0700 Subject: [PATCH 6/9] FIX: modify the timestamp --- src/service/firestore/ecosystem/addComment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/firestore/ecosystem/addComment.ts b/src/service/firestore/ecosystem/addComment.ts index 752ab64..dc4997a 100644 --- a/src/service/firestore/ecosystem/addComment.ts +++ b/src/service/firestore/ecosystem/addComment.ts @@ -8,7 +8,7 @@ export const addComments = async ( const db = firebase.firestore(); return await db.collection("threads_comments_" + getEnv()).add({ threadId: threadId, - timestamp: firebase.firestore.Timestamp.now(), + timestamp: firebase.firestore.FieldValue.serverTimestamp(), content: comment, userId: userId, }); -- GitLab From 7d0b1352df6936f69500c271f98c9f61e240be4e Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Sun, 5 Dec 2021 20:01:56 +0700 Subject: [PATCH 7/9] Fead : Integrate Delete Forum Function --- src/components/ForumPost/ForumPost.tsx | 42 +++++++++++++++++-- .../ecosystem/EcosystemDetailScreen.tsx | 2 +- src/service/firestore/thread/deleteThread.ts | 12 ++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/service/firestore/thread/deleteThread.ts diff --git a/src/components/ForumPost/ForumPost.tsx b/src/components/ForumPost/ForumPost.tsx index 61db167..5d0ce2a 100644 --- a/src/components/ForumPost/ForumPost.tsx +++ b/src/components/ForumPost/ForumPost.tsx @@ -1,7 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { MaterialIcons } from "@expo/vector-icons"; import React from "react"; -import { Text, StyleSheet, TouchableOpacity, View, Image } from "react-native"; +import { + Text, + StyleSheet, + TouchableOpacity, + View, + Image, + Alert, +} from "react-native"; import Colors from "../../constants/Colors"; import Spacer from "../../components/Spacer/Spacer"; import Layout from "../../constants/Layout"; @@ -13,14 +20,17 @@ import { IUser } from "../../types/firestore/User"; import { likeThread, unlikeThread } from "../../service/firestore/thread/like"; import { useUser } from "../../hooks/reduxHooks"; import { checkIsLiked } from "../../service/firestore/thread/checkIsLiked"; +import { deleteThread } from "../../service/firestore/thread/deleteThread"; +import { getEcosystem } from "../../service/firestore/ecosystem/getEcosystem"; type props = { item: IThread; onLike?: () => void; onUnLike?: () => void; + fromScreen?: string; }; -const ForumPost = ({ item }: props) => { +const ForumPost = ({ item, fromScreen }: props) => { const nav = useNavigation(); const user = useUser(); const [userName, setUserName] = useState(""); @@ -37,7 +47,21 @@ const ForumPost = ({ item }: props) => { }); checkIsLiked(item.id, user.id).then((res) => setIslike(res)); }, []); - + const alertDelete = () => { + Alert.alert("Hapus Forum", "Apakah anda yakin ingin menghapus Forum", [ + { + text: "Hapus", + style: "destructive", + onPress: handleDelete, + }, + { text: "Cancel", style: "cancel" }, + ]); + }; + const handleDelete = async () => { + await deleteThread(item.id); + Alert.alert("Hapus Forum", "Forum berhasil dihapus", [{ text: "OK" }]); + nav.goBack(); + }; const formatDate = () => { const date = item.timestamp.toDate(); const day = date.getDate(); @@ -45,7 +69,6 @@ const ForumPost = ({ item }: props) => { const year = date.getFullYear(); return `${day} - ${month} - ${year}`; }; - return ( @@ -139,6 +162,17 @@ const ForumPost = ({ item }: props) => { {likeQty} + {item.userId === user.id && fromScreen !== "EcosystemDetails" && ( + + + + + + )} diff --git a/src/screens/ecosystem/EcosystemDetailScreen.tsx b/src/screens/ecosystem/EcosystemDetailScreen.tsx index a539671..8eb6aa9 100644 --- a/src/screens/ecosystem/EcosystemDetailScreen.tsx +++ b/src/screens/ecosystem/EcosystemDetailScreen.tsx @@ -97,7 +97,7 @@ const EcosystemDetailScreen = ({ renderItem={({ item }) => { return ( - + ); }} diff --git a/src/service/firestore/thread/deleteThread.ts b/src/service/firestore/thread/deleteThread.ts new file mode 100644 index 0000000..e64423e --- /dev/null +++ b/src/service/firestore/thread/deleteThread.ts @@ -0,0 +1,12 @@ +import firebase from "firebase"; +import { getEnv } from "../../../helpers/getEnv"; + +export const deleteThread = async (threadId: string): Promise => { + try { + const db = firebase.firestore(); + await db.collection(`threads_${getEnv()}`).doc(threadId).delete(); + return true; + } catch (e) { + return false; + } +}; -- GitLab From b64bbd3123d6480f202a5e5b69de31904b46a1b0 Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Sun, 5 Dec 2021 21:02:05 +0700 Subject: [PATCH 8/9] fix: filter by category --- src/screens/ecosystem/EcosystemSearch.tsx | 24 +++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/screens/ecosystem/EcosystemSearch.tsx b/src/screens/ecosystem/EcosystemSearch.tsx index 4d84f2b..2235ed2 100644 --- a/src/screens/ecosystem/EcosystemSearch.tsx +++ b/src/screens/ecosystem/EcosystemSearch.tsx @@ -36,16 +36,23 @@ const EcosystemSearch = ({ route }: EcosystemStackScreenProps<"Search">) => { // const [loadingMore, setLoadingmore] = useState(false); const nav = useNavigation(); const categoriesHook = useCategory(); + // setCategories(categoriesHook); useEffect(() => { setCategories(() => getCategoriesAsDdFormat(categoriesHook)); + // // console.log(categoriesHook); + // console.log(categories); }, []); - // const filterByCategory = async () => { - // if (ecosystems.length > 0) { - // ecosystems.length = 0; - // } - // const result = await getByCategory(picked); - // setEcosystems(result); - // }; + const filterByCategory = async () => { + setIsSearchLoading(true); + const res = await searchEcosystem({ + q: search, + query_by: "categoryId", + filter_by: "categoryId:=" + picked, + }); + console.log(res.searchHits[0]); + setEcosystems(res.searchHits); + setIsSearchLoading(false); + }; // const handleOnEndReach = () => { // // setLoadingmore(true); // const lastIndexItem = ecosystems[ecosystems.length - 1]; @@ -156,7 +163,8 @@ const EcosystemSearch = ({ route }: EcosystemStackScreenProps<"Search">) => { text="Filter" colors="primary" onPress={() => { - // filterByCategory(); + ecosystems.length = 0; + filterByCategory(); }} /> -- GitLab From a83517e8f399c783e2fad02b723f00e21e61e8bc Mon Sep 17 00:00:00 2001 From: angelindepthios Date: Sun, 5 Dec 2021 21:27:26 +0700 Subject: [PATCH 9/9] delete --- .vscode/settings.json | 2 ++ src/service/firestore/ecosystem/addComment.ts | 15 --------------- 2 files changed, 2 insertions(+), 15 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 src/service/firestore/ecosystem/addComment.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} diff --git a/src/service/firestore/ecosystem/addComment.ts b/src/service/firestore/ecosystem/addComment.ts deleted file mode 100644 index dc4997a..0000000 --- a/src/service/firestore/ecosystem/addComment.ts +++ /dev/null @@ -1,15 +0,0 @@ -import firebase from "firebase"; -import { getEnv } from "../../../helpers/getEnv"; -export const addComments = async ( - threadId: string, - comment: string, - userId: string -) => { - const db = firebase.firestore(); - return await db.collection("threads_comments_" + getEnv()).add({ - threadId: threadId, - timestamp: firebase.firestore.FieldValue.serverTimestamp(), - content: comment, - userId: userId, - }); -}; -- GitLab