mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-17 04:21:45 +03:00
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
|
/*
|
||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
|
import { TagID } from "./models";
|
||
|
import { ListLayout } from "./ListLayout";
|
||
|
|
||
|
export default class RoomListLayoutStore {
|
||
|
private static internalInstance: RoomListLayoutStore;
|
||
|
|
||
|
private readonly layoutMap = new Map<TagID, ListLayout>();
|
||
|
|
||
|
public ensureLayoutExists(tagId: TagID) {
|
||
|
if (!this.layoutMap.has(tagId)) {
|
||
|
this.layoutMap.set(tagId, new ListLayout(tagId));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public getLayoutFor(tagId: TagID): ListLayout {
|
||
|
if (!this.layoutMap.has(tagId)) {
|
||
|
this.layoutMap.set(tagId, new ListLayout(tagId));
|
||
|
}
|
||
|
return this.layoutMap.get(tagId);
|
||
|
}
|
||
|
|
||
|
// Note: this primarily exists for debugging, and isn't really intended to be used by anything.
|
||
|
public async resetLayouts() {
|
||
|
console.warn("Resetting layouts for room list");
|
||
|
for (const layout of this.layoutMap.values()) {
|
||
|
layout.reset();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static get instance(): RoomListLayoutStore {
|
||
|
if (!RoomListLayoutStore.internalInstance) {
|
||
|
RoomListLayoutStore.internalInstance = new RoomListLayoutStore();
|
||
|
}
|
||
|
return RoomListLayoutStore.internalInstance;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.mx_RoomListLayoutStore = RoomListLayoutStore.instance;
|