diff --git a/src/components/structures/ThreadPanel.tsx b/src/components/structures/ThreadPanel.tsx index 51990a739d0..3b067045612 100644 --- a/src/components/structures/ThreadPanel.tsx +++ b/src/components/structures/ThreadPanel.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { Optional } from "matrix-events-sdk"; import React, { useContext, useEffect, useRef, useState } from "react"; import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set"; import { Thread } from "matrix-js-sdk/src/models/thread"; @@ -215,9 +216,12 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => const [filterOption, setFilterOption] = useState(ThreadFilterType.All); const [room, setRoom] = useState(null); - const [timelineSet, setTimelineSet] = useState(null); const [narrow, setNarrow] = useState(false); + const timelineSet: Optional = + filterOption === ThreadFilterType.My ? room?.threadsTimelineSets[1] : room?.threadsTimelineSets[0]; + const hasThreads = room?.threadsTimelineSets[0]?.getLiveTimeline()?.getEvents()?.length > 0; + useEffect(() => { const room = mxClient.getRoom(roomId); room.createThreadsTimelineSets() @@ -230,16 +234,6 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => }); }, [mxClient, roomId]); - useEffect(() => { - if (room) { - if (filterOption === ThreadFilterType.My) { - setTimelineSet(room.threadsTimelineSets[1]); - } else { - setTimelineSet(room.threadsTimelineSets[0]); - } - } - }, [room, filterOption]); - useEffect(() => { if (timelineSet && !Thread.hasServerSideSupport) { timelinePanel.current.refreshTimeline(); @@ -268,7 +262,7 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => } footer={ @@ -315,7 +309,7 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => showUrlPreview={false} // No URL previews at the threads list level empty={ 0} + hasThreads={hasThreads} filterOption={filterOption} showAllThreadsCallback={() => setFilterOption(ThreadFilterType.All)} />