-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDW-813] Move discreet mode behavior to its own feature
- Loading branch information
1 parent
2d046f6
commit b44bb5c
Showing
9 changed files
with
76 additions
and
56 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
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,14 @@ | ||
// @flow | ||
import LocalStorageApi from '../../../api/utils/localStorage'; | ||
import { STORAGE_KEYS as storageKeys } from '../../../../../common/config/electron-store.config'; | ||
|
||
export class DiscreetModeApi { | ||
getDiscreetModeSettings = (): Promise<boolean> => | ||
LocalStorageApi.get(storageKeys.DISCREET_MODE_ENABLED, false); | ||
|
||
setDiscreetModeSettings = (enabled: boolean): Promise<void> => | ||
LocalStorageApi.set(storageKeys.DISCREET_MODE_ENABLED, enabled); | ||
|
||
unsetDiscreetModeSettings = (): Promise<void> => | ||
LocalStorageApi.unset(storageKeys.DISCREET_MODE_ENABLED); | ||
} |
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,12 +1,53 @@ | ||
// @flow | ||
|
||
import { observable, action } from 'mobx'; | ||
import { observable, action, runInAction } from 'mobx'; | ||
import { Feature } from '../../utils/mobx-features/feature'; | ||
import Request from '../../stores/lib/LocalizedRequest'; | ||
import { DiscreetModeApi } from './api'; | ||
|
||
export class DiscreetMode extends Feature { | ||
api: DiscreetModeApi; | ||
@observable isDiscreetMode: boolean = false; | ||
@observable openInDiscreetMode: boolean = false; | ||
|
||
@observable getDiscreetModeSettingsRequest: Request< | ||
Promise<boolean> | ||
> = new Request(this.api.getDiscreetModeSettings); | ||
|
||
@observable setDiscreetModeSettingsRequest: Request< | ||
Promise<boolean> | ||
> = new Request(this.api.setDiscreetModeSettings); | ||
|
||
constructor(api: DiscreetModeApi) { | ||
super(); | ||
|
||
this.api = api; | ||
} | ||
|
||
async start() { | ||
super.start(); | ||
|
||
await this._setupDiscreetMode(); | ||
} | ||
|
||
_setupDiscreetMode = async () => { | ||
await this.getDiscreetModeSettingsRequest.execute(); | ||
const isDiscreetModeEnabled = this.getDiscreetModeSettingsRequest.result; | ||
runInAction('Initialize discreet mode variables', () => { | ||
this.openInDiscreetMode = isDiscreetModeEnabled; | ||
this.isDiscreetMode = isDiscreetModeEnabled; | ||
}); | ||
}; | ||
|
||
@action toggleDiscreetMode = () => { | ||
this.isDiscreetMode = !this.isDiscreetMode; | ||
}; | ||
|
||
@action toggleOpenInDiscreetMode = async () => { | ||
const nextSetting = !this.openInDiscreetMode; | ||
await this.setDiscreetModeSettingsRequest.execute(nextSetting); | ||
runInAction('Update open in discreet mode settings', () => { | ||
this.openInDiscreetMode = nextSetting; | ||
}); | ||
}; | ||
} |
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,4 +1,4 @@ | ||
// @flow | ||
|
||
export { useDiscreetModeFeature } from './context'; | ||
export { useDiscreetModeFeature, DiscreetModeFeatureProvider } from './context'; | ||
export { DiscreetValue } from './ui'; |
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,3 @@ | ||
// @flow | ||
|
||
export * from './discreet-mode'; |
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