mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Hotfix for rendering student statuses when student is not studying and show distance of study groups and students in map view
This commit is contained in:
parent
8f58dddbda
commit
cd9b8b91e3
1 changed files with 146 additions and 47 deletions
|
@ -21,6 +21,7 @@ import {
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import {
|
import {
|
||||||
GetStudentStatus,
|
GetStudentStatus,
|
||||||
|
GetStudentStatusList,
|
||||||
GetStudentStatusListNear,
|
GetStudentStatusListNear,
|
||||||
GetStudyGroupList,
|
GetStudyGroupList,
|
||||||
GetStudyGroupListFiltered,
|
GetStudyGroupListFiltered,
|
||||||
|
@ -259,6 +260,38 @@ export default function Home() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [student_statuses_global, setStudentStatusesGlobal] =
|
||||||
|
useState<StudentStatusListType>([]);
|
||||||
|
// Student Status List Global
|
||||||
|
const StudentStatusListGlobalQuery = useQuery({
|
||||||
|
enabled: !studying,
|
||||||
|
queryKey: ["user_status_list_global"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const data = await GetStudentStatusList();
|
||||||
|
if (data[0] == false) {
|
||||||
|
return Promise.reject(new Error(JSON.stringify(data[1])));
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (data: StudentStatusListReturnType) => {
|
||||||
|
if (data[1] && location) {
|
||||||
|
// Filter to only include students studying solo
|
||||||
|
let data_filtered = data[1].filter(
|
||||||
|
(item: StudentStatusFilterType) => item.study_group == null
|
||||||
|
);
|
||||||
|
setStudentStatusesGlobal(data_filtered);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error: Error) => {
|
||||||
|
toast.show(String(error), {
|
||||||
|
type: "warning",
|
||||||
|
placement: "top",
|
||||||
|
duration: 2000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const [study_groups, setStudyGroups] = useState<StudyGroupType[]>([]);
|
const [study_groups, setStudyGroups] = useState<StudyGroupType[]>([]);
|
||||||
// Study Group List
|
// Study Group List
|
||||||
const StudyGroupQuery = useQuery({
|
const StudyGroupQuery = useQuery({
|
||||||
|
@ -288,7 +321,7 @@ export default function Home() {
|
||||||
const [study_groups_global, setStudyGroupsGlobal] = useState<
|
const [study_groups_global, setStudyGroupsGlobal] = useState<
|
||||||
StudyGroupType[]
|
StudyGroupType[]
|
||||||
>([]);
|
>([]);
|
||||||
// Student Status List
|
// Study Group Global List
|
||||||
const StudyGroupGlobalQuery = useQuery({
|
const StudyGroupGlobalQuery = useQuery({
|
||||||
enabled: !studying,
|
enabled: !studying,
|
||||||
queryKey: ["study_group_list_global"],
|
queryKey: ["study_group_list_global"],
|
||||||
|
@ -350,7 +383,8 @@ export default function Home() {
|
||||||
}}
|
}}
|
||||||
loadingBackgroundColor={colors.secondary_2}
|
loadingBackgroundColor={colors.secondary_2}
|
||||||
>
|
>
|
||||||
{student_statuses.map(
|
{!studying ? (
|
||||||
|
student_statuses_global.map(
|
||||||
(student_status: StudentStatusFilterType, index: number) => {
|
(student_status: StudentStatusFilterType, index: number) => {
|
||||||
const randomColorWithOpacity = `rgba(${Math.floor(
|
const randomColorWithOpacity = `rgba(${Math.floor(
|
||||||
Math.random() * 256
|
Math.random() * 256
|
||||||
|
@ -397,6 +431,66 @@ export default function Home() {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
{studying ? (
|
||||||
|
student_statuses.map(
|
||||||
|
(student_status: StudentStatusFilterType, index: number) => {
|
||||||
|
const randomColorWithOpacity = `rgba(${Math.floor(
|
||||||
|
Math.random() * 256
|
||||||
|
)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(
|
||||||
|
Math.random() * 256
|
||||||
|
)}, 0.7)`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Marker
|
||||||
|
key={index}
|
||||||
|
coordinate={student_status.location}
|
||||||
|
pinColor={randomColorWithOpacity}
|
||||||
|
zIndex={1000}
|
||||||
|
onPress={() => {
|
||||||
|
toast.hideAll();
|
||||||
|
toast.show(
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
alignContent: "center",
|
||||||
|
alignSelf: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
Student: {student_status.user}
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{`Studying ${student_status.subject}`}
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{`${Math.round(
|
||||||
|
student_status.distance * 1000
|
||||||
|
)}m away`}
|
||||||
|
</Text>
|
||||||
|
</View>,
|
||||||
|
{
|
||||||
|
type: "normal",
|
||||||
|
placement: "top",
|
||||||
|
duration: 2000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
style: {
|
||||||
|
backgroundColor: colors.secondary_2,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: colors.primary_1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
)}
|
)}
|
||||||
{studying ? (
|
{studying ? (
|
||||||
study_groups.map(
|
study_groups.map(
|
||||||
|
@ -437,6 +531,11 @@ export default function Home() {
|
||||||
: "student"
|
: "student"
|
||||||
} studying`}
|
} studying`}
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{`${Math.round(
|
||||||
|
studygroup.distance * 1000
|
||||||
|
)}m away`}
|
||||||
|
</Text>
|
||||||
{student_status?.study_group !=
|
{student_status?.study_group !=
|
||||||
studygroup.name ? (
|
studygroup.name ? (
|
||||||
<Button
|
<Button
|
||||||
|
|
Loading…
Reference in a new issue