2020-05-13 02:16:43 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-05-13 02:16:43 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-05-13 02:16:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2020-07-28 11:53:43 -06:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2021-06-29 13:11:58 +01:00
|
|
|
import Draggable, { ILocationState } from "./Draggable";
|
2020-07-28 11:53:43 -06:00
|
|
|
import { SettingLevel } from "../../../settings/SettingLevel";
|
2020-05-13 02:16:43 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
// Current room
|
2023-04-17 09:25:00 +01:00
|
|
|
roomId: string | null;
|
2020-06-18 14:32:43 +01:00
|
|
|
minWidth: number;
|
|
|
|
|
maxWidth: number;
|
|
|
|
|
}
|
2020-05-13 02:16:43 +01:00
|
|
|
|
|
|
|
|
interface IState {
|
2020-06-18 14:32:43 +01:00
|
|
|
width: number;
|
2023-03-13 15:07:20 +00:00
|
|
|
IRCLayoutRoot: HTMLElement | null;
|
2020-06-18 14:32:43 +01:00
|
|
|
}
|
2020-05-13 02:16:43 +01:00
|
|
|
|
|
|
|
|
export default class IRCTimelineProfileResizer extends React.Component<IProps, IState> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2020-05-13 02:16:43 +01:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
width: SettingsStore.getValue("ircDisplayNameWidth", this.props.roomId),
|
|
|
|
|
IRCLayoutRoot: null,
|
2020-06-18 14:32:43 +01:00
|
|
|
};
|
|
|
|
|
}
|
2020-05-13 02:16:43 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2020-05-13 02:16:43 +01:00
|
|
|
this.setState(
|
|
|
|
|
{
|
2022-05-03 22:04:37 +01:00
|
|
|
IRCLayoutRoot: document.querySelector(".mx_IRCLayout"),
|
2020-06-18 14:32:43 +01:00
|
|
|
},
|
|
|
|
|
() => this.updateCSSWidth(this.state.width),
|
|
|
|
|
);
|
2020-05-13 02:16:43 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 11:24:59 +00:00
|
|
|
private dragFunc = (location: ILocationState, event: MouseEvent): ILocationState => {
|
2020-05-13 02:16:43 +01:00
|
|
|
const offset = event.clientX - location.currentX;
|
|
|
|
|
const newWidth = this.state.width + offset;
|
|
|
|
|
|
|
|
|
|
// If we're trying to go smaller than min width, don't.
|
2020-05-13 14:04:46 +01:00
|
|
|
if (newWidth < this.props.minWidth) {
|
2020-05-13 02:16:43 +01:00
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 14:04:46 +01:00
|
|
|
if (newWidth > this.props.maxWidth) {
|
2020-05-13 02:16:43 +01:00
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
width: newWidth,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.updateCSSWidth.bind(this)(newWidth);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
currentX: event.clientX,
|
|
|
|
|
currentY: location.currentY,
|
2020-06-18 14:32:43 +01:00
|
|
|
};
|
|
|
|
|
};
|
2020-05-13 02:16:43 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private updateCSSWidth(newWidth: number): void {
|
2023-03-13 15:07:20 +00:00
|
|
|
this.state.IRCLayoutRoot?.style.setProperty("--name-width", newWidth + "px");
|
2020-05-13 02:16:43 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onMoueUp = (): void => {
|
2020-05-18 16:37:10 +01:00
|
|
|
if (this.props.roomId) {
|
2020-08-29 01:11:08 +01:00
|
|
|
SettingsStore.setValue(
|
|
|
|
|
"ircDisplayNameWidth",
|
|
|
|
|
this.props.roomId,
|
|
|
|
|
SettingLevel.ROOM_DEVICE,
|
|
|
|
|
this.state.width,
|
|
|
|
|
);
|
2020-05-18 16:37:10 +01:00
|
|
|
}
|
2022-11-21 11:24:59 +00:00
|
|
|
};
|
2020-05-13 02:16:43 +01:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2020-06-18 14:32:43 +01:00
|
|
|
return <Draggable className="mx_ProfileResizer" dragFunc={this.dragFunc} onMouseUp={this.onMoueUp} />;
|
2020-05-13 02:16:43 +01:00
|
|
|
}
|
2020-06-18 14:32:43 +01:00
|
|
|
}
|