refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-08 22:30:06 +08:00
parent 9f1b115c73
commit c7eae47fb2
11 changed files with 33 additions and 80 deletions
-18
View File
@@ -1,18 +0,0 @@
import { useEffect } from "react";
import PWABadge from "pwa-badge";
export default function usePWABadge() {
// Create an Instance
const badge = new PWABadge();
useEffect(() => {
if (badge.isSupported()) {
badge.asyncSetBadge(2).catch((error) => {
console.error(error);
});
}
}, []);
return {
isSupported: badge.isSupported()
};
}
+2 -2
View File
@@ -12,7 +12,7 @@ export default function usePinMessage(cid: number) {
};
});
const [pin, { isError, isLoading, isSuccess }] = usePinMessageMutation();
const [unpin, { isError: isUnpinError, isLoading: isUnpining, isSuccess: isUnpinSuccess }] =
const [unpin, { isError: isUnpinError, isLoading: isUnpinning, isSuccess: isUnpinSuccess }] =
useUnpinMessageMutation();
const pinMessage = (mid: number) => {
if (!mid || !cid) return;
@@ -46,7 +46,7 @@ export default function usePinMessage(cid: number) {
isPining: isLoading,
isSuccess,
isUnpinError,
isUnpining,
isUnpinning,
isUnpinSuccess
};
}
+7 -7
View File
@@ -19,14 +19,13 @@ interface SendMessagesDTO {
}
interface SendMessageDTO {
type: "text";
content: string;
properties: object;
reply_mid?: number;
context: "user" | "channel";
from: number;
to: number;
}
export default function useSendMessage(props?: Props) {
const { context = "user", from = null, to = null } = props || {};
const useSendMessage = (props: Props) => {
const { context = "user", from, to = null } = props;
const dispatch = useAppDispatch();
const stageFiles = useAppSelector((store) => store.ui.uploadFiles[`${context}_${to}`] || []);
const [replyMessage, { isError: replyErr, isLoading: replying, isSuccess: replySuccess }] =
@@ -110,4 +109,5 @@ export default function useSendMessage(props?: Props) {
isSending: userSending || channelSending || replying,
isSuccess: channelSuccess || userSuccess || replySuccess
};
}
};
export default useSendMessage;