diff --git a/src/pages/community/CommunityPage.jsx b/src/pages/community/CommunityPage.jsx
index d9ef4b6..3021e22 100644
--- a/src/pages/community/CommunityPage.jsx
+++ b/src/pages/community/CommunityPage.jsx
@@ -13,7 +13,6 @@ import {
import { useNavigation, useFocusEffect } from "@react-navigation/native";
import { useTranslation } from "react-i18next";
import * as Sentry from "@sentry/react-native";
-
import CommunityStyles from "@pages/community/CommunityStyles";
import { getPostsByType, getCommunitySearch } from "config/api";
@@ -21,11 +20,10 @@ import ConnectTop from "@components/connect/ConnectTop";
import ConnectSearchIcon from "@components/connect/ConnectSearchIcon";
import ConnectSearchCancel from "@components/connect/ConnectSearchCancel";
import IconBookmark from "@components/chat/IconBookmark";
-import IconCommunityTitle from "@components/community/IconCommunityTitle";
import ArrowRight from "@components/common/ArrowRight";
-import ItemCommunityPreview from "@components/community/ItemCommunityPreview";
import IconSearchFail from "@components/common/IconSearchFail";
import ItemCommunity from "@components/community/ItemCommunity";
+import CommunitySection from "./CommunitySection";
const CommunityPage = () => {
const { t } = useTranslation();
@@ -74,10 +72,12 @@ const CommunityPage = () => {
useFocusEffect(
useCallback(() => {
- const community = async () => {
+ const fetchPosts = async () => {
try {
- const responseTip = await getPostsByType("TIP");
- const responseFree = await getPostsByType("FREE");
+ const [responseTip, responseFree] = await Promise.all([
+ getPostsByType("TIP"),
+ getPostsByType("FREE"),
+ ]);
setTipPostList(responseTip.data.slice(0, 3));
setFreePostList(responseFree.data.slice(0, 3));
} catch (error) {
@@ -89,81 +89,48 @@ const CommunityPage = () => {
}
};
- community();
+ fetchPosts();
}, []),
);
const { height: screenHeight } = Dimensions.get("window");
const isSmallScreen = screenHeight < 700;
- const renderCommunity = () => (
- <>
- {searchFail ? (
+ const renderCommunity = () => {
+ if (searchFail) {
+ return (
{t("searchNoResults")}
- ) : searchData && searchData.length > 0 ? (
+ );
+ }
+
+ if (searchData && searchData.length > 0) {
+ return (
- ) : (
- <>
-
-
-
-
- {t("tipBoard")}
-
-
-
- navigation.navigate("TipCommunityPage")
- }
- >
-
- {t("moreButton")}
-
-
-
-
-
-
-
+ );
+ }
-
-
-
-
- {t("freeBoard")}
-
-
-
- navigation.navigate("FreeCommunityPage")
- }
- >
-
- {t("moreButton")}
-
-
-
-
-
-
-
- >
- )}
- >
- );
+ return (
+ <>
+ navigation.navigate("TipCommunityPage")}
+ />
+ navigation.navigate("FreeCommunityPage")}
+ />
+ >
+ );
+ };
return (
Keyboard.dismiss()}>
diff --git a/src/pages/community/CommunitySection.jsx b/src/pages/community/CommunitySection.jsx
new file mode 100644
index 0000000..a7a2824
--- /dev/null
+++ b/src/pages/community/CommunitySection.jsx
@@ -0,0 +1,37 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import CommunityStyles from "@pages/community/CommunityStyles";
+import IconCommunityTitle from "@components/community/IconCommunityTitle";
+import ItemCommunityPreview from "@components/community/ItemCommunityPreview";
+import { View, Text, TouchableOpacity } from "react-native";
+import ArrowRight from "@components/common/ArrowRight";
+
+const CommunitySection = ({ title, postList, onMorePress }) => {
+ const { t } = useTranslation();
+ return (
+
+
+
+
+
+ {t(title)}
+
+
+
+
+ {t("moreButton")}
+
+
+
+
+
+
+
+
+ );
+};
+
+export default CommunitySection;