mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-18 07:31:46 +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) {
|
||||
super(props);
|
||||
|
||||
const collapsed = SpaceTreeLevelLayoutStore.getSpaceCollapsedState(
|
||||
const collapsed = SpaceTreeLevelLayoutStore.instance.getSpaceCollapsedState(
|
||||
props.space.roomId,
|
||||
this.props.parents,
|
||||
!props.isNested,
|
||||
|
@ -88,7 +88,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
|||
}
|
||||
const newCollapsedState = !this.state.collapsed;
|
||||
|
||||
SpaceTreeLevelLayoutStore.setSpaceCollapsedState(
|
||||
SpaceTreeLevelLayoutStore.instance.setSpaceCollapsedState(
|
||||
this.props.space.roomId,
|
||||
this.props.parents,
|
||||
newCollapsedState,
|
||||
|
|
|
@ -26,12 +26,21 @@ const getSpaceCollapsedKey = (roomId: string, parents: Set<string>): string => {
|
|||
};
|
||||
|
||||
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
|
||||
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));
|
||||
// XXX: localStorage doesn't allow booleans
|
||||
return collapsedLocalStorage ? collapsedLocalStorage === "true" : fallback;
|
||||
|
|
Loading…
Reference in a new issue