diff --git a/components/addQuestion.js b/components/addQuestion.js index 0d9312c..4d33159 100644 --- a/components/addQuestion.js +++ b/components/addQuestion.js @@ -4,17 +4,6 @@ import * as SecureStore from 'expo-secure-store' import { Dropdown } from 'react-native-element-dropdown' import AntDesign from '@expo/vector-icons/AntDesign' -const data = [ - { label: 'General Knowledge', value: 'General Knowledge' }, - { label: 'Entertainment', value: 'Entertainment' }, - { label: 'Science', value: 'Science' }, - { label: 'Politics', value: 'Politics' }, - { label: 'Geography', value: 'Geography' }, - { label: 'History', value: 'History' }, - { label: 'Sports', value: 'Sports' }, - { label: 'Others', value: 'Others' }, -] - export default function AddQuestion({ navigation }) { const [question, setQuestion] = useState("") const [option1, setOption1] = useState("") @@ -24,13 +13,31 @@ export default function AddQuestion({ navigation }) { const [correctOption, setCorrectOption] = useState("") const [category, setCategory] = useState("") + const categoryData = [ + { label: 'General Knowledge', value: 'General Knowledge' }, + { label: 'Entertainment', value: 'Entertainment' }, + { label: 'Science', value: 'Science' }, + { label: 'Politics', value: 'Politics' }, + { label: 'Geography', value: 'Geography' }, + { label: 'History', value: 'History' }, + { label: 'Sports', value: 'Sports' }, + { label: 'Others', value: 'Others' } + ] + + const correctOptionData = [ + { label: option1, value: option1 }, + { label: option2, value: option2 }, + { label: option3, value: option3 }, + { label: option4, value: option4 } + ].filter(option => option.label.trim() !== "" && option.label.trim() !== null) + + const addQuestion = async (e) => { // console.log(question) e.preventDefault() const user_email = await SecureStore.getItemAsync("email") // Api Call - console.log(category) - const response = await fetch("http://172.31.33.189/software_project/addQuestions", { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/addQuestions`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' @@ -44,13 +51,13 @@ export default function AddQuestion({ navigation }) { return ( + )} /> + - + + { + setCorrectOption(item.value) + }} + /> + Save @@ -164,6 +189,9 @@ const styles = StyleSheet.create({ }, inputSearchStyle: { height: 40, - fontSize: 16, + fontSize: 16 }, + placeholderCorrectStyle: { + color: '#9E9E9E' + } }) \ No newline at end of file diff --git a/components/home.js b/components/home.js index 3ad88ec..14d4d64 100644 --- a/components/home.js +++ b/components/home.js @@ -1,53 +1,70 @@ -import {StyleSheet} from "react-native" +import { StyleSheet } from "react-native" import Tab_one from "./tab_one"; import AddQuestion from "./addQuestion"; import { createNativeStackNavigator } from '@react-navigation/native-stack' import { NavigationContainer } from '@react-navigation/native' -import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; -import User from "./user"; -import User_helper from "./user_helper"; +import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' +import User from "./user" +import User_helper from "./user_helper" const Stack = createNativeStackNavigator(); const User_Stack = createNativeStackNavigator(); const Tab = createBottomTabNavigator(); -const Question_One_Tab = ({navigation})=>{ +const Question_One_Tab = ({ navigation }) => { return ( - - - + + + ) } -const User_Tab = ({navigation})=>{ +const User_Tab = ({ navigation }) => { return ( - - - + + + ) } -export default function Home({navigation}){ - return( +export default function Home({ navigation }) { + return ( - - + + - ) } const styles = StyleSheet.create({ container: { - flex: 1 - }, - }); \ No newline at end of file + flex: 1 + } +}) \ No newline at end of file diff --git a/components/login.js b/components/login.js index 42f1aed..acd7a32 100644 --- a/components/login.js +++ b/components/login.js @@ -15,7 +15,7 @@ export default function Login({ navigation }) { const saveUser = async (name, email) => { console.log(name, email) - const response = await fetch(`http://172.31.33.189/software_project/login`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/login`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' diff --git a/components/question.js b/components/question.js index 3b6453a..71ff67b 100644 --- a/components/question.js +++ b/components/question.js @@ -3,9 +3,11 @@ import { View, Text, StyleSheet, TouchableOpacity } from 'react-native' import { FlatList } from 'react-native' import { FontAwesome } from '@expo/vector-icons' import * as SecureStore from 'expo-secure-store' +import { Dropdown } from 'react-native-element-dropdown' +import AntDesign from '@expo/vector-icons/AntDesign' const FlatList_Item = (props) => { - const { question, options, correct, questionId, BookmarkInstantiation, UpvoteInstantiation ,DownvoteInstantiation } = props + const { question, options, correct, category, questionId, BookmarkInstantiation, UpvoteInstantiation, DownvoteInstantiation } = props const [selectedOption, setSelectedOption] = useState(-1) // selectedOption is the index of option selected. const [isCorrect, setIsCorrect] = useState(-1) // -1 -> Not Answered , 0 -> Incorrect Answer , 1 -> Correct Answer @@ -18,7 +20,7 @@ const FlatList_Item = (props) => { setIsBookmarked(BookmarkInstantiation) setIsUpvoted(UpvoteInstantiation) setIsDownvoted(DownvoteInstantiation) - }, [BookmarkInstantiation,UpvoteInstantiation,DownvoteInstantiation]) + }, [BookmarkInstantiation, UpvoteInstantiation, DownvoteInstantiation]) const handleOptionPress = (optionIndex) => { @@ -56,7 +58,7 @@ const FlatList_Item = (props) => { setIsBookmarked(false) - const response = await fetch(`http://172.31.33.189/software_project/remove_bookmark`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/remove_bookmark`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' @@ -70,7 +72,7 @@ const FlatList_Item = (props) => { setIsBookmarked(true) - const response = await fetch(`http://172.31.33.189/software_project/add_bookmark`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/add_bookmark`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' @@ -97,7 +99,7 @@ const FlatList_Item = (props) => { setIsUpvoted(false) } - const response = await fetch(`http://172.31.33.189/software_project/upvote`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/upvote`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' @@ -108,7 +110,7 @@ const FlatList_Item = (props) => { const json = await response.json() } - const handleDownvotePress = async() => { + const handleDownvotePress = async () => { const email = await SecureStore.getItemAsync("email") @@ -123,7 +125,7 @@ const FlatList_Item = (props) => { setIsDownvoted(false) } - const response = await fetch(`http://172.31.33.189/software_project/downvote`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 + const response = await fetch(`http://172.31.52.60/software_project/downvote`, { //Ansh =>172.31.52.60, Jay => 172.31.33.189 method: "post", headers: { "Content-Type": 'application/json' @@ -145,7 +147,7 @@ const FlatList_Item = (props) => { isCorrect == 1 && styles.correctItemContainer, isCorrect == 0 && styles.incorrectItemContainer ]}> - + handleUpvotePress(questionId)}> @@ -165,6 +167,8 @@ const FlatList_Item = (props) => { + {category} + {question} {options.map((option, index) => ( @@ -202,29 +206,101 @@ const FlatList_Item = (props) => { ) } -const Question = ({ questions, bookmarked_questions, upvoted_questions , downvoted_questions }) => { +const Question = ({ questions, bookmarked_questions, upvoted_questions, downvoted_questions }) => { + + const [isFilter, setIsFilter] = useState(false) + const [FilterCategory, setFilterCategory] = useState("") + + const categoryData = [ + { label: 'General Knowledge', value: 'General Knowledge' }, + { label: 'Entertainment', value: 'Entertainment' }, + { label: 'Science', value: 'Science' }, + { label: 'Politics', value: 'Politics' }, + { label: 'Geography', value: 'Geography' }, + { label: 'History', value: 'History' }, + { label: 'Sports', value: 'Sports' }, + { label: 'Others', value: 'Others' } + ] + const renderItem = ({ item }) => { - return ( - - ) + + if (isFilter && FilterCategory != item.category) { + return null + } + else { + + return ( + + ) + + } } return ( - + + + + + + + { + setFilterCategory(item.value) + setIsFilter(true) + }} + renderLeftIcon={() => ( + + )} + /> + + + + { + setIsFilter(false) + setFilterCategory("") + }}> + + Remove Filter + + + + + + item._id} /> + + ) } @@ -240,7 +316,8 @@ const styles = StyleSheet.create({ padding: 20, marginVertical: 8, borderRadius: 10, - elevation: 3 + elevation: 3, + marginTop: 20 }, correctItemContainer: { borderColor: '#4CAF50', @@ -250,8 +327,22 @@ const styles = StyleSheet.create({ borderColor: '#FF220B', borderWidth: 3 }, + category: { + fontSize: 14, + color: '#808080', + fontStyle: 'italic', + marginTop: 35, + borderWidth: 1, + borderRadius: 5, + borderColor: '#808080', + paddingVertical: 4, + paddingHorizontal: 8, + textAlign: 'center', + alignSelf: 'flex-start', + maxWidth: '80%', + }, questionText: { - marginTop: 20, + marginTop: 5, fontSize: 18, fontWeight: 'bold', marginBottom: 12, @@ -315,6 +406,58 @@ const styles = StyleSheet.create({ }, downvoteFalse: { color: '#908C8C' + }, + icon: { + marginRight: 5, + }, + label: { + position: 'absolute', + backgroundColor: 'white', + left: 22, + top: 8, + zIndex: 999, + paddingHorizontal: 8, + fontSize: 14, + }, + placeholderStyle: { + fontSize: 16, + color: '#9E9E9E', + }, + selectedTextStyle: { + fontSize: 16 + }, + iconStyle: { + width: 20, + height: 20, + }, + inputSearchStyle: { + height: 40, + fontSize: 16 + }, + placeholderCorrectStyle: { + color: '#9E9E9E' + }, + dropdown: { + height: 50, + borderColor: '#000000', + borderWidth: 1, + borderRadius: 8, + paddingHorizontal: 8, + backgroundColor: '#ffffff', + width: 215 + }, + removeFilter: { + height: 50, + borderColor: '#000000', + borderWidth: 1, + borderRadius: 8, + width: 115, + backgroundColor: '#ffffff', + alignItems: 'center', + justifyContent: 'center', + }, + removeFilterText: { + color: '#9E9E9E' } }) diff --git a/components/tab_one.js b/components/tab_one.js index 8a86f0b..445fb3d 100644 --- a/components/tab_one.js +++ b/components/tab_one.js @@ -5,7 +5,7 @@ import { useIsFocused } from "@react-navigation/native"; import * as SecureStore from 'expo-secure-store'; export default function Tab_one({ navigation }) { - const isFocused = useIsFocused(); + const isFocused = useIsFocused() const [questions, setQuestions] = useState([]) const [bookmarked_questions, setBookmarked_questions] = useState([]) const [upvoted_questions, setUpvoted_questions] = useState([]) @@ -14,7 +14,7 @@ export default function Tab_one({ navigation }) { const fetchQuestions = async () => { const email = await SecureStore.getItemAsync("email") //Api call - const response = await fetch(`http://172.31.33.189/software_project/questions`, { + const response = await fetch(`http://172.31.52.60/software_project/questions`, { method: "post", body: JSON.stringify({ email: email }), headers: { @@ -30,14 +30,13 @@ export default function Tab_one({ navigation }) { } const addQuestion = async () => { - navigation.navigate('AddQuestion') + navigation.navigate('Add Question') } useEffect(() => { fetchQuestions() }, [isFocused,navigation]) - return (