fix: update device token

This commit is contained in:
Tristan Yang
2022-08-12 21:43:27 +08:00
parent ef9bd40d8c
commit c95bba557a
+13 -4
View File
@@ -7,12 +7,21 @@ let updated = false;
const Notification = () => {
const navigateTo = useNavigate();
const token = useDeviceToken(vapidKey);
const [updateDeviceToken, { isSuccess }] = useUpdateDeviceTokenMutation();
const [updateDeviceToken, { isLoading, isSuccess }] = useUpdateDeviceTokenMutation();
useEffect(() => {
if (token && !updated) {
updateDeviceToken(token);
if (token && !isLoading && !updated) {
updateDeviceToken(token)
.then(() => {
updated = true;
})
.catch(() => {
updated = true;
})
.finally(() => {
updated = true;
});
}
}, [token]);
}, [token, isLoading]);
useEffect(() => {
updated = isSuccess;
}, [isSuccess]);