fbb43d5e61
* feat: implement `ExtrasApi#setRoomIdsForSpace` * fix: message reply with multiple room views * fix: message edition when multiple rooms are displayed * test: check that the view room action is not dispatch when replying * test: check that the view room action is not dispatch when editing * refactor: use `ExtraApis#getVisibleRoomBySpaceKey` instead of `ExtraApis#setRoomIdsForSpace` * test: update tests to use `getVisibleRoomBySpaceKey`
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { type SpacePanelItemProps, type ExtrasApi } from "@element-hq/element-web-module-api";
|
|
import { TypedEventEmitter } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { useTypedEventEmitter } from "../hooks/useEventEmitter";
|
|
|
|
export interface ModuleSpacePanelItem extends SpacePanelItemProps {
|
|
spaceKey: string;
|
|
}
|
|
|
|
enum ExtrasApiEvent {
|
|
SpacePanelItemsChanged = "SpacePanelItemsChanged",
|
|
}
|
|
|
|
interface EmittedEvents {
|
|
[ExtrasApiEvent.SpacePanelItemsChanged]: () => void;
|
|
}
|
|
|
|
export class ElementWebExtrasApi extends TypedEventEmitter<keyof EmittedEvents, EmittedEvents> implements ExtrasApi {
|
|
public spacePanelItems = new Map<string, SpacePanelItemProps>();
|
|
public visibleRoomBySpaceKey = new Map<string, () => string[]>();
|
|
|
|
public setSpacePanelItem(spacekey: string, item: SpacePanelItemProps): void {
|
|
this.spacePanelItems.set(spacekey, item);
|
|
this.emit(ExtrasApiEvent.SpacePanelItemsChanged);
|
|
}
|
|
|
|
public getVisibleRoomBySpaceKey(spaceKey: string, cb: () => string[]): void {
|
|
this.visibleRoomBySpaceKey.set(spaceKey, cb);
|
|
}
|
|
}
|
|
|
|
export function useModuleSpacePanelItems(api: ElementWebExtrasApi): ModuleSpacePanelItem[] {
|
|
const getItems = (): ModuleSpacePanelItem[] => {
|
|
return Array.from(api.spacePanelItems.entries()).map(([spaceKey, item]) => ({
|
|
spaceKey,
|
|
...item,
|
|
}));
|
|
};
|
|
|
|
const [items, setItems] = useState<ModuleSpacePanelItem[]>(getItems);
|
|
|
|
useTypedEventEmitter(api, ExtrasApiEvent.SpacePanelItemsChanged, () => {
|
|
setItems(getItems());
|
|
});
|
|
|
|
return items;
|
|
}
|