diff --git a/src/components/views/elements/PowerSelector.tsx b/src/components/views/elements/PowerSelector.tsx index f6e24f2bbb..a99812028e 100644 --- a/src/components/views/elements/PowerSelector.tsx +++ b/src/components/views/elements/PowerSelector.tsx @@ -33,7 +33,7 @@ interface IProps { // should the user be able to change the value? false by default. disabled?: boolean; - onChange?: (value: string, powerLevelKey: string) => void; + onChange?: (value: number, powerLevelKey: string) => void; // Optional key to pass as the second argument to `onChange` powerLevelKey?: string; @@ -111,8 +111,9 @@ export default class PowerSelector extends React.Component { if (isCustom) { this.setState({ custom: true }); } else { - this.props.onChange(event.target.value, this.props.powerLevelKey); - this.setState({ selectValue: parseInt(event.target.value) }); + const powerLevel = parseInt(event.target.value); + this.props.onChange(powerLevel, this.props.powerLevelKey); + this.setState({ selectValue: powerLevel }); } }; @@ -124,7 +125,7 @@ export default class PowerSelector extends React.Component { event.preventDefault(); event.stopPropagation(); - this.props.onChange(String(this.state.customValue), this.props.powerLevelKey); + this.props.onChange(this.state.customValue, this.props.powerLevelKey); }; private onCustomKeyDown = (event: React.KeyboardEvent): void => { diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index f1807985ae..3790fc3701 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -1052,8 +1052,7 @@ const PowerLevelEditor: React.FC<{ const cli = useContext(MatrixClientContext); const [selectedPowerLevel, setSelectedPowerLevel] = useState(user.powerLevel); - const onPowerChange = useCallback(async (powerLevelStr: string) => { - const powerLevel = parseInt(powerLevelStr, 10); + const onPowerChange = useCallback(async (powerLevel: number) => { setSelectedPowerLevel(powerLevel); const applyPowerChange = (roomId, target, powerLevel, powerLevelEvent) => { diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index d27910517d..f1179d38e5 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -137,7 +137,7 @@ export default class RolesRoomSettingsTab extends React.Component { } } - private onPowerLevelsChanged = (inputValue: string, powerLevelKey: string) => { + private onPowerLevelsChanged = (value: number, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents(EventType.RoomPowerLevels, ''); @@ -148,8 +148,6 @@ export default class RolesRoomSettingsTab extends React.Component { const eventsLevelPrefix = "event_levels_"; - const value = parseInt(inputValue); - if (powerLevelKey.startsWith(eventsLevelPrefix)) { // deep copy "events" object, Object.assign itself won't deep copy plContent["events"] = Object.assign({}, plContent["events"] || {}); @@ -181,7 +179,7 @@ export default class RolesRoomSettingsTab extends React.Component { }); }; - private onUserPowerLevelChanged = (value: string, powerLevelKey: string) => { + private onUserPowerLevelChanged = (value: number, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents(EventType.RoomPowerLevels, '');