fix: notification error

This commit is contained in:
Tristan Yang
2022-08-09 21:46:54 +08:00
parent 44b0b8b285
commit 9daa0a384b
2 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ export const ChatPrefixes = {
channel: "#",
user: "@"
};
export const vapidKey = `BGXCn-5YRXSFw38Q9lUKJ5bibL212-yIQn1pCvthGhp6_KwA29FO1Ax_d_7if1vfC2a5wTSVO8AcZrc-Hm1aS0Y`;
export const vapidKey = `BOmzyZhw-DcIGYQ77mzQUVqLlcvn0bm_76P_kc7rpwRxzXNbui-JP8iPyEQYfyoxyJeq43Ud4IiIsJSMNHNujn0`;
export const tokenHeader = "X-API-Key";
export const FILE_SLICE_SIZE = 1000 * 200 * 8; //200kb
export const FILE_IMAGE_SIZE = 1000 * 10000 * 8; //10mb
+8 -5
View File
@@ -1,18 +1,21 @@
import { useEffect } from "react";
import { useEffect, memo } from "react";
import { useNavigate } from "react-router-dom";
import useDeviceToken from "./useDeviceToken";
import { vapidKey } from "../../../app/config";
import { useUpdateDeviceTokenMutation } from "../../../app/services/auth";
let updated = false;
const Notification = () => {
const navigateTo = useNavigate();
const token = useDeviceToken(vapidKey);
const [updateDeviceToken] = useUpdateDeviceTokenMutation();
const [updateDeviceToken, { isSuccess }] = useUpdateDeviceTokenMutation();
useEffect(() => {
if (token) {
if (token && !updated) {
updateDeviceToken(token);
}
}, [token]);
useEffect(() => {
updated = isSuccess;
}, [isSuccess]);
useEffect(() => {
const handleServiceworkerMessage = (event: MessageEvent) => {
@@ -29,4 +32,4 @@ const Notification = () => {
return null;
};
export default Notification;
export default memo(Notification);