- ) => {
+ if (data[index].type === 'search') {
+ return 'search';
+ } else if (data[index].type === 'empty') {
+ return 'empty';
+ } else {
+ return data[index].threadInfo.id;
+ }
+};
+
+const renderItem = ({ index, data, style }) => {
+ let item;
+ if (data[index].type === 'search') {
+ item = ;
+ } else if (data[index].type === 'empty') {
+ item = ;
+ } else {
+ item = ;
+ }
+
+ return
{item}
;
+};
+
function ChatThreadList(): React.Node {
const threadListContext = React.useContext(ThreadListContext);
invariant(
threadListContext,
'threadListContext should be set in ChatThreadList',
);
- const { activeTab, threadList, setSearchText, searchText } =
- threadListContext;
+ const { activeTab, threadList } = threadListContext;
const onClickNewThread = useOnClickNewThread();
@@ -33,31 +68,66 @@
const communityID = useSelector(state => state.communityPickerStore.chat);
- const threadComponents: React.Node[] = React.useMemo(() => {
- const threads = threadList
- .filter(
+ const threadListContainerRef = React.useRef();
+
+ const threads = React.useMemo(
+ () =>
+ threadList.filter(
item =>
!communityID ||
item.threadInfo.community === communityID ||
item.threadInfo.id === communityID,
- )
- .map(item => );
- if (threads.length === 0 && isBackground) {
- threads.push();
+ ),
+ [communityID, threadList],
+ );
+
+ React.useEffect(() => {
+ if (threadListContainerRef.current) {
+ threadListContainerRef.current.resetAfterIndex(0, false);
}
- return threads;
- }, [threadList, isBackground, communityID]);
+ }, [threads]);
+
+ const threadListContainer = React.useMemo(() => {
+ const items: Item[] = [{ type: 'search' }, ...threads];
+
+ if (isBackground && threads.length === 0) {
+ items.push({ type: 'empty' });
+ }
+
+ const itemSize = index => {
+ if (items[index].type === 'search') {
+ return sizes.search;
+ } else if (items[index].type === 'empty') {
+ return sizes.empty;
+ }
+
+ const sidebarHeight = _sum(
+ items[index].sidebars.map(s => sizes.sidebars[s.type]),
+ );
+ return sizes.thread + sidebarHeight;
+ };
+
+ return (
+
+ {({ height }) => (
+
+ {renderItem}
+
+ )}
+
+ );
+ }, [isBackground, threads]);
return (
<>
-
+ {threadListContainer}