mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-18 09:31:47 +03:00
Make SpaceTreeLevelLayoutStore into a singleton
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
4115fd8695
commit
1b877f2b7c
2 changed files with 13 additions and 4 deletions
|
@ -69,7 +69,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const collapsed = SpaceTreeLevelLayoutStore.getSpaceCollapsedState(
|
const collapsed = SpaceTreeLevelLayoutStore.instance.getSpaceCollapsedState(
|
||||||
props.space.roomId,
|
props.space.roomId,
|
||||||
this.props.parents,
|
this.props.parents,
|
||||||
!props.isNested,
|
!props.isNested,
|
||||||
|
@ -88,7 +88,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
||||||
}
|
}
|
||||||
const newCollapsedState = !this.state.collapsed;
|
const newCollapsedState = !this.state.collapsed;
|
||||||
|
|
||||||
SpaceTreeLevelLayoutStore.setSpaceCollapsedState(
|
SpaceTreeLevelLayoutStore.instance.setSpaceCollapsedState(
|
||||||
this.props.space.roomId,
|
this.props.space.roomId,
|
||||||
this.props.parents,
|
this.props.parents,
|
||||||
newCollapsedState,
|
newCollapsedState,
|
||||||
|
|
|
@ -26,12 +26,21 @@ const getSpaceCollapsedKey = (roomId: string, parents: Set<string>): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class SpaceTreeLevelLayoutStore {
|
export default class SpaceTreeLevelLayoutStore {
|
||||||
public static setSpaceCollapsedState(roomId: string, parents: Set<string>, collapsed: boolean) {
|
private static internalInstance: SpaceTreeLevelLayoutStore;
|
||||||
|
|
||||||
|
public static get instance(): SpaceTreeLevelLayoutStore {
|
||||||
|
if (!SpaceTreeLevelLayoutStore.internalInstance) {
|
||||||
|
SpaceTreeLevelLayoutStore.internalInstance = new SpaceTreeLevelLayoutStore();
|
||||||
|
}
|
||||||
|
return SpaceTreeLevelLayoutStore.internalInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setSpaceCollapsedState(roomId: string, parents: Set<string>, collapsed: boolean) {
|
||||||
// XXX: localStorage doesn't allow booleans
|
// XXX: localStorage doesn't allow booleans
|
||||||
localStorage.setItem(getSpaceCollapsedKey(roomId, parents), collapsed.toString());
|
localStorage.setItem(getSpaceCollapsedKey(roomId, parents), collapsed.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getSpaceCollapsedState(roomId: string, parents: Set<string>, fallback: boolean): boolean {
|
public getSpaceCollapsedState(roomId: string, parents: Set<string>, fallback: boolean): boolean {
|
||||||
const collapsedLocalStorage = localStorage.getItem(getSpaceCollapsedKey(roomId, parents));
|
const collapsedLocalStorage = localStorage.getItem(getSpaceCollapsedKey(roomId, parents));
|
||||||
// XXX: localStorage doesn't allow booleans
|
// XXX: localStorage doesn't allow booleans
|
||||||
return collapsedLocalStorage ? collapsedLocalStorage === "true" : fallback;
|
return collapsedLocalStorage ? collapsedLocalStorage === "true" : fallback;
|
||||||
|
|
Loading…
Reference in a new issue