menu.ts: refactoring and fixes, reuse route paths from views (renderer)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-22 17:10:37 +03:00
1 parent 117ad584d3
commit a4bcfc1e52
7 files changed
+118 -139

No files matched your search

@@ -33,7 +33,7 @@ export class WhatsNew extends React.Component {
</div>
<div className="bottom">
<Button
primary
primary autoFocus
label={<Trans>Ok, got it!</Trans>}
onClick={this.ok}
/>
+4 -4
View File
@@ -5,7 +5,7 @@ import { createPortal } from "react-dom";
import { cssNames, noop } from "../../utils";
import { Icon } from "../icon";
import { Animate, AnimateName } from "../animate";
import { browserHistory } from "../../navigation";
import { history } from "../../navigation";
import { themeStore } from "../../theme.store";
export interface DrawerProps {
@@ -36,7 +36,7 @@ export class Drawer extends React.Component<DrawerProps> {
private scrollElem: HTMLElement
private scrollPos = new Map<string, number>();
private stopListenLocation = browserHistory.listen(() => {
private stopListenLocation = history.listen(() => {
this.restoreScrollPos();
});
@@ -55,13 +55,13 @@ export class Drawer extends React.Component<DrawerProps> {
saveScrollPos = () => {
if (!this.scrollElem) return;
const key = browserHistory.location.key;
const key = history.location.key;
this.scrollPos.set(key, this.scrollElem.scrollTop);
}
restoreScrollPos = () => {
if (!this.scrollElem) return;
const key = browserHistory.location.key;
const key = history.location.key;
this.scrollElem.scrollTop = this.scrollPos.get(key) || 0;
}
+2 -2
View File
@@ -7,7 +7,7 @@ import { userStore } from "../common/user-store";
import { workspaceStore } from "../common/workspace-store";
import { clusterStore } from "../common/cluster-store";
import { I18nProvider } from "@lingui/react";
import { browserHistory } from "./navigation";
import { history } from "./navigation";
import { isMac } from "../common/vars";
import { _i18n } from "./i18n";
import { ClusterManager } from "./components/cluster-manager";
@@ -32,7 +32,7 @@ class LensApp extends React.Component {
render() {
return (
<I18nProvider i18n={_i18n}>
<Router history={browserHistory}>
<Router history={history}>
<ErrorBoundary>
<Switch>
{userStore.isNewVersion && <Route component={WhatsNew}/>}
+11 -3
View File
@@ -1,11 +1,19 @@
// Navigation helpers
import { ipcRenderer } from "electron";
import { compile } from "path-to-regexp"
import { createBrowserHistory, Location, LocationDescriptor } from "history";
import { createBrowserHistory, createMemoryHistory, Location, LocationDescriptor } from "history";
import { createObservableHistory } from "mobx-observable-history";
export const browserHistory = createBrowserHistory();
export const navigation = createObservableHistory(browserHistory);
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
export const navigation = createObservableHistory(history);
if (ipcRenderer) {
// subscribe for navigation via menu.ts
ipcRenderer.on("menu:navigate", (event, path: string) => {
navigate(path);
});
}
export function navigate(location: LocationDescriptor) {
navigation.location = location as Location;