Sidebar work
This commit is contained in:
@@ -38,8 +38,7 @@ class CollectionsStore {
|
||||
}
|
||||
};
|
||||
|
||||
@action getById = async (id: string): Promise<Collection> => {
|
||||
if (!this.isLoaded) await this.fetch();
|
||||
getById = (id: string): Collection => {
|
||||
return _.find(this.data, { id });
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user