fix: can not send new message at new channel
This commit is contained in:
@@ -1,46 +1,33 @@
|
||||
import { useRef, useEffect } from "react";
|
||||
// import { useDebounce } from "rooks";
|
||||
function useChatScroll(dep) {
|
||||
function useChatScroll(deps = []) {
|
||||
const ref = useRef();
|
||||
// const updateScrollTop = useDebounce(() => {
|
||||
// console.log("chat scroll", ref);
|
||||
// if (ref.current) {
|
||||
// setTimeout(() => {
|
||||
// ref.current.scrollTop = ref.current.scrollHeight;
|
||||
// }, 50);
|
||||
// }
|
||||
// }, 100);
|
||||
// const updateScrollTop = () => {
|
||||
// console.log("chat scroll", ref);
|
||||
// if (ref.current) {
|
||||
// setTimeout(() => {
|
||||
// ref.current.scrollTop = ref.current.scrollHeight;
|
||||
// }, 100);
|
||||
// }
|
||||
// };
|
||||
useEffect(() => {
|
||||
console.log("chat scroll", ref);
|
||||
if (ref.current) {
|
||||
// setTimeout(() => {
|
||||
if (ref.current) {
|
||||
ref.current.scrollTop = ref.current.scrollHeight;
|
||||
}
|
||||
// }, 20);
|
||||
}
|
||||
}, [dep]);
|
||||
// useEffect(() => {
|
||||
// console.log("chat scroll", ref);
|
||||
// if (ref.current) {
|
||||
// const ele = ref.current;
|
||||
// const resizeObserver = new ResizeObserver((entries) => {
|
||||
// for (let entry of entries) {
|
||||
// entry.target.scrollTop = entry.target.scrollHeight;
|
||||
// }
|
||||
// });
|
||||
|
||||
// resizeObserver.observe(ele);
|
||||
// // setTimeout(() => {
|
||||
// if (ref.current) {
|
||||
// setTimeout(() => {
|
||||
// ref.current.scrollTop = ref.current.scrollHeight;
|
||||
// }, 500);
|
||||
// }
|
||||
// // }, 20);
|
||||
// }
|
||||
// }, []);
|
||||
// }, [...deps]);
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
console.log("chat scroll", ref);
|
||||
const ele = ref.current;
|
||||
const resizeObserver = new ResizeObserver((entries) => {
|
||||
for (let entry of entries) {
|
||||
console.log("update scroll top");
|
||||
entry.target.scrollTop = entry.target.scrollHeight;
|
||||
}
|
||||
});
|
||||
|
||||
resizeObserver.observe(ele);
|
||||
}
|
||||
}, []);
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,18 +76,25 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
}
|
||||
}, [items, context, id]);
|
||||
useEffect(() => {
|
||||
if (listRef.current.length == 0 && mids.length) {
|
||||
const serverMids = mids.filter((id) => {
|
||||
const ts = new Date().getTime();
|
||||
return Math.abs(ts - id) > 5 * 1000;
|
||||
});
|
||||
if (listRef.current.length == 0 && serverMids.length) {
|
||||
// 初次
|
||||
const pageInfo = getFeedWithPagination({ mids, isLast: true });
|
||||
const pageInfo = getFeedWithPagination({
|
||||
mids: serverMids,
|
||||
isLast: true,
|
||||
});
|
||||
console.log("pull up 2", pageInfo);
|
||||
pageRef.current = pageInfo;
|
||||
listRef.current = pageInfo.ids;
|
||||
setItems(listRef.current);
|
||||
console.log("message pageInfo", mids, pageInfo);
|
||||
console.log("message pageInfo", serverMids, pageInfo);
|
||||
} else {
|
||||
// 追加
|
||||
const lastMid = listRef.current.slice(-1);
|
||||
const sorteds = mids.slice(0).sort((a, b) => {
|
||||
const sorteds = serverMids.slice(0).sort((a, b) => {
|
||||
return Number(a) - Number(b);
|
||||
});
|
||||
const appends = sorteds.filter((s) => s > lastMid);
|
||||
|
||||
Reference in New Issue
Block a user