Skip to content

Commit

Permalink
Merge pull request #3 from AnshMehta1/main
Browse files Browse the repository at this point in the history
added filter based on category, improved CSS
  • Loading branch information
Jay18Mehta authored Apr 22, 2024
2 parents 256fa5e + afde91f commit 8b0ab8e
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 72 deletions.
62 changes: 45 additions & 17 deletions components/addQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand All @@ -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'
Expand All @@ -44,13 +51,13 @@ export default function AddQuestion({ navigation }) {
return (
<View style={styles.container}>
<View style={styles.itemContainer}>

<Dropdown
style={[styles.dropdown]}
placeholderStyle={styles.placeholderStyle}
selectedTextStyle={styles.selectedTextStyle}
inputSearchStyle={styles.inputSearchStyle}
iconStyle={styles.iconStyle}
data={data}
data={categoryData}
search={true}
maxHeight={300}
labelField="label"
Expand All @@ -70,12 +77,30 @@ export default function AddQuestion({ navigation }) {
/>
)}
/>

<TextInput onChangeText={setQuestion} value={question} style={styles.question} placeholder="Question" />
<TextInput onChangeText={setOption1} value={option1} style={styles.input} placeholder="Option 1" />
<TextInput onChangeText={setOption2} value={option2} style={styles.input} placeholder="Option 2" />
<TextInput onChangeText={setOption3} value={option3} style={styles.input} placeholder="Option 3" />
<TextInput onChangeText={setOption4} value={option4} style={styles.input} placeholder="Option 4" />
<TextInput onChangeText={setCorrectOption} value={correctOption} style={styles.correct} placeholder="Correct Option" />

<Dropdown
style={[styles.correct]}
inputSearchStyle={styles.inputSearchStyle}
placeholderStyle={styles.placeholderCorrectStyle}
data={correctOptionData}
search={true}
maxHeight={300}
labelField="label"
valueField="value"
placeholder={"Correct Option"}
searchPlaceholder="Search..."
value={correctOption}
onChange={item => {
setCorrectOption(item.value)
}}
/>

<Pressable onPress={addQuestion} style={styles.save}><Text style={styles.saveText}>Save</Text></Pressable>
</View>
</View>
Expand Down Expand Up @@ -164,6 +189,9 @@ const styles = StyleSheet.create({
},
inputSearchStyle: {
height: 40,
fontSize: 16,
fontSize: 16
},
placeholderCorrectStyle: {
color: '#9E9E9E'
}
})
57 changes: 37 additions & 20 deletions components/home.js
Original file line number Diff line number Diff line change
@@ -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 (
<NavigationContainer style={styles.container} independent={true}>
<Stack.Navigator initialRouteName="Tab_one">
<Stack.Screen name="Tab_one" component={Tab_one} options={{ headerShown: false }}/>
<Stack.Screen name = "AddQuestion" component={AddQuestion}/>
<Stack.Navigator initialRouteName="Single Correct MCQs" screenOptions={{

headerTitleStyle: {
fontSize: 22,
color: '#000000'
},

headerTitleAlign: 'center'

}}>
<Stack.Screen name="Single Correct MCQs" component={Tab_one} options={{ headerShown: true }} />
<Stack.Screen name="Add Question" component={AddQuestion} options={{ headerShown: true }} />
</Stack.Navigator>
</NavigationContainer>
)
}

const User_Tab = ({navigation})=>{
const User_Tab = ({ navigation }) => {
return (
<NavigationContainer style={styles.container} independent={true}>
<User_Stack.Navigator initialRouteName="User">
<User_Stack.Screen name="User" component={User}/>
<User_Stack.Screen name = "User_helper" component={User_helper}/>
<User_Stack.Navigator initialRouteName="User Profile" screenOptions={{

headerTitleStyle: {
fontSize: 22,
color: '#000000'
},

headerTitleAlign: 'center'

}}>
<User_Stack.Screen name="User Profile" component={User} options={{ headerShown: true }} />
<User_Stack.Screen name="User_helper" component={User_helper} options={{ headerShown: true }} />
</User_Stack.Navigator>
</NavigationContainer>
)
}

export default function Home({navigation}){
return(
export default function Home({ navigation }) {
return (
<NavigationContainer independent={true}>
<Tab.Navigator>
<Tab.Screen name="Question_One_Tab" component={Question_One_Tab} />
<Tab.Screen name="User" component={User_Tab} options={{ headerShown: false }}/>
<Tab.Screen name="Question_One_Tab" component={Question_One_Tab} options={{ headerShown: false }} />
<Tab.Screen name="User" component={User_Tab} options={{ headerShown: false }} />
</Tab.Navigator>
</NavigationContainer>

)
}

const styles = StyleSheet.create({
container: {
flex: 1
},
});
flex: 1
}
})
2 changes: 1 addition & 1 deletion components/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading

0 comments on commit 8b0ab8e

Please sign in to comment.