-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e94781
commit f74882d
Showing
10 changed files
with
109 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { FC } from "react" | ||
import { AutoStartStopModal } from "./auto-start-stop" | ||
import { GeneratorStopInfo } from "./generator-stop-info" | ||
|
||
export const Modals: FC = () => ( | ||
<> | ||
<AutoStartStopModal /> | ||
<GeneratorStopInfo /> | ||
</> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 7 additions & 28 deletions
35
src/app/Marine2/components/_composed/modals/generator-stop-info/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
import { makeAutoObservable, observable, computed } from "mobx" | ||
import { useMemo } from "react" | ||
|
||
export class UiState { | ||
language = "en_US" | ||
pendingRequestCount = 0 | ||
type Modal = "deviceSetting" | "startStopMode" | "generatorStopInfo" | ||
|
||
// .struct makes sure observer won't be signaled unless the | ||
// dimensions object changed in a deepEqual manner. | ||
windowDimensions = { | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
export interface Modals { | ||
[keyOf: string]: boolean | ||
} | ||
|
||
export class UiStore { | ||
modals: Modals = { | ||
deviceSettings: false, | ||
startStopMode: false, | ||
generatorStopInfo: false, | ||
} | ||
|
||
constructor() { | ||
makeAutoObservable(this, { windowDimensions: observable.struct }) | ||
window.onresize = () => { | ||
//this.windowDimensions = getWindowDimensions() | ||
} | ||
makeAutoObservable(this) | ||
} | ||
|
||
openModalFor(id: Modal) { | ||
this.modals[id] = true | ||
} | ||
|
||
closeModalFor(id: Modal) { | ||
this.modals[id] = false | ||
} | ||
|
||
get appIsInSync() { | ||
return this.pendingRequestCount === 0 | ||
toggleModalFor(id: Modal) { | ||
this.modals[id] = !this.modals[id] | ||
} | ||
} | ||
|
||
let store: UiStore | ||
|
||
function initializeStore() { | ||
const _store = store ?? new UiStore() | ||
// For SSG and SSR always create a new store | ||
if (typeof window === "undefined") return _store | ||
// Create the store once in the client | ||
if (!store) store = _store | ||
|
||
return _store | ||
} | ||
|
||
export function useUiStore() { | ||
return useMemo(() => initializeStore(), []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./Ui.store" |