mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Finish up subjects page and user info page
This commit is contained in:
parent
ff973ccb0b
commit
1ac68bee30
4 changed files with 22 additions and 10 deletions
2
App.tsx
2
App.tsx
|
@ -20,6 +20,7 @@ import { useState, useEffect } from "react";
|
||||||
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
||||||
import { StatusBar } from "expo-status-bar";
|
import { StatusBar } from "expo-status-bar";
|
||||||
import UserInfoPage from "./src/routes/UserInfoPage/UserInfoPage";
|
import UserInfoPage from "./src/routes/UserInfoPage/UserInfoPage";
|
||||||
|
import SubjectsPage from "./src/routes/SubjectsPage/SubjectsPage";
|
||||||
|
|
||||||
const Drawer = createDrawerNavigator();
|
const Drawer = createDrawerNavigator();
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ export default function App() {
|
||||||
<Drawer.Screen name="Revalidation" component={Revalidation} />
|
<Drawer.Screen name="Revalidation" component={Revalidation} />
|
||||||
<Drawer.Screen name="Activation" component={Activation} />
|
<Drawer.Screen name="Activation" component={Activation} />
|
||||||
<Drawer.Screen name="User Info" component={UserInfoPage} />
|
<Drawer.Screen name="User Info" component={UserInfoPage} />
|
||||||
|
<Drawer.Screen name="Subjects" component={SubjectsPage} />
|
||||||
</Drawer.Navigator>
|
</Drawer.Navigator>
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
</Provider>
|
</Provider>
|
||||||
|
|
|
@ -78,6 +78,15 @@ export default function CustomDrawerContent(props: {}) {
|
||||||
<UserIcon size={32} />
|
<UserIcon size={32} />
|
||||||
<Text style={styles.text_white_medium}>User Info</Text>
|
<Text style={styles.text_white_medium}>User Info</Text>
|
||||||
</DrawerButton>
|
</DrawerButton>
|
||||||
|
<DrawerButton
|
||||||
|
color={colors.secondary_2}
|
||||||
|
onPress={() => {
|
||||||
|
navigation.navigate("Subjects");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<UserIcon size={32} />
|
||||||
|
<Text style={styles.text_white_medium}>Subjects</Text>
|
||||||
|
</DrawerButton>
|
||||||
<DrawerButton
|
<DrawerButton
|
||||||
color={colors.secondary_3}
|
color={colors.secondary_3}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
|
|
|
@ -75,7 +75,6 @@ export default function SubjectsPage() {
|
||||||
first_name: data[1].first_name,
|
first_name: data[1].first_name,
|
||||||
last_name: data[1].last_name,
|
last_name: data[1].last_name,
|
||||||
});
|
});
|
||||||
console.log(user.subjects);
|
|
||||||
setSelectedSubjects(user.subjects);
|
setSelectedSubjects(user.subjects);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -91,11 +90,11 @@ export default function SubjectsPage() {
|
||||||
// Subjects
|
// Subjects
|
||||||
|
|
||||||
const [selected_subjects, setSelectedSubjects] = useState<any>([]);
|
const [selected_subjects, setSelectedSubjects] = useState<any>([]);
|
||||||
const [subjectsOpen, setSubjectsOpen] = useState(true);
|
const [subjectsOpen, setSubjectsOpen] = useState(false);
|
||||||
const [subjects, setSubjects] = useState<OptionType[]>([]);
|
const [subjects, setSubjects] = useState<OptionType[]>([]);
|
||||||
|
|
||||||
const Subjects = useQuery({
|
const Subjects = useQuery({
|
||||||
enabled: StudentInfo.isFetched && !StudentInfo.isStale,
|
enabled: StudentInfo.isFetched,
|
||||||
queryKey: ["subjects"],
|
queryKey: ["subjects"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let data;
|
let data;
|
||||||
|
@ -128,14 +127,12 @@ export default function SubjectsPage() {
|
||||||
label: subject.name,
|
label: subject.name,
|
||||||
value: subject.name,
|
value: subject.name,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Update the 'subjects' state
|
// Update the 'subjects' state
|
||||||
|
setSelectedSubjects(user.subjects);
|
||||||
setSubjects(subjectsData);
|
setSubjects(subjectsData);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Toggle editing of profile
|
|
||||||
const [isEditable, setIsEditable] = useState(false);
|
|
||||||
// Profile photo
|
// Profile photo
|
||||||
function Avatar() {
|
function Avatar() {
|
||||||
if (user.avatar) {
|
if (user.avatar) {
|
||||||
|
@ -172,7 +169,6 @@ export default function SubjectsPage() {
|
||||||
<View style={{ flex: 3 }}>
|
<View style={{ flex: 3 }}>
|
||||||
<DropDownPicker
|
<DropDownPicker
|
||||||
zIndex={1000}
|
zIndex={1000}
|
||||||
disabled={!isEditable}
|
|
||||||
multiple={true}
|
multiple={true}
|
||||||
max={16}
|
max={16}
|
||||||
open={subjectsOpen}
|
open={subjectsOpen}
|
||||||
|
@ -186,6 +182,8 @@ export default function SubjectsPage() {
|
||||||
...styles.text_white_tiny_bold,
|
...styles.text_white_tiny_bold,
|
||||||
...{ textAlign: "left" },
|
...{ textAlign: "left" },
|
||||||
}}
|
}}
|
||||||
|
placeholder="Select subjects"
|
||||||
|
multipleText="Select subjects"
|
||||||
style={styles.input}
|
style={styles.input}
|
||||||
textStyle={{
|
textStyle={{
|
||||||
...styles.text_white_tiny_bold,
|
...styles.text_white_tiny_bold,
|
||||||
|
@ -193,6 +191,7 @@ export default function SubjectsPage() {
|
||||||
}}
|
}}
|
||||||
dropDownContainerStyle={{
|
dropDownContainerStyle={{
|
||||||
backgroundColor: colors.primary_2,
|
backgroundColor: colors.primary_2,
|
||||||
|
borderWidth: 0,
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
}}
|
}}
|
||||||
dropDownDirection="TOP"
|
dropDownDirection="TOP"
|
||||||
|
@ -203,18 +202,17 @@ export default function SubjectsPage() {
|
||||||
<Button
|
<Button
|
||||||
color={colors.secondary_3}
|
color={colors.secondary_3}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (isEditable) {
|
if (subjectsOpen) {
|
||||||
setSelectedSubjects([]);
|
setSelectedSubjects([]);
|
||||||
setSubjectsOpen(false);
|
setSubjectsOpen(false);
|
||||||
mutation.mutate({
|
mutation.mutate({
|
||||||
subjects: selected_subjects,
|
subjects: selected_subjects,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setIsEditable(!isEditable);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text style={styles.text_white_small}>
|
<Text style={styles.text_white_small}>
|
||||||
{isEditable && StudentInfo.isSuccess ? "Save" : "Edit Subjects"}
|
{subjectsOpen && StudentInfo.isSuccess ? "Save" : "Edit Subjects"}
|
||||||
</Text>
|
</Text>
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -230,6 +230,7 @@ export default function UserInfoPage() {
|
||||||
dropDownContainerStyle={{
|
dropDownContainerStyle={{
|
||||||
backgroundColor: colors.primary_2,
|
backgroundColor: colors.primary_2,
|
||||||
zIndex: 4000,
|
zIndex: 4000,
|
||||||
|
borderWidth: 0,
|
||||||
}}
|
}}
|
||||||
dropDownDirection="TOP"
|
dropDownDirection="TOP"
|
||||||
/>
|
/>
|
||||||
|
@ -265,6 +266,7 @@ export default function UserInfoPage() {
|
||||||
dropDownContainerStyle={{
|
dropDownContainerStyle={{
|
||||||
backgroundColor: colors.primary_2,
|
backgroundColor: colors.primary_2,
|
||||||
zIndex: 3000,
|
zIndex: 3000,
|
||||||
|
borderWidth: 0,
|
||||||
}}
|
}}
|
||||||
dropDownDirection="TOP"
|
dropDownDirection="TOP"
|
||||||
/>
|
/>
|
||||||
|
@ -300,6 +302,7 @@ export default function UserInfoPage() {
|
||||||
dropDownContainerStyle={{
|
dropDownContainerStyle={{
|
||||||
backgroundColor: colors.primary_2,
|
backgroundColor: colors.primary_2,
|
||||||
zIndex: 2000,
|
zIndex: 2000,
|
||||||
|
borderWidth: 0,
|
||||||
}}
|
}}
|
||||||
dropDownDirection="TOP"
|
dropDownDirection="TOP"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue