You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/web/src/components/Panel/personal/ConversePanel.tsx

61 lines
1.7 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { ChatBox } from '@/components/ChatBox';
import React from 'react';
import { joinArray, Trans, useAppSelector, useUserId } from 'tailchat-shared';
import { PanelCommonHeader } from '../common/Header';
import _without from 'lodash/without';
import _take from 'lodash/take';
import { UserName } from '@/components/UserName';
function useConverseTitle(converseId: string): React.ReactNode {
const members = useAppSelector(
(state) => state.chat.converses[converseId]?.members ?? []
);
const userId = useUserId();
const otherMembers = _without<string>(members, userId ?? '');
const len = otherMembers.length;
if (len === 1) {
return (
<Trans>
<UserName userId={otherMembers[0]} />
</Trans>
);
} else if (len === 2) {
return (
<Trans>
<UserName userId={otherMembers[0]} /> {' '}
<UserName userId={otherMembers[1]} />
</Trans>
);
} else {
const membersEl = joinArray(
_take(otherMembers, 2).map((uid) => <UserName key={uid} userId={uid} />),
<span></span>
);
return (
<Trans>
<span>{{ membersEl }}</span>
</Trans>
);
}
}
interface ConversePanelProps {
converseId: string;
}
export const ConversePanel: React.FC<ConversePanelProps> = React.memo(
({ converseId }) => {
const title = useConverseTitle(converseId);
return (
<div className="flex flex-col overflow-hidden flex-1">
<PanelCommonHeader actions={[]}>{title}</PanelCommonHeader>
<div className="flex-1 overflow-hidden">
<ChatBox converseId={converseId} isGroup={false} />
</div>
</div>
);
}
);
ConversePanel.displayName = 'ConversePanel';