Skip to content

Commit

Permalink
Merge pull request #50 from I-Dont-Want-An-F/EInstein_Post
Browse files Browse the repository at this point in the history
E instein post
  • Loading branch information
dylanmount authored Dec 12, 2022
2 parents 2db1677 + 5648ce2 commit a5eeef1
Show file tree
Hide file tree
Showing 9 changed files with 963 additions and 691 deletions.
1,510 changes: 831 additions & 679 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"@react-navigation/native": "^6.0.13",
"@react-navigation/native-stack": "^6.9.1",
"@react-navigation/stack": "^6.3.2",
"@types/express": "^4.17.14",
"cli": "^1.0.1",
"expo": "~46.0.9",
"expo-cli": "^6.0.6",
"expo-status-bar": "~1.4.0",
"express": "^4.18.2",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-native": "0.69.6",
Expand Down
67 changes: 61 additions & 6 deletions screens/DetailScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default function DetailsScreen({ route, navigation }) {
const [rating, setRating] = useState([]);
const [post, setPost] = useState([]);
const [comments, setComment] = useState([]);
const [inputValue, setInputValue] = useState('');

//finds the averages


// finds the averages of the rating
const [stars, setStars] = useState([]);
Expand All @@ -32,10 +36,9 @@ export default function DetailsScreen({ route, navigation }) {
const [selected, setSelected] = useState([]);
const options = [{ key: '1', value: 'Comments' }, { key: '2', value: 'Questions' }, { key: '3', value: 'All' },];

// fetch the class data from the DB.
const getProf = async () => {
try {
const response = await fetch(URL + '/prof/' + route.params.shortname)
const response = await fetch(URL + '/prof/' + route.params.shortname )
const json = await response.json();
setProf(json);
} catch (error) {
Expand Down Expand Up @@ -70,7 +73,9 @@ export default function DetailsScreen({ route, navigation }) {
}
sum = sum / rating.length;
sum = Math.round(sum * 100) / 100;
return (

return(

sum
)
}
Expand All @@ -82,7 +87,11 @@ export default function DetailsScreen({ route, navigation }) {
}
sum = sum / rating.length;
sum = Math.round(sum * 100) / 100;
return (sum)

return(sum)



}

const getDif = () => {
Expand All @@ -92,7 +101,11 @@ export default function DetailsScreen({ route, navigation }) {
}
sum = sum / rating.length;
sum = Math.round(sum * 100) / 100;



return (sum)

}

//need to do somthing differnet
Expand All @@ -103,7 +116,9 @@ export default function DetailsScreen({ route, navigation }) {
}
sum = sum / rating.length;
sum = Math.round(sum * 100) / 100;

return (sum)

}

useEffect(() => {
Expand All @@ -112,9 +127,32 @@ export default function DetailsScreen({ route, navigation }) {
getRating();
getPost();
getStars();


}, []);

function Sendpost () {
if (inputValue === ''){return}

let Posts = {ID: post.length+49, classID : route.params.id, userID: username, text : inputValue }
console.log(Posts)
fetch(URL + '/createposts', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(Posts)
})
setInputValue('');
getPost();
}




// if the class has more than prof to teach

if (prof.length > 1) {
return (
<KeyboardAwareScrollView style={GlobalStyles.background3} >
Expand All @@ -138,13 +176,18 @@ export default function DetailsScreen({ route, navigation }) {
{/* create the basic info section. */}
<View style={GlobalStyles.titleSmall}>





<View key={rating} style={GlobalStyles.background2}>
<Text style={GlobalStyles.textSmall3}> {'General Rating: ' + getStars() + ' / 5'} </Text>
<Text style={GlobalStyles.textSmall3}> {'Difficulty: ' + getDif() + ' / 5'} </Text>
<Text style={GlobalStyles.textSmall3}> {'Homework frequency: ' + 'Approximately ' + getHW() + ' hours per week'} </Text>
{/* <Text style={GlobalStyles.textSmall3}> {'Textbook requirement: ' + rating.book} </Text> */}
</View>


</View>

<Text style={GlobalStyles.textDivider} ></Text>
Expand All @@ -162,7 +205,11 @@ export default function DetailsScreen({ route, navigation }) {
save="value"
/>




{/* show all the posts. */}

<View style={GlobalStyles.titleSmall}>
{post.map((post) => {
return (
Expand Down Expand Up @@ -211,12 +258,15 @@ export default function DetailsScreen({ route, navigation }) {

{/* create the basic info section. */}
<View style={GlobalStyles.titleSmall}>


<View key={rating} style={GlobalStyles.background2}>
<Text style={GlobalStyles.textSmall3}> {'General Rating: ' + getStars() + ' / 5'} </Text>
<Text style={GlobalStyles.textSmall3}> {'Difficulty: ' + getDif() + ' / 5'} </Text>
<Text style={GlobalStyles.textSmall3}> {'Homework frequency: ' + 'Approximately ' + getHW() + ' hours per week'} </Text>
{/* <Text style={GlobalStyles.textSmall3}> {'Textbook requirement: ' + rating.book} </Text> */}
</View>

</View>

<Text style={GlobalStyles.textDivider} ></Text>
Expand All @@ -234,7 +284,10 @@ export default function DetailsScreen({ route, navigation }) {
save="value"
/>



{/* show all posts. */}

<View style={GlobalStyles.titleSmall}>
{post.map((post) => {
return (
Expand All @@ -257,8 +310,10 @@ export default function DetailsScreen({ route, navigation }) {
})}
</View>

{/* create the reply input box. */}
<TextInput style={GlobalStyles.post_detail} placeholder="post a comment" onSubmitEditing={(event) => { setComment([...comments, { user1: username, post: event.nativeEvent.text }]) }} >{ }</TextInput>

<TextInput style={GlobalStyles.post_detail} placeholder="post a comment" onSubmitEditing={(event) => { setComment([...comments, { user1: username, post: inputValue }]) , Sendpost ()}} onChangeText={setInputValue} >{ }</TextInput>


</KeyboardAwareScrollView>
);
}
1 change: 1 addition & 0 deletions screens/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function MessageScreen ({ route, navigation }) {
// Post new message to the database
function onSend () {
if (inputValue === ''){return}

let message = {ID: messages.length+1, roomID: roomid, text: inputValue, sender: username.toLocaleLowerCase() }
fetch(URL + '/sendmessage', {
method: 'POST',
Expand Down
56 changes: 54 additions & 2 deletions screens/PostScreen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

/**
* Created by Sophia. Implements the post screen.
*/


import { React, useEffect, useState } from 'react';
import { Button, View, Text, TouchableOpacity, FlatList, TextInput } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
Expand All @@ -14,6 +16,9 @@ export default function PostScreen({ route, navigation }) {
const [username, setUsername] = useState();
const [reply, setReply] = useState([])
const [comments, setComment] = useState([])
const [post, setPost] = useState([])
const [inputValue, setInputValue] = useState('');


// fetch replies of the post from the DB.
const getReply = async () => {
Expand All @@ -26,18 +31,50 @@ export default function PostScreen({ route, navigation }) {
}
}

const getPost = async () => {
try {
const response = await fetch(URL + '/post/' + route.params.id)
const json = await response.json();
setPost(json);
} catch (error) {
console.error(error);
}
}


useEffect(() => {
getLocalData('username').then((data) => { setUsername(data.toLocaleLowerCase()) });
getReply();
}, []);


function Sendreply () {
if (inputValue === ''){return}
let replies = { ID: reply.length+40, text : inputValue }
console.log(replies)
fetch(URL + '/createreply', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(replies)
})
setInputValue('');
getReply();
}



return (
<KeyboardAwareScrollView style={GlobalStyles.background2}>
<View style={GlobalStyles.background2}>
<Text> </Text>
{/* show the main post. */}
<Text style={GlobalStyles.textSmall} > {route.params.username + ":"} {route.params.text} </Text>


{/* show the replies to the main post. */}

<View style={GlobalStyles.titleSmall}>
{reply.map((reply) => {
return (
Expand All @@ -49,6 +86,17 @@ export default function PostScreen({ route, navigation }) {
})}
</View>


{/* <FlatList data={comments} renderItem={({ item }) => (
<View>
<Text style={GlobalStyles.textSmall}>{' ' + item.user1}</Text>
<Text style={GlobalStyles.textSmall2}>{' ' + item.post}</Text>
</View>
)} />
<TextInput style={GlobalStyles.textIn} placeholder="post a reply" onSubmitEditing={(event) => { setComment([...comments, { user1: username, post: inputValue} ]) , Sendreply() }} onChangeText={setInputValue} >{ }</TextInput> */}


<View style={GlobalStyles.titleSmall}>
{comments.map((item) => {
return (
Expand All @@ -63,7 +111,11 @@ export default function PostScreen({ route, navigation }) {
{/* create the reply input box. */}
<TextInput style={GlobalStyles.textIn} placeholder="post a reply" onSubmitEditing={(event) => { setComment([...comments, { user1: username, post: event.nativeEvent.text }]) }} >{ }</TextInput>


<Text> </Text>
</KeyboardAwareScrollView>
{/* <TextInput onSubmitEditing={replySend} value={inputValue} onChangeText={setInputValue} /> */}
</View>


);
}
1 change: 1 addition & 0 deletions screens/ProfileScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ProfileScreen({ navigation }) {
const [username, setUsername] = useState("abc12");
const [classTaking, setTaking] = useState([]);
const [classTaken, setTaken] = useState([]);


// get the user data from the DB.
const getTaking = async () => {
Expand Down
2 changes: 1 addition & 1 deletion screens/SearchScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function SearchScreen({ navigation }) {
useEffect(() => {
const getData = async () => {
const apiResponse = await fetch(
"https://fast-woodland-72631.herokuapp.com/classes"
"https://shrouded-lowlands-27855.herokuapp.com/classes"
);
const data = await apiResponse.json();
setFakeData(data);
Expand Down
11 changes: 9 additions & 2 deletions screens/SignInScreen/SignInScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const SignInScreen = () => {

const onSignInPressed = () => {
storeLocalData('username', username);
navigation.navigate('Home')
};



navigation.navigate('Home') };


const onSignUpPressed = () => {
navigation.navigate('Sign Up')
Expand All @@ -34,8 +37,11 @@ const SignInScreen = () => {
navigation.navigate('Home')
};


return (
<ScrollView>


<View style={styles.root}>
<Image
source={Logo}
Expand Down Expand Up @@ -74,6 +80,7 @@ const SignInScreen = () => {
/>

</View>

</ScrollView>
);
};
Expand Down
4 changes: 3 additions & 1 deletion shared/URL.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

/**
* Created by Sophia. Stores the URL of the Heroku database.
*/

export const URL = 'https://fast-woodland-72631.herokuapp.com'
export const URL = 'https://fast-woodland-72631.herokuapp.com'

0 comments on commit a5eeef1

Please sign in to comment.