mirror of https://github.com/msgbyte/tailchat
feat: add message list popover for DM and group
parent
693edf2739
commit
704c05e0ec
@ -0,0 +1,40 @@
|
||||
import { fetchImagePrimaryColor } from '@/utils/image-helper';
|
||||
import { Space, Tag } from 'antd';
|
||||
import React, { useEffect } from 'react';
|
||||
import { t, UserBaseInfo } from 'tailchat-shared';
|
||||
import { UserProfileContainer } from '../../UserProfileContainer';
|
||||
import { usePluginUserExtraInfo } from './usePluginUserExtraInfo';
|
||||
|
||||
export const PersonalUserPopover: React.FC<{
|
||||
userInfo: UserBaseInfo;
|
||||
}> = React.memo((props) => {
|
||||
const { userInfo } = props;
|
||||
const userExtra = userInfo.extra ?? {};
|
||||
const pluginUserExtraInfoEl = usePluginUserExtraInfo(userExtra);
|
||||
|
||||
useEffect(() => {
|
||||
if (userInfo.avatar) {
|
||||
fetchImagePrimaryColor(userInfo.avatar).then((rgba) => {
|
||||
console.log('fetchImagePrimaryColor', rgba);
|
||||
});
|
||||
}
|
||||
}, [userInfo.avatar]);
|
||||
|
||||
return (
|
||||
<div className="w-80 -mx-4 -my-3 bg-inherit">
|
||||
<UserProfileContainer userInfo={userInfo}>
|
||||
<div className="text-xl">
|
||||
<span className="font-semibold">{userInfo.nickname}</span>
|
||||
<span className="opacity-60 ml-1">#{userInfo.discriminator}</span>
|
||||
</div>
|
||||
|
||||
<Space size={4} wrap={true} className="py-1">
|
||||
{userInfo.temporary && <Tag color="processing">{t('游客')}</Tag>}
|
||||
</Space>
|
||||
|
||||
<div className="pt-2">{pluginUserExtraInfoEl}</div>
|
||||
</UserProfileContainer>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
PersonalUserPopover.displayName = 'PersonalUserPopover';
|
@ -0,0 +1,23 @@
|
||||
import { useGroupIdContext } from '@/context/GroupIdContext';
|
||||
import React from 'react';
|
||||
import { useGroupInfo, UserBaseInfo } from 'tailchat-shared';
|
||||
import { GroupUserPopover } from './GroupUserPopover';
|
||||
import { PersonalUserPopover } from './PersonalUserPopover';
|
||||
|
||||
/**
|
||||
* Common Entry for User Popover
|
||||
*/
|
||||
export const UserPopover: React.FC<{
|
||||
userInfo: UserBaseInfo;
|
||||
}> = React.memo((props) => {
|
||||
const groupId = useGroupIdContext();
|
||||
const groupInfo = useGroupInfo(groupId);
|
||||
|
||||
if (groupInfo) {
|
||||
return <GroupUserPopover userInfo={props.userInfo} groupInfo={groupInfo} />;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return <PersonalUserPopover userInfo={props.userInfo} />;
|
||||
});
|
||||
UserPopover.displayName = 'UserPopover';
|
@ -0,0 +1,28 @@
|
||||
import { pluginUserExtraInfo } from '@/plugin/common';
|
||||
import React from 'react';
|
||||
|
||||
export function usePluginUserExtraInfo(
|
||||
userExtra: Record<string, unknown> = {}
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
{pluginUserExtraInfo.map((item, i) => {
|
||||
const Component = item.component?.render;
|
||||
if (Component) {
|
||||
// 自定义渲染方式
|
||||
return <Component key={item.name + i} value={userExtra[item.name]} />;
|
||||
}
|
||||
|
||||
// 默认渲染方式
|
||||
return (
|
||||
<div key={item.name + i} className="flex">
|
||||
<div className="w-1/4 text-gray-500">{item.label}:</div>
|
||||
<div className="w-3/4">
|
||||
{userExtra[item.name] ? String(userExtra[item.name]) : ''}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue