refactor: more TS code
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user