/* * Copyright 2026 Element Creations 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 React, { type JSX } from "react"; import { IconButton, H1 } from "@vector-im/compound-web"; import { CollapseAllIcon, ExpandAllIcon, ChatIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import { type ViewModel, useViewModel } from "../../core/viewmodel"; import { Flex } from "../../core/utils/Flex"; import { useI18n } from "../../core/i18n/i18nContext"; import { ComposeMenuView, OptionMenuView, SpaceMenuView } from "./menu"; import styles from "./RoomListHeaderView.module.css"; /** * The available sorting options for the room list. */ export type SortOption = "recent" | "alphabetical" | "unread-first"; /** * The available options for collapsing sections in the room list. */ export type CollapseSectionsOption = "collapse" | "expand"; export interface RoomListHeaderViewSnapshot { /** * The title of the room list */ title: string; /** * Whether to display the space menu * True if there is an active space */ displaySpaceMenu: boolean; /** * Whether the user can create rooms */ canCreateRoom: boolean; /** * Whether the user can create video rooms */ canCreateVideoRoom: boolean; /** * Whether the user can invite in the active space */ canInviteInSpace: boolean; /** * Whether the user can access space settings */ canAccessSpaceSettings: boolean; /** * The currently active sort option. */ activeSortOption: SortOption; /** * Whether message previews are enabled in the room list. */ isMessagePreviewEnabled: boolean; /** * Whether sections are enabled in the room list. */ areSectionsEnabled: boolean; /** * If "collapse", an icon to collapse all sections is shown. * If "expand", an icon to expand all sections is shown. * If undefined, no icon are shown. */ collapseSections?: CollapseSectionsOption; /** * Whether to display the section release announcement */ displaySectionReleaseAnnouncement: boolean; } export interface RoomListHeaderViewActions { /** * Create a chat room */ createChatRoom: (e: Event) => void; /** * Create a room */ createRoom: (e: Event) => void; /** * Create a video room */ createVideoRoom: () => void; /** * Open the active space home */ openSpaceHome: () => void; /** * Display the space invite dialog */ inviteInSpace: () => void; /** * Open the space preferences */ openSpacePreferences: () => void; /** * Open the space settings */ openSpaceSettings: () => void; /** * Change the sort order of the room-list. */ sort: (option: SortOption) => void; /** * Toggle message preview display in the room list. */ toggleMessagePreview: () => void; /** * Create a new section in the room list. */ createSection: () => void; /** * Collapse or expand all sections in the room list depending on the current state. */ collapseOrExpandSections: () => void; /** * Close the section release announcement */ closeSectionReleaseAnnouncement: () => void; } /** * The view model for the room list header component. */ export type RoomListHeaderViewModel = ViewModel; interface RoomListHeaderViewProps { /** * The view model for the room list header component. */ vm: RoomListHeaderViewModel; } /** * The header view for the room list * The space name is displayed and a compose menu is shown if the user can create rooms * * @example * ```tsx * * ``` */ export function RoomListHeaderView({ vm }: Readonly): JSX.Element { const { translate: _t } = useI18n(); const { title, displaySpaceMenu, collapseSections, areSectionsEnabled, canCreateRoom, canCreateVideoRoom } = useViewModel(vm); const canOnlyStartChat = !areSectionsEnabled && !canCreateRoom && !canCreateVideoRoom; return (

{title}

{displaySpaceMenu && }
{areSectionsEnabled && collapseSections && ( vm.collapseOrExpandSections()} tooltip={ collapseSections === "collapse" ? _t("room_list|collapse_all_sections") : _t("room_list|expand_all_sections") } > {collapseSections === "collapse" ? ( ) : ( )} )} {canOnlyStartChat ? ( vm.createChatRoom(e.nativeEvent)} tooltip={_t("action|start_chat")} > ) : ( )}
); }