Skip to content

Commit

Permalink
Merge pull request #51 from mooco-renew/feat/#50
Browse files Browse the repository at this point in the history
fix: Error Page Space & Comment Delete
  • Loading branch information
zoeyourlife authored May 7, 2024
2 parents a357ecd + 0f44c4c commit 14de6cd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
10 changes: 8 additions & 2 deletions src/components/profiletab/DailyBarcodeTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export default function DailyBarcodeTab({ profileData }) {
const [hasMore, setHasMore] = useState(true);
const [refreshing, setRefreshing] = useState(false);

const onServerError = () => {
navigation.reset({
index: 0,
routes: [{ name: "ServerError" }],
});
};

useEffect(() => {
fetchData();
}, []);
Expand All @@ -45,8 +52,7 @@ export default function DailyBarcodeTab({ profileData }) {
console.log("더 이상 데이터가 없습니다.");
}
} catch (error) {
console.error("API 호출 에러", error);
Alert.alert("API 호출 에러", "데이터를 불러오는 중 문제가 발생했습니다.");
onServerError();
} finally {
setLoading(false);
setRefreshing(false);
Expand Down
21 changes: 14 additions & 7 deletions src/screens/profile/DailyBarcodeDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,27 @@ export default function DailyBarcodeDetail() {
} = route.params;
const { setBarcodeId } = useBarcodeContext();

const onServerError = () => {
navigation.reset({
index: 0,
routes: [{ name: "ServerError" }],
});
};

useEffect(() => {
setBarcodeId(barcodeId);
}, [barcodeId, setBarcodeId]);

useEffect(() => {
getToggleStateFromStorage(); // 저장된 토글 상태 불러오기
getToggleStateFromStorage();
}, []);

useEffect(() => {
setIsEnabled(isPrivate); // 초기 토글 상태 설정
setIsEnabled(isPrivate);
}, [isPrivate]);

useEffect(() => {
loadPhotos(); // 사진 정보 받아오기
loadPhotos();
}, []);

const getToggleStateFromStorage = async () => {
Expand All @@ -83,7 +90,7 @@ export default function DailyBarcodeDetail() {

try {
await patchPublicBarcode(barcodeId, !isEnabled);
storeToggleState(!isEnabled); // 토글 상태 저장
storeToggleState(!isEnabled);
} catch (error) {
console.error("바코드 전환 에러:", error);
}
Expand All @@ -101,7 +108,7 @@ export default function DailyBarcodeDetail() {
console.error("일상 디테일 사진 조회 에러 ", response.error.message);
}
} catch (error) {
console.error("일상 디테일 사진 조회 에러 ", error);
onServerError();
}
};

Expand Down Expand Up @@ -143,10 +150,10 @@ export default function DailyBarcodeDetail() {
setPhotos((prevPhotos) => [...prevPhotos, ...nextTenPhotos]);
setCurrentPage(nextPage);
} else {
console.error("일상 디테일 사진 조회 에러 ", response.error.message);
onServerError();
}
} catch (error) {
console.error("일상 디테일 사진 조회 에러 ", error);
onServerError();
} finally {
setIsLoadingMore(false);
}
Expand Down
36 changes: 8 additions & 28 deletions src/screens/profile/Profile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SERVER_HOST } from "@env";
import React, { useEffect, useState } from "react";
import { useNavigation } from "@react-navigation/native";
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
Expand All @@ -7,30 +6,27 @@ import SettingSvg from "../../assets/images/setting/setting";
import DailyBarcodeTab from "../../components/profiletab/DailyBarcodeTab";
import EventBarcodeTab from "../../components/profiletab/EventBarcodeTab";
import getProfileData from "../../server/profile/getProfileData";
// import sendRequest from "../../server/test/makeBarcode";

const Tab = createMaterialTopTabNavigator();

export default function Profile() {
// const [loading, setLoading] = useState(false);

// const handleBarcodeCreation = async () => {
// setLoading(true);
// await sendRequest();
// setLoading(false);
// };
// 바코드 만들기 테스트
const navigation = useNavigation();

const [profileData, setProfileData] = useState(null);

const onServerError = () => {
navigation.reset({
index: 0,
routes: [{ name: "ServerError" }],
});
};

useEffect(() => {
const fetchProfileData = async () => {
try {
const data = await getProfileData();
setProfileData(data);
} catch (error) {
console.error("프로필 데이터 에러", error);
onServerError();
}
};

Expand Down Expand Up @@ -62,9 +58,6 @@ export default function Profile() {
<Text style={styles.profileTag}>@{profileData.identifierId}</Text>
</View>
</View>
{/* <TouchableOpacity onPress={handleBarcodeCreation} style={styles.button}>
<Text style={styles.buttonText}>바코드 생성</Text>
</TouchableOpacity> */}
<Tab.Navigator
initialRouteName="데일리 바코드"
screenOptions={{
Expand Down Expand Up @@ -117,19 +110,6 @@ const styles = StyleSheet.create({
fontSize: 12,
fontWeight: "500",
},
// button: {
// backgroundColor: "#FFD700",
// paddingVertical: 10,
// paddingHorizontal: 20,
// borderRadius: 8,
// alignSelf: "center",
// marginVertical: 20,
// },
// buttonText: {
// color: "#000000",
// fontSize: 16,
// fontWeight: "bold",
// },
disabled: {
opacity: 0.5,
},
Expand Down
9 changes: 8 additions & 1 deletion src/screens/profile/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ export default function Setting() {
const navigation = useNavigation();
const [profileData, setProfileData] = useState(null);

const onServerError = () => {
navigation.reset({
index: 0,
routes: [{ name: "ServerError" }],
});
};

useEffect(() => {
const fetchProfileData = async () => {
try {
const data = await getProfileData();
console.log(data);
setProfileData(data);
} catch (error) {
console.error("프로필 데이터 에러", error);
onServerError();
}
};

Expand Down

0 comments on commit 14de6cd

Please sign in to comment.