diff --git a/src/views/navigator/common/RoomSettingsData.ts b/src/views/navigator/common/RoomSettingsData.ts index 35fec6f6..7144458f 100644 --- a/src/views/navigator/common/RoomSettingsData.ts +++ b/src/views/navigator/common/RoomSettingsData.ts @@ -20,7 +20,6 @@ export default class RoomSettingsData public allowPetsEat: boolean; public usersWithRights: Map; - public friends: Map; public hideWalls: boolean; public wallThickness: number; @@ -59,7 +58,6 @@ export default class RoomSettingsData this.allowPetsEat = parser.allowPetsEat; this.usersWithRights = new Map(); - this.friends = new Map(); this.hideWalls = parser.hideWalls; this.wallThickness = parser.thicknessWall; @@ -74,26 +72,5 @@ export default class RoomSettingsData this.kickState = parser.moderationSettings.allowKick; this.banState = parser.moderationSettings.allowBan; this.bannedUsers = new Map(); - this.selectedUserToUnban = 0; - } - - public selectUserToUnban(userId: number): void - { - if(this.selectedUserToUnban === userId) - { - this.selectedUserToUnban = 0; - } - else - { - this.selectedUserToUnban = userId; - } - } - - public get selectedUsernameToUnban(): string - { - if(this.selectedUserToUnban > 0) - return this.bannedUsers.get(this.selectedUserToUnban); - - return null; } } diff --git a/src/views/navigator/views/room-settings/NavigatorRoomSettingsView.tsx b/src/views/navigator/views/room-settings/NavigatorRoomSettingsView.tsx index c2669b83..385a0a4f 100644 --- a/src/views/navigator/views/room-settings/NavigatorRoomSettingsView.tsx +++ b/src/views/navigator/views/room-settings/NavigatorRoomSettingsView.tsx @@ -1,5 +1,5 @@ import { RoomBannedUsersComposer, RoomBannedUsersEvent, RoomSettingsEvent, RoomUsersWithRightsComposer, RoomUsersWithRightsEvent, SaveRoomSettingsComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; +import { FC, useCallback, useEffect, useState } from 'react'; import { LocalizeText } from '../../../../api'; import { FriendListEvent } from '../../../../events'; import { FriendListContentEvent } from '../../../../events/friend-list/FriendListContentEvent'; @@ -25,6 +25,7 @@ export const NavigatorRoomSettingsView: FC<{}> = props => { const [ roomSettingsData, setRoomSettingsData ] = useState(null); const [ currentTab, setCurrentTab ] = useState(TABS[0]); + const [ friends, setFriends ] = useState>(new Map()); const updateSettings = useCallback((roomSettings: RoomSettingsData) => { @@ -55,8 +56,6 @@ export const NavigatorRoomSettingsView: FC<{}> = props => data.usersWithRights = new Map(parser.users); setRoomSettingsData(data); - - dispatchUiEvent(new FriendListEvent(FriendListEvent.REQUEST_FRIEND_LIST)); }, [roomSettingsData]); const onRoomBannedUsersEvent = useCallback((event: RoomBannedUsersEvent) => @@ -76,13 +75,9 @@ export const NavigatorRoomSettingsView: FC<{}> = props => const onFriendsListContentEvent = useCallback((event: FriendListContentEvent) => { - if(!roomSettingsData) return; + if(!roomSettingsData || !event.friends) return; - const clone = Object.assign({}, roomSettingsData); - - clone.friends = event.friends; - - setRoomSettingsData(clone); + setFriends(event.friends); }, [roomSettingsData]); CreateMessageHook(RoomSettingsEvent, onRoomSettingsEvent); @@ -90,6 +85,11 @@ export const NavigatorRoomSettingsView: FC<{}> = props => CreateMessageHook(RoomBannedUsersEvent, onRoomBannedUsersEvent); useUiEvent(FriendListContentEvent.FRIEND_LIST_CONTENT, onFriendsListContentEvent); + useEffect(() => + { + if(roomSettingsData) dispatchUiEvent(new FriendListEvent(FriendListEvent.REQUEST_FRIEND_LIST)); + }, [roomSettingsData]) + const save = useCallback((data: RoomSettingsData) => { SendMessageHook( @@ -146,7 +146,7 @@ export const NavigatorRoomSettingsView: FC<{}> = props => { currentTab === TABS[0] && } { currentTab === TABS[1] && } - { currentTab === TABS[2] && } + { currentTab === TABS[2] && } { currentTab === TABS[3] && } { currentTab === TABS[4] && } diff --git a/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.tsx b/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.tsx index 4b63cc4d..f91a328f 100644 --- a/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.tsx +++ b/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.tsx @@ -3,11 +3,11 @@ import { FC, useCallback, useMemo } from 'react'; import { LocalizeText } from '../../../../../../api'; import { SendMessageHook } from '../../../../../../hooks'; import { UserProfileIconView } from '../../../../../shared/user-profile-icon/UserProfileIconView'; -import { NavigatorRoomSettingsTabViewProps } from '../../NavigatorRoomSettingsView.types'; +import { NavigatorRoomSettingsRightsTabViewProps } from './NavigatorRoomSettingsRightsTabView.types'; -export const NavigatorRoomSettingsRightsTabView: FC = props => +export const NavigatorRoomSettingsRightsTabView: FC = props => { - const { roomSettingsData = null, setRoomSettingsData = null, onSave = null } = props; + const { roomSettingsData = null, setRoomSettingsData = null, onSave = null, friends = null } = props; const removeUserRights = useCallback( (userId: number) => { @@ -43,14 +43,14 @@ export const NavigatorRoomSettingsRightsTabView: FC(); - roomSettingsData.friends.forEach((name, id) => + friends.forEach((name, id) => { if(!roomSettingsData.usersWithRights.has(id)) map.set(id, name); }); return map; - }, [roomSettingsData]); + }, [friends, roomSettingsData]); return (
diff --git a/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.types.ts b/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.types.ts new file mode 100644 index 00000000..496eaf2a --- /dev/null +++ b/src/views/navigator/views/room-settings/views/tab-rights/NavigatorRoomSettingsRightsTabView.types.ts @@ -0,0 +1,6 @@ +import { NavigatorRoomSettingsTabViewProps } from '../../NavigatorRoomSettingsView.types'; + +export interface NavigatorRoomSettingsRightsTabViewProps extends NavigatorRoomSettingsTabViewProps +{ + friends: Map; +}