pleroma/app/soapbox/features/status/components/thread-status.tsx

55 lines
1.7 KiB
TypeScript
Raw Normal View History

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
contextType?: string
focusedStatusId: string
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
className={clsx('absolute left-5 z-[1] hidden w-0.5 bg-gray-200 rtl:left-auto rtl:right-5 dark:bg-primary-800', {
'!block top-[calc(12px+42px)] h-[calc(100%-42px-8px-1rem)]': isConnectedBottom,
2022-04-04 13:20:17 -07:00
})}
/>
);
};
return (
<div className='thread__status'>
{renderConnector()}
{isLoaded ? (
// @ts-ignore FIXME
2023-04-26 06:46:31 -07:00
<StatusContainer {...props} showGroup={false} />
2022-04-04 13:20:17 -07:00
) : (
2023-05-03 08:13:47 -07:00
<PlaceholderStatus variant='default' />
2022-04-04 13:20:17 -07:00
)}
</div>
);
};
export default ThreadStatus;