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: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["study_group_list"] });
|
||||
student_status_patch.mutate({
|
||||
study_group: name,
|
||||
});
|
||||
|
|
|
@ -172,7 +172,13 @@ export default function Home() {
|
|||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["study_group_list_global"] });
|
||||
setTimeout(() => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["study_group_list"] });
|
||||
}, 500);
|
||||
setStudyGroups([]);
|
||||
setStudying(false);
|
||||
toast.show("You are no longer studying \n" + subject, {
|
||||
type: "success",
|
||||
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] =
|
||||
useState<StudentStatusListType>([]);
|
||||
// Student Status List
|
||||
|
@ -251,7 +229,7 @@ export default function Home() {
|
|||
});
|
||||
|
||||
const [study_groups, setStudyGroups] = useState<StudyGroupType[]>([]);
|
||||
// Student Status List
|
||||
// Study Group List
|
||||
const StudyGroupQuery = useQuery({
|
||||
enabled: studying,
|
||||
queryKey: ["study_group_list"],
|
||||
|
@ -281,7 +259,7 @@ export default function Home() {
|
|||
>([]);
|
||||
// Student Status List
|
||||
const StudyGroupGlobalQuery = useQuery({
|
||||
enabled: !studying,
|
||||
enabled: !studying && !StudentStatusQuery.isFetching,
|
||||
queryKey: ["study_group_list_global"],
|
||||
queryFn: async () => {
|
||||
const data = await GetStudyGroupList();
|
||||
|
@ -420,11 +398,8 @@ export default function Home() {
|
|||
</Text>
|
||||
<Button
|
||||
onPress={() => {
|
||||
toast.show("Joined successfully", {
|
||||
type: "success",
|
||||
placement: "top",
|
||||
duration: 2000,
|
||||
animationType: "slide-in",
|
||||
mutation.mutate({
|
||||
study_group: studygroup.name,
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue