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