2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-04-04 13:20:17 -07:00
|
|
|
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
|
|
|
import React from 'react';
|
|
|
|
|
2022-11-15 08:13:54 -08:00
|
|
|
import StatusContainer from 'soapbox/containers/status-container';
|
2022-11-15 11:00:40 -08:00
|
|
|
import PlaceholderStatus from 'soapbox/features/placeholder/components/placeholder-status';
|
2022-04-04 13:20:17 -07:00
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
interface IThreadStatus {
|
|
|
|
id: string,
|
2023-02-07 06:38:31 -08:00
|
|
|
contextType?: string,
|
2022-04-04 13:20:17 -07:00
|
|
|
focusedStatusId: string,
|
2022-08-12 14:21:44 -07:00
|
|
|
onMoveUp: (id: string) => void,
|
|
|
|
onMoveDown: (id: string) => void,
|
2022-04-04 13:20:17 -07:00
|
|
|
}
|
|
|
|
|
2022-05-13 13:02:20 -07:00
|
|
|
/** Status with reply-connector in threads. */
|
2022-04-04 13:20:17 -07:00
|
|
|
const ThreadStatus: React.FC<IThreadStatus> = (props): JSX.Element => {
|
|
|
|
const { id, focusedStatusId } = props;
|
|
|
|
|
2022-05-13 13:02:20 -07:00
|
|
|
const replyToId = useAppSelector(state => state.contexts.inReplyTos.get(id));
|
|
|
|
const replyCount = useAppSelector(state => state.contexts.replies.get(id, ImmutableOrderedSet()).size);
|
2022-04-04 13:20:17 -07:00
|
|
|
const isLoaded = useAppSelector(state => Boolean(state.statuses.get(id)));
|
|
|
|
|
|
|
|
const renderConnector = (): JSX.Element | null => {
|
|
|
|
const isConnectedTop = replyToId && replyToId !== focusedStatusId;
|
|
|
|
const isConnectedBottom = replyCount > 0;
|
|
|
|
const isConnected = isConnectedTop || isConnectedBottom;
|
|
|
|
|
|
|
|
if (!isConnected) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx('thread__connector', {
|
2022-04-04 13:20:17 -07:00
|
|
|
'thread__connector--top': isConnectedTop,
|
|
|
|
'thread__connector--bottom': isConnectedBottom,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='thread__status'>
|
|
|
|
{renderConnector()}
|
|
|
|
{isLoaded ? (
|
|
|
|
// @ts-ignore FIXME
|
|
|
|
<StatusContainer {...props} />
|
|
|
|
) : (
|
|
|
|
<PlaceholderStatus thread />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ThreadStatus;
|