From e1b0048df61c81ec691e33c036d194ffb33d54ae Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Wed, 21 Dec 2022 08:07:47 +0800 Subject: [PATCH] chore: updates --- src/common/component/styled/Input.tsx | 2 +- src/common/hook/useMessageFeed.ts | 17 ++++++++++------- src/routes/settingDM/index.tsx | 7 ++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/common/component/styled/Input.tsx b/src/common/component/styled/Input.tsx index 2f4b31d6..8bc01baf 100644 --- a/src/common/component/styled/Input.tsx +++ b/src/common/component/styled/Input.tsx @@ -109,7 +109,7 @@ const Input: FC = ({ type = "text", prefix = "", className, ...rest }) => return type == "password" ? ( - +
{inputType == "password" ? : }
diff --git a/src/common/hook/useMessageFeed.ts b/src/common/hook/useMessageFeed.ts index 64f0b762..a39082df 100644 --- a/src/common/hook/useMessageFeed.ts +++ b/src/common/hook/useMessageFeed.ts @@ -59,7 +59,7 @@ export default function useMessageFeed({ context = "channel", id }: Props) { const pageRef = useRef(null); const containerRef = useRef(null); const [hasMore, setHasMore] = useState(true); - const [appends, setAppends] = useState([]); + const [appends, setAppends] = useState([]); const [items, setItems] = useState([]); const loadMoreMsgsFromServer = context == "channel" ? loadMoreChannelMsgs : loadMoreDmMsgs; const { mids, messageData, loginUid } = useAppSelector((store) => { @@ -71,6 +71,8 @@ export default function useMessageFeed({ context = "channel", id }: Props) { }; }); useEffect(() => { + // curScrollPos = 0; + // oldScroll = 0; listRef.current = []; pageRef.current = null; setItems([]); @@ -87,17 +89,18 @@ export default function useMessageFeed({ context = "channel", id }: Props) { } }, [items, context, id]); useEffect(() => { + //过滤掉本地消息 const serverMids = mids.filter((id: number) => { const ts = +new Date(); return Math.abs(ts - id) > 10 * 1000; }); - if (listRef.current.length == 0 && serverMids.length) { + if (listRef.current.length == 0 && serverMids.length > 0) { // 初次 const pageInfo = getFeedWithPagination({ mids: serverMids, isLast: true }); - // console.log("pull up 2", pageInfo); + console.log("pull up first", pageInfo, serverMids); pageRef.current = pageInfo; listRef.current = pageInfo.ids; setItems(listRef.current); @@ -109,7 +112,7 @@ export default function useMessageFeed({ context = "channel", id }: Props) { return Number(a) - Number(b); }); const appends = sorteds.filter((s: number) => s > lastMid); - // console.log("appends", appends, sorteds, lastMid, mids); + console.log("pull up appends", appends, sorteds, lastMid, mids); if (appends.length) { setAppends(appends); const [newestMsgId] = appends.slice(-1); @@ -133,7 +136,7 @@ export default function useMessageFeed({ context = "channel", id }: Props) { }, [mids, messageData, loginUid]); const pullUp = async () => { const currPageInfo = pageRef.current; - // console.log("pull up", currPageInfo); + console.log("pull up", currPageInfo); // 第一页 if (currPageInfo && currPageInfo.isFirst) { const [firstMid] = currPageInfo.ids; @@ -165,7 +168,7 @@ export default function useMessageFeed({ context = "channel", id }: Props) { setTimeout( () => { setItems(listRef.current); - // console.log("pull up", currPageInfo, listRef.current); + console.log("pull up timeout", currPageInfo, listRef.current); setHasMore(pageInfo.pageNumber !== 1); const container = containerRef.current; if (container) { @@ -173,7 +176,7 @@ export default function useMessageFeed({ context = "channel", id }: Props) { oldScroll = container.scrollHeight - container.clientHeight; } }, - currPageInfo?.isLast ? 10 : 800 + currPageInfo?.isLast ? 10 : 500 ); }; const pullDown = () => { diff --git a/src/routes/settingDM/index.tsx b/src/routes/settingDM/index.tsx index 72f96dbf..a2488be6 100644 --- a/src/routes/settingDM/index.tsx +++ b/src/routes/settingDM/index.tsx @@ -9,9 +9,10 @@ import { useTranslation } from "react-i18next"; let from: string = ""; export default function DMSetting() { - const { t } = useTranslation("setting"); + // const { t } = useTranslation("setting"); + const { t: ct } = useTranslation(); const { uid = 0 } = useParams(); - const { loginUser, user } = useAppSelector((store) => { + const { loginUser } = useAppSelector((store) => { return { loginUser: store.authData.user, user: uid ? store.users.byId[+uid] : undefined @@ -48,7 +49,7 @@ export default function DMSetting() { navs={navs} dangers={[ canDelete && { - title: t("action.remove"), + title: ct("action.remove_user"), handler: toggleDeleteConfirm } ]}