refactor: load more in msg feed

This commit is contained in:
Tristan Yang
2023-03-09 11:32:44 +08:00
parent 384de7c8df
commit 3af4cab880
8 changed files with 171 additions and 181 deletions
+4 -46
View File
@@ -1,11 +1,8 @@
// import { useState, useEffect } from "react";
// import { NavLink } from "react-router-dom";
import { useTranslation } from "react-i18next";
import useMessageFeed from "../../../common/hook/useMessageFeed";
// import { useTranslation } from "react-i18next";
import ChannelIcon from "../../../common/component/ChannelIcon";
import Layout from "../Layout";
import { renderMessageFragment } from "../utils";
import LoadMore from "../LoadMore";
import { useAppSelector } from "../../../app/store";
import GoBackNav from "../../../common/component/GoBackNav";
@@ -13,27 +10,14 @@ type Props = {
cid?: number;
};
export default function GuestChannelChat({ cid = 0 }: Props) {
const { t } = useTranslation("chat");
const {
list: msgIds,
appends,
hasMore,
pullUp,
pulling
} = useMessageFeed({
context: "channel",
id: cid
});
const { data, messageData } = useAppSelector((store) => {
// const { t } = useTranslation("chat");
const { data } = useAppSelector((store) => {
return {
footprint: store.footprint,
data: store.channels.byId[cid],
messageData: store.message || {}
};
});
if (!data) return null;
const { name, description, is_public } = data;
const feeds = [...msgIds, ...appends];
return (
<Layout
readonly
@@ -49,32 +33,6 @@ export default function GuestChannelChat({ cid = 0 }: Props) {
</div>
</header>
}
>
<>
{hasMore ? (
<LoadMore pullUp={pullUp} pulling={pulling} />
) : (
<div className="pt-14 flex flex-col items-start gap-2">
<h2 className="font-bold text-4xl dark:text-white">{t("welcome_channel", { name })}</h2>
<p className="text-gray-600 dark:text-gray-300">{t("welcome_desc", { name })} </p>
</div>
)}
{/* <div className="feed"> */}
{feeds.map((mid, idx) => {
const curr = messageData[mid];
if (!curr) return null;
const isFirst = idx == 0;
const prev = isFirst ? null : messageData[feeds[idx - 1]];
return renderMessageFragment({
readonly: true,
selectMode: false,
prev,
curr,
contextId: cid,
context: "channel"
});
})}
</>
</Layout>
/>
);
}