From c9d2bbbe9c5fa9731ed648acbe1ddf56696d9e38 Mon Sep 17 00:00:00 2001 From: aestera Date: Sat, 14 Oct 2023 21:38:02 +0900 Subject: [PATCH] Minor Changes --- src/screens/MypageScreen/MypageScreen.js | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/screens/MypageScreen/MypageScreen.js b/src/screens/MypageScreen/MypageScreen.js index ad5fe2a..6d35258 100644 --- a/src/screens/MypageScreen/MypageScreen.js +++ b/src/screens/MypageScreen/MypageScreen.js @@ -1,14 +1,15 @@ -import React, {useContext, useEffect, useState} from 'react'; +import React, { useContext, useEffect, useState } from 'react'; -import {useNavigation} from '@react-navigation/native'; -import {launchImageLibrary, launchCamera} from 'react-native-image-picker'; -import {TabView, TabBar} from 'react-native-tab-view'; +import { useNavigation, useIsFocused } from '@react-navigation/native'; +import { launchImageLibrary, launchCamera } from 'react-native-image-picker'; +import { TabView, TabBar } from 'react-native-tab-view'; import { useRecoilValue } from 'recoil'; import { userInfoState } from '../../states/atoms'; -import axios from 'axios'; -import {AuthContext} from '../../utils/Auth'; +import { AuthContext } from '../../utils/Auth'; import { backendURL } from '../../constants/url'; +import axios from 'axios'; + import { Pressable, HamburgerIcon, @@ -38,6 +39,14 @@ import { const MypageScreen = () => { + const isFocused = useIsFocused(); + + useEffect(() =>{ + if(isFocused) { + getPictureFromDB() + } + }, [isFocused]) + const {logout} = useContext(AuthContext); const userInfo = useRecoilValue(userInfoState); @@ -54,7 +63,6 @@ const MypageScreen = () => { const [index, setIndex] = useState(0); const [modalVisible, setModalVisible] = useState(false); const [userStyles, setUserStyles] = useState(); - const [getClothesData, setGetClothesData] = useState(); const [postData, setPostData] = useState(); const [data, setData] = useState({}); @@ -110,7 +118,6 @@ const MypageScreen = () => { } else if (response.error) { console.log('Image picker error: ', response.error); } else { - const ImgUri = response.assets[0].uri; const base = response.assets[0]; try { @@ -152,7 +159,11 @@ const MypageScreen = () => { const getPictureFromDB = async () => { try { await axios.get(backendURL+`/api/closet/getClosetData?userId=${userInfo.nickname}`) - .then((res)=>{setClothesData(res.data)}) + .then((res)=>{ + setClothesData(res.data) + setPostData(0) + setIndex(0) + }) } catch (e) { console.log(e); @@ -283,7 +294,6 @@ const MypageScreen = () => { indicatorStyle={styles.listunderline} style={styles.listBackground} labelStyle={styles.listTitle} - // onTabPress={getPictureFromDB} /> )} />