refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-25 23:14:27 +08:00
parent 17984a385e
commit 396a296c0b
21 changed files with 73 additions and 95 deletions
+7 -1
View File
@@ -2,7 +2,13 @@ import { useState, useEffect } from "react";
import { useLazyRemoveFavoriteQuery, useFavoriteMessageMutation } from "../../app/services/message";
import { useAppSelector } from "../../app/store";
export default function useFavMessage({ cid = null, uid = null }) {
export default function useFavMessage({
cid = null,
uid = null
}: {
cid?: number | null;
uid?: number | null;
}) {
const [removeFav] = useLazyRemoveFavoriteQuery();
const [addFav] = useFavoriteMessageMutation();
const [favorites, setFavorites] = useState([]);
+2 -2
View File
@@ -7,7 +7,7 @@ import { useAppDispatch, useAppSelector } from "../../app/store";
interface Props {
context: "user" | "channel";
from: number;
from?: number;
to: number;
}
@@ -25,7 +25,7 @@ interface SendMessageDTO {
}
const useSendMessage = (props?: Props) => {
const { context = "user", from, to = null } = props || {};
const { context = "user", from = 0, to = null } = props || {};
const dispatch = useAppDispatch();
const stageFiles = useAppSelector((store) => store.ui.uploadFiles[`${context}_${to}`] || []);
const [replyMessage, { isError: replyErr, isLoading: replying, isSuccess: replySuccess }] =
+3 -3
View File
@@ -4,13 +4,14 @@ import { updateUploadFiles } from "../../app/slices/ui";
import BASE_URL, { FILE_SLICE_SIZE } from "../../app/config";
import { usePrepareUploadFileMutation, useUploadFileMutation } from "../../app/services/message";
import { useAppDispatch, useAppSelector } from "../../app/store";
import { Message } from "../../types/channel";
// todo: check props type
interface IProps {
context: "channel" | "user";
id: number;
}
const useUploadFile = (props: IProps) => {
const useUploadFile = (props?: IProps) => {
const { context, id } = props ? props : { context: "channel", id: 0 };
const dispatch = useAppDispatch();
const { stageFiles, replying } = useAppSelector((store) => {
@@ -19,8 +20,7 @@ const useUploadFile = (props: IProps) => {
replying: store.message.replying[`${context}_${id}`]
};
});
const [data, setData] = useState(null);
// const [uploadingFile, setUploadingFile] = useState(false);
const [data, setData] = useState<Message | null>(null);
const canceledRef = useRef(false);
const sliceUploadedCountRef = useRef(0);
const totalSliceCountRef = useRef(1);
+2 -1
View File
@@ -8,6 +8,7 @@ import { useLazyDeleteUserQuery } from "../../app/services/user";
import useConfig from "./useConfig";
import useCopy from "./useCopy";
import { useAppSelector } from "../../app/store";
import { AgoraConfig } from "../../types/server";
interface IProps {
uid?: number;
cid?: number;
@@ -79,7 +80,7 @@ const useUserOperation = ({ uid, cid }: IProps) => {
const canDeleteChannel = cid && !channel?.is_public && isAdmin;
const canRemoveFromChannel =
cid && !channel?.is_public && (isAdmin || channel?.owner == loginUid) && uid != channel?.owner;
const canCall: boolean = agoraConfig.enabled && loginUid != uid;
const canCall: boolean = (agoraConfig as AgoraConfig)?.enabled && loginUid != uid;
const canRemove: boolean = isAdmin && loginUid != uid && !cid;
return {