2022-08-31 10:24:01 -07:00
|
|
|
import classNames from 'clsx';
|
2022-05-01 10:53:53 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-08-16 05:39:58 -07:00
|
|
|
import { HStack, Stack, Text } from 'soapbox/components/ui';
|
|
|
|
|
2022-08-16 13:35:06 -07:00
|
|
|
import { randomIntFromInterval } from '../utils';
|
2022-05-01 10:53:53 -07:00
|
|
|
|
2022-11-17 07:58:34 -08:00
|
|
|
import PlaceholderAvatar from './placeholder-avatar';
|
2022-05-01 10:53:53 -07:00
|
|
|
|
|
|
|
/** Fake chat to display while data is loading. */
|
2022-08-26 09:41:25 -07:00
|
|
|
const PlaceholderChatMessage = ({ isMyMessage = false }: { isMyMessage?: boolean }) => {
|
2022-08-16 05:39:58 -07:00
|
|
|
const messageLength = randomIntFromInterval(160, 220);
|
2022-05-01 10:53:53 -07:00
|
|
|
|
|
|
|
return (
|
2022-08-16 05:39:58 -07:00
|
|
|
<Stack
|
2022-09-12 11:42:15 -07:00
|
|
|
data-testid='placeholder-chat-message'
|
2022-08-16 05:39:58 -07:00
|
|
|
space={1}
|
|
|
|
className={classNames({
|
|
|
|
'max-w-[85%] animate-pulse': true,
|
|
|
|
'ml-auto': isMyMessage,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<HStack
|
|
|
|
alignItems='center'
|
|
|
|
justifyContent={isMyMessage ? 'end' : 'start'}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={
|
|
|
|
classNames({
|
|
|
|
'text-ellipsis break-words relative rounded-md p-2': true,
|
|
|
|
'mr-2': isMyMessage,
|
|
|
|
'order-2 ml-2': !isMyMessage,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div style={{ width: messageLength, height: 20 }} className='rounded-full bg-primary-50 dark:bg-primary-800' />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={classNames({ 'order-1': !isMyMessage })}>
|
|
|
|
<PlaceholderAvatar size={34} />
|
|
|
|
</div>
|
|
|
|
</HStack>
|
|
|
|
|
|
|
|
<HStack
|
|
|
|
alignItems='center'
|
|
|
|
space={2}
|
|
|
|
className={classNames({
|
|
|
|
'ml-auto': isMyMessage,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
theme='muted'
|
|
|
|
size='xs'
|
|
|
|
className={classNames({
|
|
|
|
'text-right': isMyMessage,
|
|
|
|
'order-2': !isMyMessage,
|
|
|
|
})}
|
|
|
|
>
|
2022-08-26 09:41:25 -07:00
|
|
|
<span style={{ width: 50, height: 12 }} className='rounded-full bg-primary-50 dark:bg-primary-800 block' />
|
2022-08-16 05:39:58 -07:00
|
|
|
</Text>
|
|
|
|
|
|
|
|
<div className={classNames({ 'order-1': !isMyMessage })}>
|
|
|
|
<div className='w-[34px] ml-2' />
|
2022-05-01 10:53:53 -07:00
|
|
|
</div>
|
2022-08-16 05:39:58 -07:00
|
|
|
</HStack>
|
|
|
|
</Stack>
|
2022-05-01 10:53:53 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-08-26 09:41:25 -07:00
|
|
|
export default PlaceholderChatMessage;
|