/* eslint-disable react/destructuring-assignment */ import React, { forwardRef, useMemo } from 'react'; import { EventTimelineSet, Room } from 'matrix-js-sdk'; import { Box, config, Header, Icon, IconButton, Icons, Menu, Scroll, Text, toRem } from 'folds'; import * as css from './ThreadsMenu.css'; import { ContainerColor } from '../../../styles/ContainerColor.css'; import { useRoomMyThreads } from '../../../hooks/useRoomThreads'; import { AsyncStatus } from '../../../hooks/useAsyncCallback'; import { getLinkedTimelines, getTimelinesEventsCount } from '../utils'; import { ThreadsTimeline } from './ThreadsTimeline'; import { ThreadsLoading } from './ThreadsLoading'; import { ThreadsError } from './ThreadsError'; const getTimelines = (timelineSet: EventTimelineSet) => { const liveTimeline = timelineSet.getLiveTimeline(); const linkedTimelines = getLinkedTimelines(liveTimeline); return linkedTimelines; }; function NoThreads() { return ( No Threads Yet Threads you’re participating in will appear here. ); } type ThreadsMenuProps = { room: Room; requestClose: () => void; }; export const ThreadsMenu = forwardRef( ({ room, requestClose }, ref) => { const threadsState = useRoomMyThreads(room); const threadsTimelineSet = threadsState.status === AsyncStatus.Success ? threadsState.data : undefined; const linkedTimelines = useMemo(() => { if (!threadsTimelineSet) return undefined; return getTimelines(threadsTimelineSet); }, [threadsTimelineSet]); const hasEvents = linkedTimelines && getTimelinesEventsCount(linkedTimelines) > 0; return (
My Threads
{threadsState.status === AsyncStatus.Success && hasEvents ? ( ) : ( {(threadsState.status === AsyncStatus.Loading || threadsState.status === AsyncStatus.Idle) && } {threadsState.status === AsyncStatus.Success && !hasEvents && } {threadsState.status === AsyncStatus.Error && ( )} )}
); } );