mirror of https://github.com/msgbyte/tailchat
feat: 增加仅允许指定用户发言的配置
parent
a0f3337ae0
commit
25beff5526
@ -0,0 +1,16 @@
|
|||||||
|
import { getCachedUserInfo } from '../../cache/cache';
|
||||||
|
import type { UserBaseInfo } from '../../model/user';
|
||||||
|
import { useAsync } from '../useAsync';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息列表
|
||||||
|
*/
|
||||||
|
export function useUserInfoList(userIds: string[] = []): UserBaseInfo[] {
|
||||||
|
const { value: userInfoList = [] } = useAsync(async () => {
|
||||||
|
const users = await Promise.all(userIds.map((id) => getCachedUserInfo(id)));
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}, [userIds.join(',')]);
|
||||||
|
|
||||||
|
return userInfoList;
|
||||||
|
}
|
||||||
@ -1,15 +1,10 @@
|
|||||||
import { getCachedUserInfo } from '../../cache/cache';
|
import { useUserInfoList } from './useUserInfoList';
|
||||||
import { useAsync } from '../useAsync';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名列表
|
* 用户名列表
|
||||||
*/
|
*/
|
||||||
export function useUsernames(userIds: string[]): string[] {
|
export function useUsernames(userIds: string[]): string[] {
|
||||||
const { value: names = [] } = useAsync(async () => {
|
const userInfoList = useUserInfoList(userIds);
|
||||||
const users = await Promise.all(userIds.map((id) => getCachedUserInfo(id)));
|
|
||||||
|
|
||||||
return users.map((user) => user.nickname);
|
return userInfoList.map((info) => info.nickname);
|
||||||
}, [userIds.join(',')]);
|
|
||||||
|
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
import { Select } from 'antd';
|
||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { t } from 'tailchat-shared';
|
||||||
|
import { useUserInfoList } from 'tailchat-shared/hooks/model/useUserInfoList';
|
||||||
|
|
||||||
|
interface UserSelectorProps {
|
||||||
|
allUserIds: string[];
|
||||||
|
userIds?: string[];
|
||||||
|
onChange?: (userIds: string[]) => void;
|
||||||
|
}
|
||||||
|
export const UserSelector: React.FC<UserSelectorProps> = React.memo((props) => {
|
||||||
|
const { allUserIds, userIds, onChange } = props;
|
||||||
|
const userInfoList = useUserInfoList(allUserIds);
|
||||||
|
|
||||||
|
const handleChange = useCallback(
|
||||||
|
(userIds: string[]) => {
|
||||||
|
typeof onChange === 'function' && onChange(userIds);
|
||||||
|
},
|
||||||
|
[onChange]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
mode="multiple"
|
||||||
|
allowClear={true}
|
||||||
|
placeholder={t('请选择用户')}
|
||||||
|
value={userIds}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{userInfoList.map((info) => (
|
||||||
|
<Select.Option key={info._id} value={info._id}>
|
||||||
|
{info.nickname}
|
||||||
|
</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
UserSelector.displayName = 'UserSelector';
|
||||||
Loading…
Reference in New Issue