mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 13:26:27 +01:00
Enhancement - Room settings rights
This commit is contained in:
parent
9693bcae0b
commit
a7de317f49
@ -1,8 +1,8 @@
|
|||||||
import { FlatControllerAddedEvent, FlatControllerRemovedEvent, FlatControllersEvent, RemoveAllRightsMessageComposer, RoomTakeRightsComposer, RoomUsersWithRightsComposer } from '@nitrots/nitro-renderer';
|
import { FlatControllerAddedEvent, FlatControllerRemovedEvent, FlatControllersEvent, RemoveAllRightsMessageComposer, RoomGiveRightsComposer, RoomTakeRightsComposer, RoomUsersWithRightsComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useState } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
import { IRoomData, LocalizeText, SendMessageComposer } from '../../../../api';
|
import { IRoomData, LocalizeText, MessengerFriend, SendMessageComposer } from '../../../../api';
|
||||||
import { Button, Column, Flex, Grid, Text, UserProfileIconView } from '../../../../common';
|
import { Button, Column, Flex, Grid, Text, UserProfileIconView } from '../../../../common';
|
||||||
import { useMessageEvent } from '../../../../hooks';
|
import { useFriends, useMessageEvent } from '../../../../hooks';
|
||||||
|
|
||||||
interface NavigatorRoomSettingsTabViewProps
|
interface NavigatorRoomSettingsTabViewProps
|
||||||
{
|
{
|
||||||
@ -14,6 +14,7 @@ export const NavigatorRoomSettingsRightsTabView: FC<NavigatorRoomSettingsTabView
|
|||||||
{
|
{
|
||||||
const { roomData = null } = props;
|
const { roomData = null } = props;
|
||||||
const [ usersWithRights, setUsersWithRights ] = useState<Map<number, string>>(new Map());
|
const [ usersWithRights, setUsersWithRights ] = useState<Map<number, string>>(new Map());
|
||||||
|
const { friends = [] } = useFriends();
|
||||||
|
|
||||||
useMessageEvent<FlatControllersEvent>(FlatControllersEvent, event =>
|
useMessageEvent<FlatControllersEvent>(FlatControllersEvent, event =>
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ export const NavigatorRoomSettingsRightsTabView: FC<NavigatorRoomSettingsTabView
|
|||||||
newValue.delete(parser.userId);
|
newValue.delete(parser.userId);
|
||||||
|
|
||||||
return newValue;
|
return newValue;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
@ -61,6 +62,8 @@ export const NavigatorRoomSettingsRightsTabView: FC<NavigatorRoomSettingsTabView
|
|||||||
SendMessageComposer(new RoomUsersWithRightsComposer(roomData.roomId));
|
SendMessageComposer(new RoomUsersWithRightsComposer(roomData.roomId));
|
||||||
}, [ roomData.roomId ]);
|
}, [ roomData.roomId ]);
|
||||||
|
|
||||||
|
const friendsWithoutRights = friends.map( (friend: MessengerFriend) => friend ).filter(friend => friend.id !== -1 && !Array.from(usersWithRights.keys()).includes(friend.id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid>
|
<Grid>
|
||||||
<Column size={ 6 }>
|
<Column size={ 6 }>
|
||||||
@ -73,18 +76,36 @@ export const NavigatorRoomSettingsRightsTabView: FC<NavigatorRoomSettingsTabView
|
|||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<Flex key={ index } shrink alignItems="center" gap={ 1 } overflow="hidden">
|
<Flex key={ index } shrink alignItems="center" gap={ 1 } overflow="hidden">
|
||||||
<UserProfileIconView userName={ name } />
|
<UserProfileIconView userId={ id } />
|
||||||
<Text pointer grow onClick={ event => SendMessageComposer(new RoomTakeRightsComposer(id)) }> { name }</Text>
|
<Text pointer grow onClick={ event => SendMessageComposer(new RoomTakeRightsComposer(id)) }> { name }</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}) }
|
}) }
|
||||||
</Column>
|
</Column>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
<Column>
|
||||||
|
<Button variant="danger" disabled={ !usersWithRights.size } onClick={ event => SendMessageComposer(new RemoveAllRightsMessageComposer(roomData.roomId)) } >
|
||||||
|
{ LocalizeText('navigator.flatctrls.clear') }
|
||||||
|
</Button>
|
||||||
|
</Column>
|
||||||
</Column>
|
</Column>
|
||||||
<Column size={ 6 } justifyContent="end">
|
<Column size={ 6 }>
|
||||||
<Button variant="danger" disabled={ !usersWithRights.size } onClick={ event => SendMessageComposer(new RemoveAllRightsMessageComposer(roomData.roomId)) } >
|
<Text bold>
|
||||||
{ LocalizeText('navigator.flatctrls.clear') }
|
{ LocalizeText('navigator.flatctrls.friends', [ 'displayed', 'total' ], [ friendsWithoutRights.length.toString(), friendsWithoutRights.length.toString() ]) }
|
||||||
</Button>
|
</Text>
|
||||||
|
<Flex overflow="hidden" className="bg-white rounded list-container p-2">
|
||||||
|
<Column fullWidth overflow="auto" gap={ 1 }>
|
||||||
|
{ friendsWithoutRights && friendsWithoutRights.map((friend: MessengerFriend, index) =>
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
<Flex key={ index } shrink alignItems="center" gap={ 1 } overflow="hidden">
|
||||||
|
<UserProfileIconView userId={ friend.id } />
|
||||||
|
<Text pointer grow onClick={ event => SendMessageComposer(new RoomGiveRightsComposer(friend.id)) }> { friend.name }</Text>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
}) }
|
||||||
|
</Column>
|
||||||
|
</Flex>
|
||||||
</Column>
|
</Column>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user