Sidebar work

This commit is contained in:
Jori Lallo
2017-06-15 20:39:08 -07:00
parent 42e54a3a54
commit aa0ddd94bf
21 changed files with 250 additions and 368 deletions

View File

@ -1,34 +1,18 @@
// @flow
import { observable, action, computed, autorunAsync } from 'mobx';
const UI_STORE = 'UI_STORE';
import { observable, action } from 'mobx';
class UiStore {
@observable sidebar: boolean = false;
/* Computed */
@computed get asJson(): string {
return JSON.stringify({
sidebar: this.sidebar,
});
}
@observable activeCollection: ?string;
/* Actions */
@action toggleSidebar = (): void => {
this.sidebar = !this.sidebar;
@action setActiveCollection = (id: string): void => {
this.activeCollection = id;
};
constructor() {
// Rehydrate
const data = JSON.parse(localStorage.getItem(UI_STORE) || '{}');
this.sidebar = data.sidebar;
autorunAsync(() => {
localStorage.setItem(UI_STORE, this.asJson);
});
}
@action clearActiveCollection = (): void => {
this.activeCollection = null;
};
}
export default UiStore;