mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
HistoryStore initial draft
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
54ac311933
commit
82ac857e2f
88
src/common/history-store.ts
Normal file
88
src/common/history-store.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { action, makeObservable, observable, reaction } from "mobx";
|
||||||
|
import { navigation } from "../renderer/navigation";
|
||||||
|
import { BaseStore } from "./base-store";
|
||||||
|
import { toJS } from "./utils";
|
||||||
|
|
||||||
|
type HistoryModel = {
|
||||||
|
activeStep: number
|
||||||
|
};
|
||||||
|
|
||||||
|
export class HistoryStore extends BaseStore<HistoryModel> {
|
||||||
|
@observable activeStep = 0;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
configName: "lens-history-store",
|
||||||
|
});
|
||||||
|
makeObservable(this);
|
||||||
|
|
||||||
|
reaction(() => navigation.location, () => {
|
||||||
|
console.log(
|
||||||
|
`The current URL is ${navigation.location.pathname}${navigation.location.search}${navigation.location.hash}`
|
||||||
|
);
|
||||||
|
console.log(`The last navigation action was ${navigation.action}`);
|
||||||
|
|
||||||
|
if (!this.backOrForwardChange()) {
|
||||||
|
this.activeStep++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
goBack() {
|
||||||
|
this.activeStep--;
|
||||||
|
navigation.goBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
goForward() {
|
||||||
|
this.activeStep++;
|
||||||
|
navigation.goForward();
|
||||||
|
}
|
||||||
|
|
||||||
|
isPreviousExist() {
|
||||||
|
return this.activeStep > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
isForwardExist() {
|
||||||
|
return this.activeStep < navigation.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
backOrForwardChange() {
|
||||||
|
return navigation.action == "POP";
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
protected fromStore(data: Partial<HistoryModel> = {}) {
|
||||||
|
this.activeStep = data.activeStep || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON(): HistoryModel {
|
||||||
|
const model: HistoryModel = {
|
||||||
|
activeStep: this.activeStep
|
||||||
|
};
|
||||||
|
|
||||||
|
return toJS(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -51,6 +51,7 @@ import { ThemeStore } from "./theme.store";
|
|||||||
import { SentryInit } from "../common/sentry";
|
import { SentryInit } from "../common/sentry";
|
||||||
import { TerminalStore } from "./components/dock/terminal.store";
|
import { TerminalStore } from "./components/dock/terminal.store";
|
||||||
import cloudsMidnight from "./monaco-themes/Clouds Midnight.json";
|
import cloudsMidnight from "./monaco-themes/Clouds Midnight.json";
|
||||||
|
import { HistoryStore } from "../common/history-store";
|
||||||
|
|
||||||
configurePackages();
|
configurePackages();
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ export async function bootstrap(App: AppComponent) {
|
|||||||
// HotbarStore depends on: ClusterStore
|
// HotbarStore depends on: ClusterStore
|
||||||
HotbarStore.createInstance();
|
HotbarStore.createInstance();
|
||||||
ExtensionsStore.createInstance();
|
ExtensionsStore.createInstance();
|
||||||
|
HistoryStore.createInstance();
|
||||||
FilesystemProvisionerStore.createInstance();
|
FilesystemProvisionerStore.createInstance();
|
||||||
|
|
||||||
// define Monaco Editor themes
|
// define Monaco Editor themes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user