refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-11 16:28:02 +08:00
parent c7eae47fb2
commit 45a147ae67
18 changed files with 132 additions and 113 deletions
+6 -2
View File
@@ -48,7 +48,11 @@ const getFeedWithPagination = (config: Config): PageInfo => {
};
let curScrollPos = 0;
let oldScroll = 0;
export default function useMessageFeed({ context = "channel", id = null }) {
type Props = {
context?: "channel" | "user";
id: number;
};
export default function useMessageFeed({ context = "channel", id }: Props) {
const [loadMoreChannelMsgs] = useLazyGetHistoryMessagesQuery();
const [loadMoreDmMsgs] = useLazyGetDMHistoryMsg();
const listRef = useRef<number[]>([]);
@@ -83,7 +87,7 @@ export default function useMessageFeed({ context = "channel", id = null }) {
}
}, [items, context, id]);
useEffect(() => {
const serverMids = mids.filter((id) => {
const serverMids = mids.filter((id: number) => {
const ts = +new Date();
return Math.abs(ts - id) > 10 * 1000;
});
+3 -3
View File
@@ -15,15 +15,15 @@ export default function usePinMessage(cid: number) {
const [unpin, { isError: isUnpinError, isLoading: isUnpinning, isSuccess: isUnpinSuccess }] =
useUnpinMessageMutation();
const pinMessage = (mid: number) => {
if (!mid || !cid) return;
if (!mid) return;
pin({ mid, gid: +cid });
};
const unpinMessage = (mid: number) => {
if (!mid || !cid) return;
if (!mid) return;
unpin({ mid, gid: +cid });
};
const getPinInfo = (mid: number) => {
if (!cid || !channel) return;
if (!channel) return;
const pins = channel.pinned_messages;
if (!pins || pins.length == 0) return;
const pinned = pins.find((p) => p.mid == mid);