Skip to content

Commit

Permalink
프론트 최종
Browse files Browse the repository at this point in the history
  • Loading branch information
lotuxsoo committed Jul 29, 2022
1 parent e900e7e commit bf0a9d9
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 192 deletions.
6 changes: 2 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
Expand All @@ -14,9 +14,7 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
Expand Down
19 changes: 11 additions & 8 deletions src/components/MyRoutineButton.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { StyleSheet, Text, View, Pressable } from "react-native";
import React from "react";
import React, { useEffect } from "react";
import { useNavigation } from "@react-navigation/native";
import { LinearGradient } from "expo-linear-gradient";

const MyRoutineButton = ({ routine }) => {
//한사람의 todos 전체받기
/*new*/
const navigation = useNavigation();
const Title = routine.title;
const Timezone1 = routine.startTime;
Expand Down Expand Up @@ -41,10 +39,15 @@ const MyRoutineButton = ({ routine }) => {
};

const post_no = routine.post_no;

const heartCount = routine.heartCount;
const scrapCount = routine.scrapCount;
const goTodoPage = () => {
// console.log(id)
navigation.navigate("Mines", { post_no });
navigation.navigate("Mines", {
heartCount: heartCount,
scrapCount: scrapCount,
post_no: post_no,
});
};

return (
Expand Down Expand Up @@ -74,9 +77,9 @@ const MyRoutineButton = ({ routine }) => {
</View>
</LinearGradient>
<View>
<Text style={styles.routineName}>{Title}</Text>
<Text style={styles.routineName}>🤍 100</Text>
<Text style={styles.routineName}>💚 100</Text>
<Text style={styles.routineName}>{routine.title}</Text>
<Text style={styles.routineName}>🤍 {heartCount}</Text>
<Text style={styles.routineName}>📌 {scrapCount}</Text>
</View>
</Pressable>
);
Expand Down
8 changes: 4 additions & 4 deletions src/components/TimePick.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState, useEffect } from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import { View, Text, StyleSheet } from "react-native";
import DateTimePickerModal from "react-native-modal-datetime-picker";
import DateTimePicker from "react-native-modal-datetime-picker";

const TimePick = ({ item, text, id, setHoursRange, hoursRange }) => {
const [selectedDate, setSelectedDate] = useState();

const [datePickerVisible, setDatePickerVisible] = useState(false);
// console.log('Time Pick hour', item)

const handleConfirm = (hour) => {
setSelectedDate(hour);
hideDatePicker();
Expand All @@ -14,7 +16,6 @@ const TimePick = ({ item, text, id, setHoursRange, hoursRange }) => {
});
const currentTime = Object.assign({}, hoursRange);
currentTime[id]["text"] = today;

setHoursRange(currentTime);
};

Expand All @@ -28,7 +29,6 @@ const TimePick = ({ item, text, id, setHoursRange, hoursRange }) => {
};

function printHour() {

const today = selectedDate.toLocaleTimeString("en-US", {
timeStyle: "short",
});
Expand Down
35 changes: 16 additions & 19 deletions src/screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
TouchableOpacity,
Image,
} from "react-native";
import todos from "../../assets/data/todos";
import { useNavigation, useIsFocused } from "@react-navigation/native";
import RoutineButton from "../components/RoutineButton";
import closestIndexTo from "date-fns/fp/closestIndexTo/index";
Expand Down Expand Up @@ -106,29 +105,24 @@ function HomeScreen() {
setFetchTodo(null);
// loading 상태를 true 로 바꿉니다.
setLoading(true);

const response = await axios.get("http://3.38.14.254/newRoutine/list");
setFetchTodo(response.data); // 데이터는 response.data 안에 들어있습니다.
setTimeTodos(
fettodo.filter(
(routine) =>
routine.startTime.charAt(0) == timeId ||
routine.startTime.substring(0, 2) == timeId
)
);
console.log(timeTodos);
} catch (e) {
setError(e);
}
setLoading(false);
setFlag(!flag);
};
fetching();
}, [isFocused]);

useEffect(() => {
fettodo !== null
? setTimeTodos(
fettodo.filter(
(routine) =>
routine.startTime.charAt(0) == timeId ||
routine.startTime.substring(0, 2) == timeId
)
)
: console.log("home");
}, [timeId, flag]);
}, [timeId, isFocused]);

