mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Fixed bug in active student status if user leaves a study group
This commit is contained in:
parent
debaa544bc
commit
709125a344
2 changed files with 12 additions and 36 deletions
|
@ -52,6 +52,7 @@ export default function CreateGroup({ route }: any) {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["study_group_list"] });
|
||||||
student_status_patch.mutate({
|
student_status_patch.mutate({
|
||||||
study_group: name,
|
study_group: name,
|
||||||
});
|
});
|
||||||
|
|
|
@ -172,7 +172,13 @@ export default function Home() {
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["study_group_list_global"] });
|
||||||
|
setTimeout(() => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["study_group_list"] });
|
||||||
|
}, 500);
|
||||||
|
setStudyGroups([]);
|
||||||
|
setStudying(false);
|
||||||
toast.show("You are no longer studying \n" + subject, {
|
toast.show("You are no longer studying \n" + subject, {
|
||||||
type: "success",
|
type: "success",
|
||||||
placement: "top",
|
placement: "top",
|
||||||
|
@ -190,34 +196,6 @@ export default function Home() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const study_group_create = useMutation({
|
|
||||||
mutationFn: async (info: StudyGroupCreateType) => {
|
|
||||||
const data = await CreateStudyGroup(info);
|
|
||||||
if (data[0] != true) {
|
|
||||||
return Promise.reject(new Error());
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
|
||||||
toast.show("Created successfully", {
|
|
||||||
type: "success",
|
|
||||||
placement: "top",
|
|
||||||
duration: 2000,
|
|
||||||
animationType: "slide-in",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error: Error) => {
|
|
||||||
toast.show(String(error), {
|
|
||||||
type: "warning",
|
|
||||||
placement: "top",
|
|
||||||
duration: 2000,
|
|
||||||
animationType: "slide-in",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [student_statuses, setStudentStatuses] =
|
const [student_statuses, setStudentStatuses] =
|
||||||
useState<StudentStatusListType>([]);
|
useState<StudentStatusListType>([]);
|
||||||
// Student Status List
|
// Student Status List
|
||||||
|
@ -251,7 +229,7 @@ export default function Home() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const [study_groups, setStudyGroups] = useState<StudyGroupType[]>([]);
|
const [study_groups, setStudyGroups] = useState<StudyGroupType[]>([]);
|
||||||
// Student Status List
|
// Study Group List
|
||||||
const StudyGroupQuery = useQuery({
|
const StudyGroupQuery = useQuery({
|
||||||
enabled: studying,
|
enabled: studying,
|
||||||
queryKey: ["study_group_list"],
|
queryKey: ["study_group_list"],
|
||||||
|
@ -281,7 +259,7 @@ export default function Home() {
|
||||||
>([]);
|
>([]);
|
||||||
// Student Status List
|
// Student Status List
|
||||||
const StudyGroupGlobalQuery = useQuery({
|
const StudyGroupGlobalQuery = useQuery({
|
||||||
enabled: !studying,
|
enabled: !studying && !StudentStatusQuery.isFetching,
|
||||||
queryKey: ["study_group_list_global"],
|
queryKey: ["study_group_list_global"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const data = await GetStudyGroupList();
|
const data = await GetStudyGroupList();
|
||||||
|
@ -420,11 +398,8 @@ export default function Home() {
|
||||||
</Text>
|
</Text>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
toast.show("Joined successfully", {
|
mutation.mutate({
|
||||||
type: "success",
|
study_group: studygroup.name,
|
||||||
placement: "top",
|
|
||||||
duration: 2000,
|
|
||||||
animationType: "slide-in",
|
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue