mirror of https://github.com/msgbyte/tailchat
feat: 群组自动选择第一个可用面板
parent
7f631544ce
commit
0feea9c465
@ -0,0 +1,28 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { useHistory, useParams } from 'react-router';
|
||||||
|
import { GroupPanelType, useGroupInfo } from 'tailchat-shared';
|
||||||
|
import _isNil from 'lodash/isNil';
|
||||||
|
|
||||||
|
export const GroupPanelRedirect: React.FC = React.memo(() => {
|
||||||
|
const { groupId } = useParams<{
|
||||||
|
groupId: string;
|
||||||
|
}>();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const groupInfo = useGroupInfo(groupId);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!Array.isArray(groupInfo?.panels) || groupInfo?.panels.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstAvailablePanel = groupInfo?.panels.find(
|
||||||
|
(panel) => panel.type !== GroupPanelType.GROUP
|
||||||
|
);
|
||||||
|
if (!_isNil(firstAvailablePanel)) {
|
||||||
|
history.replace(`/main/group/${groupId}/${firstAvailablePanel.id}`);
|
||||||
|
}
|
||||||
|
}, [groupInfo]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
GroupPanelRedirect.displayName = 'GroupPanelRedirect';
|
Loading…
Reference in New Issue