return (
<View style={styles.container}>
Expand Down Expand Up @@ -183,26 +177,29 @@ function HomeScreen() {

<View style={styles.r_container}>
<ScrollView contentContainerStyle={styles.routine}>
{fettodo !== null && timeTodos !== null ? (
{timeTodos !== null ? (
<>
<View style={styles.column1}>
{timeTodos
.filter((index) => index % 2 == 0)
.filter((item) => item.post_no % 2 == 0)
.map((routine) => (
<RoutineButton routine={routine} key={routine.post_no} />
))}
</View>
<View style={styles.column2}>
{timeTodos
.filter((index) => index % 2 == 1)
.filter((item) => item.post_no % 2 == 1)
.map((routine) => (
<RoutineButton routine={routine} key={routine.post_no} />
))}
</View>
</>
) : (
<View style={{ justifyContent: "center", alignItems: "center" }}>
<Image source={Spinner} style={{ width: 100, height: 100 }} />
<Image
source={Spinner}
style={{ marginTop: 200, width: 100, height: 100 }}
/>
</View>
)}
</ScrollView>
Expand Down
73 changes: 46 additions & 27 deletions src/screens/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const LoginScreen = ({ navigation }) => {
// });
// };

await fetch("http://3.38.14.254/login", {
const response = await fetch("http://3.38.14.254/login", {
method: "POST",
body: JSON.stringify({
password: password,
Expand All @@ -63,35 +63,54 @@ const LoginScreen = ({ navigation }) => {
headers: {
"Content-Type": "application/json",
},
})
.then((response) => {
console.log(response.headers);
})
.then((response) => {
console.log(response);
//console.log(response.text)
// setLoading(false);
// console.log(response);
// console.log(response.ok);
// console.log(response.status);
// console.log(response.data.username);
if (!response) {
//AsyncStorage.setItem("username", response.data.username);
navigation.replace("BottomTab");
} else {
setErrortext(response.msg);
alert("이메일과 비밀번호를 다시 확인하세요.");
});
console.log(response.ok);
if (response.ok) {
console.log(response.headers);
AsyncStorage.setItem(
"@userData",
JSON.stringify(response.headers),
(err) => {
if (err) {
console.log("an error");
throw err;
}
console.log("success");
}
})
.catch((error) => {
setLoading(false);
console.error(error);
).catch((err) => {
console.log("2 an error");
});
alert("Login Success!");
navigation.navigate("BottomTab");
} else {
alert("Login failed");
}
// .then((response) => {
// console.log(response.headers);
// alert("회원가입 성공");
// })
// .then((response) => {
// console.log(response);
// //console.log(response.text)
// // setLoading(false);
// // console.log(response);
// // console.log(response.ok);
// // console.log(response.status);
// // console.log(response.data.username);
// if (!response) {
// //AsyncStorage.setItem("username", response.data.username);
// navigation.replace("BottomTab");
// } else {
// setErrortext(response.msg);
// alert("이메일과 비밀번호를 다시 확인하세요.");
// }
// })
// .catch((error) => {
// setLoading(false);
// console.error(error);
// });
};

const llogin = () => {
navigation.navigate("BottomTab");
};
const goBack = () => {
navigation.goBack();
};
Expand Down Expand Up @@ -166,7 +185,7 @@ const LoginScreen = ({ navigation }) => {
returnKeyType="next"
/>

<CustomButton onPress={llogin} text="Sign In" />
<CustomButton onPress={login} text="Sign In" />
</View>
</LinearGradient>
);
Expand Down
16 changes: 5 additions & 11 deletions src/screens/MineRoutineScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import IconButton from "../components/IconButton";
import AsyncStorage from "@react-native-async-storage/async-storage";
import axios from "axios";

function MineRoutineScreen() {
const MineRoutineScreen = () => {
const navigation = useNavigation();
const route = useRoute();
const [fettodo, setFetchTodo] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
Expand All @@ -34,7 +36,7 @@ function MineRoutineScreen() {
// loading 상태를 true 로 바꿉니다.
setLoading(true);
const response = await axios.get(
`http://3.38.14.254/newRoutine/list/${route.params?.post_no}`
`http://3.38.14.254/myRoutine/${route.params?.id}/${route.params?.post_no}`
);
setFetchTodo(response.data); // 데이터는 response.data 안에 들어있습니다
} catch (e) {
Expand All @@ -48,8 +50,6 @@ function MineRoutineScreen() {
const width = useWindowDimensions().width;
const height = useWindowDimensions().height;

const navigation = useNavigation();
const route = useRoute();
const TodoId = route.params?.id;

const goBack = () => {
Expand Down Expand Up @@ -102,12 +102,6 @@ function MineRoutineScreen() {
source={require("../../assets/icons/outline_delete_black_24dp.png")}
/>
</Pressable>

{/* <Button
onPress={onDelete}
style={{ width: 30, height: 15 }}
title=" 삭제 "
></Button> */}
</View>

<View style={styles.userInfo}>
Expand Down Expand Up @@ -141,7 +135,7 @@ function MineRoutineScreen() {
)}
</LinearGradient>
);
}
};

const styles = StyleSheet.create({
todo: {
Expand Down
Loading

0 comments on commit bf0a9d9

Please sign in to comment.