fix(fe): hotkeys should not be enabled when component is not active
This commit is contained in:
parent
097b94d1ed
commit
8c508c517f
7 changed files with 52 additions and 21 deletions
|
@ -37,6 +37,9 @@ export class HotkeyHandler {
|
||||||
};
|
};
|
||||||
|
|
||||||
handle = (ev: KeyboardEvent) => {
|
handle = (ev: KeyboardEvent) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
|
||||||
const hotKey = {
|
const hotKey = {
|
||||||
key: ev.key,
|
key: ev.key,
|
||||||
ctrl: ev.ctrlKey,
|
ctrl: ev.ctrlKey,
|
||||||
|
|
|
@ -35,7 +35,8 @@ describe("Login", () => {
|
||||||
login: coreState.login,
|
login: coreState.login,
|
||||||
msg: coreState.msg,
|
msg: coreState.msg,
|
||||||
ui: coreState.ui,
|
ui: coreState.ui,
|
||||||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
enabled: true,
|
||||||
|
update: (updater: (prevState: ICoreState) => ICoreState) => { },
|
||||||
});
|
});
|
||||||
|
|
||||||
const usersCl = NewMockUsersClient("");
|
const usersCl = NewMockUsersClient("");
|
||||||
|
|
|
@ -33,7 +33,8 @@ describe("FilesPanel", () => {
|
||||||
msg: coreState.msg,
|
msg: coreState.msg,
|
||||||
login: coreState.login,
|
login: coreState.login,
|
||||||
ui: coreState.ui,
|
ui: coreState.ui,
|
||||||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
enabled: true,
|
||||||
|
update: (updater: (prevState: ICoreState) => ICoreState) => { },
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -30,7 +30,7 @@ export interface Props {
|
||||||
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {}
|
export interface State { }
|
||||||
export class Layers extends React.Component<Props, State, {}> {
|
export class Layers extends React.Component<Props, State, {}> {
|
||||||
private hotkeyHandler: HotkeyHandler;
|
private hotkeyHandler: HotkeyHandler;
|
||||||
constructor(p: Props) {
|
constructor(p: Props) {
|
||||||
|
@ -39,11 +39,7 @@ export class Layers extends React.Component<Props, State, {}> {
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
this.hotkeyHandler = new HotkeyHandler();
|
this.hotkeyHandler = new HotkeyHandler();
|
||||||
|
this.hotkeyHandler.add({ key: "Escape" }, this.closeHandler);
|
||||||
const closeHandler = () => {
|
|
||||||
this.setControlOption(settingsDialogCtrl, ctrlOff);
|
|
||||||
};
|
|
||||||
this.hotkeyHandler.add({ key: "Escape" }, closeHandler);
|
|
||||||
|
|
||||||
document.addEventListener("keyup", this.hotkeyHandler.handle);
|
document.addEventListener("keyup", this.hotkeyHandler.handle);
|
||||||
}
|
}
|
||||||
|
@ -52,18 +48,23 @@ export class Layers extends React.Component<Props, State, {}> {
|
||||||
document.removeEventListener("keyup", this.hotkeyHandler.handle);
|
document.removeEventListener("keyup", this.hotkeyHandler.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeHandler = () => {
|
||||||
|
if (this.props.ui.control.controls.get(settingsDialogCtrl) === ctrlOn) {
|
||||||
|
this.setControlOption(settingsDialogCtrl, ctrlOff);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setControlOption = (targetControl: string, option: string) => {
|
setControlOption = (targetControl: string, option: string) => {
|
||||||
updater().setControlOption(targetControl, option);
|
updater().setControlOption(targetControl, option);
|
||||||
this.props.update(updater().updateUI);
|
this.props.update(updater().updateUI);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const showLogin =
|
const hideLogin = this.props.login.authed ||
|
||||||
this.props.login.authed ||
|
|
||||||
(this.props.ui.control.controls.get(sharingCtrl) === ctrlOn &&
|
(this.props.ui.control.controls.get(sharingCtrl) === ctrlOn &&
|
||||||
this.props.filesInfo.isSharing)
|
this.props.filesInfo.isSharing);
|
||||||
? "hidden"
|
const loginPaneClass = hideLogin ? "hidden" : "";
|
||||||
: "";
|
|
||||||
const showSettings =
|
const showSettings =
|
||||||
this.props.ui.control.controls.get(settingsDialogCtrl) === ctrlOn
|
this.props.ui.control.controls.get(settingsDialogCtrl) === ctrlOn
|
||||||
? ""
|
? ""
|
||||||
|
@ -79,13 +80,14 @@ export class Layers extends React.Component<Props, State, {}> {
|
||||||
<LoadingIcon />
|
<LoadingIcon />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="login-layer" className={`layer ${showLogin}`}>
|
<div id="login-layer" className={`layer ${loginPaneClass}`}>
|
||||||
<div id="root-container">
|
<div id="root-container">
|
||||||
<AuthPane
|
<AuthPane
|
||||||
login={this.props.login}
|
login={this.props.login}
|
||||||
ui={this.props.ui}
|
ui={this.props.ui}
|
||||||
update={this.props.update}
|
update={this.props.update}
|
||||||
msg={this.props.msg}
|
msg={this.props.msg}
|
||||||
|
enabled={!hideLogin}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,6 +28,7 @@ export interface Props {
|
||||||
login: LoginProps;
|
login: LoginProps;
|
||||||
msg: MsgProps;
|
msg: MsgProps;
|
||||||
ui: UIProps;
|
ui: UIProps;
|
||||||
|
enabled: boolean;
|
||||||
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +58,17 @@ export class AuthPane extends React.Component<Props, State, {}> {
|
||||||
this.hotkeyHandler = new HotkeyHandler();
|
this.hotkeyHandler = new HotkeyHandler();
|
||||||
this.hotkeyHandler.add({ key: "Enter" }, this.login);
|
this.hotkeyHandler.add({ key: "Enter" }, this.login);
|
||||||
|
|
||||||
document.addEventListener("keyup", this.hotkeyHandler.handle);
|
document.addEventListener("keyup", this.handleHotKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
document.removeEventListener("keyup", this.hotkeyHandler.handle);
|
document.removeEventListener("keyup", this.handleHotKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHotKey = (ev: KeyboardEvent) => {
|
||||||
|
if (this.props.enabled) {
|
||||||
|
this.hotkeyHandler.handle(ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changeUser = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
changeUser = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
|
@ -61,6 +61,7 @@ export interface Props {
|
||||||
msg: MsgProps;
|
msg: MsgProps;
|
||||||
login: LoginProps;
|
login: LoginProps;
|
||||||
ui: UIProps;
|
ui: UIProps;
|
||||||
|
enabled: boolean;
|
||||||
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +101,10 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
this.uploadInput = ReactDOM.findDOMNode(input);
|
this.uploadInput = ReactDOM.findDOMNode(input);
|
||||||
};
|
};
|
||||||
this.onClickUpload = () => {
|
this.onClickUpload = () => {
|
||||||
|
if (!this.props.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const uploadInput = this.uploadInput as HTMLButtonElement;
|
const uploadInput = this.uploadInput as HTMLButtonElement;
|
||||||
uploadInput.click();
|
uploadInput.click();
|
||||||
};
|
};
|
||||||
|
@ -227,6 +232,10 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
};
|
};
|
||||||
|
|
||||||
delete = async () => {
|
delete = async () => {
|
||||||
|
if (!this.props.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: selected should be cleaned after change the cwd
|
// TODO: selected should be cleaned after change the cwd
|
||||||
if (this.props.filesInfo.dirPath.join("/") !== this.state.selectedSrc) {
|
if (this.props.filesInfo.dirPath.join("/") !== this.state.selectedSrc) {
|
||||||
alertMsg(this.props.msg.pkg.get("browser.del.fail"));
|
alertMsg(this.props.msg.pkg.get("browser.del.fail"));
|
||||||
|
@ -239,8 +248,7 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
const filesToDel = this.state.selectedItems.keySeq().join(", ");
|
const filesToDel = this.state.selectedItems.keySeq().join(", ");
|
||||||
if (
|
if (
|
||||||
!confirmMsg(
|
!confirmMsg(
|
||||||
`${this.props.msg.pkg.get("op.confirm")} [${
|
`${this.props.msg.pkg.get("op.confirm")} [${this.state.selectedItems.size
|
||||||
this.state.selectedItems.size
|
|
||||||
}]: ${filesToDel}`
|
}]: ${filesToDel}`
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
@ -284,6 +292,10 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
};
|
};
|
||||||
|
|
||||||
moveHere = async () => {
|
moveHere = async () => {
|
||||||
|
if (!this.props.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const oldDir = this.state.selectedSrc;
|
const oldDir = this.state.selectedSrc;
|
||||||
const newDir = this.props.filesInfo.dirPath.join("/");
|
const newDir = this.props.filesInfo.dirPath.join("/");
|
||||||
if (oldDir === newDir) {
|
if (oldDir === newDir) {
|
||||||
|
@ -377,6 +389,10 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
||||||
};
|
};
|
||||||
|
|
||||||
selectAll = () => {
|
selectAll = () => {
|
||||||
|
if (!this.props.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let newSelected = Map<string, boolean>();
|
let newSelected = Map<string, boolean>();
|
||||||
const someSelected = this.state.selectedItems.size === 0 ? true : false;
|
const someSelected = this.state.selectedItems.size === 0 ? true : false;
|
||||||
if (someSelected) {
|
if (someSelected) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ export interface Props {
|
||||||
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {}
|
export interface State { }
|
||||||
export class RootFrame extends React.Component<Props, State, {}> {
|
export class RootFrame extends React.Component<Props, State, {}> {
|
||||||
constructor(p: Props) {
|
constructor(p: Props) {
|
||||||
super(p);
|
super(p);
|
||||||
|
@ -114,6 +114,7 @@ export class RootFrame extends React.Component<Props, State, {}> {
|
||||||
msg={this.props.msg}
|
msg={this.props.msg}
|
||||||
login={this.props.login}
|
login={this.props.login}
|
||||||
ui={this.props.ui}
|
ui={this.props.ui}
|
||||||
|
enabled={displaying === "filesPanel"}
|
||||||
update={this.props.update}
|
update={this.props.update}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue