From 21dd9751453a3229781fa666abb4b7ff036b6b25 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Thu, 21 Jul 2022 18:37:47 +0800 Subject: [PATCH] refactor: more TS definitions --- src/app/services/base.query.ts | 2 +- src/react-app-env.d.ts | 10 ---------- src/routes/chat/utils.tsx | 6 ++---- src/routes/favs/index.tsx | 9 ++++----- src/routes/home/Tools.tsx | 10 +++++++--- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/app/services/base.query.ts b/src/app/services/base.query.ts index 73d0ea81..d9a6263b 100644 --- a/src/app/services/base.query.ts +++ b/src/app/services/base.query.ts @@ -37,7 +37,7 @@ const baseQuery = fetchBaseQuery({ } }); -let waitingForRenew = null; +let waitingForRenew: null | any = null; const baseQueryWithTokenCheck = async (args, api, extraOptions) => { if (waitingForRenew) { await waitingForRenew; diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 8380f0f0..02610c70 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -61,13 +61,3 @@ declare module "*.module.css" { const classes: { readonly [key: string]: string }; export default classes; } - -declare module "*.module.scss" { - const classes: { readonly [key: string]: string }; - export default classes; -} - -declare module "*.module.sass" { - const classes: { readonly [key: string]: string }; - export default classes; -} diff --git a/src/routes/chat/utils.tsx b/src/routes/chat/utils.tsx index 31575e13..f2f83459 100644 --- a/src/routes/chat/utils.tsx +++ b/src/routes/chat/utils.tsx @@ -26,11 +26,11 @@ export function getUnreadCount({ mids = [], messageData = {}, loginUid = 0, read return mid > readIndex; }); // 拿at数量 - const tmps = []; + const tmps: number[] = []; final.forEach((mid) => { const msg = messageData[mid]; const { mentions = [] } = msg.properties || {}; - mentions.forEach((id) => { + mentions.forEach((id: number) => { if (id == loginUid) { tmps.push(mid); } @@ -104,7 +104,6 @@ const StyledWrapper = styled.div` flex: 1; } &.select { - /* cursor: pointer; */ &:hover { border-radius: var(--br); background: #f5f6f7; @@ -127,7 +126,6 @@ const MessageWrapper = ({ selectMode = false, context, id, mid, children, ...res return ( - {/* {React.cloneElement(children, { readOnly: selected })} */} {children} {selectMode &&
}
diff --git a/src/routes/favs/index.tsx b/src/routes/favs/index.tsx index 4c13ebaf..96107596 100644 --- a/src/routes/favs/index.tsx +++ b/src/routes/favs/index.tsx @@ -37,19 +37,18 @@ const Filters = [ filter: "audio" } ]; +type filter = "audio" | "video" | "image" | ""; function FavsPage() { - const [filter, setFilter] = useState(""); + const [filter, setFilter] = useState(""); const [favs, setFavs] = useState([]); const { favorites, channelData, userData } = useAppSelector((store) => { - console.log("favs", store.favorites); return { favorites: store.favorites, userData: store.users.byId, channelData: store.channels.byId }; }); - const handleFilter = (ftr) => { - console.log("fff", ftr); + const handleFilter = (ftr: filter) => { setFilter(ftr); }; useEffect(() => { @@ -122,7 +121,7 @@ function FavsPage() {
  • {icon} {title} diff --git a/src/routes/home/Tools.tsx b/src/routes/home/Tools.tsx index a6e66288..6276b858 100644 --- a/src/routes/home/Tools.tsx +++ b/src/routes/home/Tools.tsx @@ -1,4 +1,4 @@ -// import React from 'react'; +import React from "react"; import { RiAddFill } from "react-icons/ri"; import styled from "styled-components"; @@ -60,7 +60,10 @@ const StyledWrapper = styled.div` } } `; -export default function Tools({ expand = true }) { +type Props = { + expand?: boolean; +}; +const Tools: React.FC = ({ expand = true }) => { return (
    @@ -90,4 +93,5 @@ export default function Tools({ expand = true }) {
    ); -} +}; +export default Tools;