refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-08 19:13:49 +08:00
parent 678b8515ca
commit 9f1b115c73
55 changed files with 421 additions and 338 deletions
+3 -3
View File
@@ -5,16 +5,16 @@ import { addChannelMsg } from "../../app/slices/message.channel";
import { addUserMsg } from "../../app/slices/message.user";
interface IProps {
context: "channel" | "uesr";
context: "channel" | "user";
to: number;
}
export default function useAddLocalFileMessage({ context, to }: IProps) {
const dispatch = useDispatch();
const addContextMessage = context == "channel" ? addChannelMsg : addUserMsg;
const addLocalFileMesage = (data) => {
const addLocalFileMessage = (data) => {
dispatch(addMessage(data));
dispatch(addContextMessage({ id: to, mid: data.mid }));
};
return addLocalFileMesage;
return addLocalFileMessage;
}
+1 -1
View File
@@ -74,7 +74,7 @@ export default function useStreaming() {
isError
} = await renewToken({
token,
refreshToken
refresh_token: refreshToken
});
if (isError) return;
api_token = newToken;
+11 -6
View File
@@ -1,4 +1,4 @@
import { useState, useRef } from "react";
import { useState, useRef, FC } from "react";
import toast from "react-hot-toast";
import { updateUploadFiles } from "../../app/slices/ui";
import BASE_URL, { FILE_SLICE_SIZE } from "../../app/config";
@@ -6,8 +6,12 @@ import { usePrepareUploadFileMutation, useUploadFileMutation } from "../../app/s
import { useAppDispatch, useAppSelector } from "../../app/store";
// todo: check props type
export default function useUploadFile(props: { context: string; id: string } | object = {}) {
const { context = "", id = "" } = props;
interface IProps {
context: "channel" | "user";
id: number;
}
const useUploadFile = (props: IProps) => {
const { context, id } = props;
const dispatch = useAppDispatch();
const { stageFiles, replying } = useAppSelector((store) => {
return {
@@ -112,7 +116,7 @@ export default function useUploadFile(props: { context: string; id: string } | o
canceledRef.current = true;
};
const removeStageFile = (idx) => {
const removeStageFile = (idx: number) => {
dispatch(updateUploadFiles({ context, id, operation: "remove", index: idx }));
};
@@ -128,7 +132,7 @@ export default function useUploadFile(props: { context: string; id: string } | o
dispatch(updateUploadFiles({ context, id, operation: "reset" }));
};
const updateStageFile = (idx, data = {}) => {
const updateStageFile = (idx: number, data = {}) => {
dispatch(
updateUploadFiles({
context,
@@ -156,4 +160,5 @@ export default function useUploadFile(props: { context: string; id: string } | o
removeStageFile,
updateStageFile
};
}
};
export default useUploadFile;
+1 -1
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, FC } from "react";
import { useState, useEffect } from "react";
import toast from "react-hot-toast";
// import { ContentTypes } from "../../../app/config";
import { useNavigate, useMatch } from "react-router-dom";