diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/default-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/default-auto.png new file mode 100644 index 0000000000..fde6a23cfe Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/default-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-auto.png new file mode 100644 index 0000000000..bcf28e7f88 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-favourite-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-favourite-filter-auto.png new file mode 100644 index 0000000000..503593f1f7 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-favourite-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-invites-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-invites-filter-auto.png new file mode 100644 index 0000000000..ef6ddca30b Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-invites-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-low-priority-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-low-priority-filter-auto.png new file mode 100644 index 0000000000..2efcd5267e Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-low-priority-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-mentions-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-mentions-filter-auto.png new file mode 100644 index 0000000000..a72a03d73b Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-mentions-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-people-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-people-filter-auto.png new file mode 100644 index 0000000000..88597f19e1 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-people-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-rooms-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-rooms-filter-auto.png new file mode 100644 index 0000000000..de8bc49c55 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-rooms-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-unread-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-unread-filter-auto.png new file mode 100644 index 0000000000..844f532cf1 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-unread-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-without-create-permission-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-without-create-permission-auto.png new file mode 100644 index 0000000000..fdfb2a4d12 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/empty-without-create-permission-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/large-list-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/large-list-auto.png new file mode 100644 index 0000000000..fde6a23cfe Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/large-list-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/loading-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/loading-auto.png new file mode 100644 index 0000000000..bace5dba52 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/loading-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/small-list-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/small-list-auto.png new file mode 100644 index 0000000000..7572cec331 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/small-list-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-active-filter-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-active-filter-auto.png new file mode 100644 index 0000000000..081aa94307 Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-active-filter-auto.png differ diff --git a/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-selection-auto.png b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-selection-auto.png new file mode 100644 index 0000000000..8bb5d6447f Binary files /dev/null and b/packages/shared-components/__vis__/linux/__baselines__/room-list/RoomListView/RoomListView.stories.tsx/with-selection-auto.png differ diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.module.css b/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.module.css new file mode 100644 index 0000000000..204e7615a4 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.module.css @@ -0,0 +1,33 @@ +/* + * Copyright 2025 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. + */ + +.genericPlaceholder { + align-self: center; + /** It should take 2/3 of the width **/ + width: 66%; + /** It should be positioned at 1/3 of the height **/ + padding-top: 33%; +} + +.title { + font: var(--cpd-font-body-lg-semibold); + text-align: center; +} + +.description { + font: var(--cpd-font-body-sm-regular); + color: var(--cpd-color-text-secondary); + text-align: center; +} + +.defaultPlaceholder { + margin-top: var(--cpd-space-4x); +} + +.genericPlaceholder button { + width: 100%; +} diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.tsx b/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.tsx new file mode 100644 index 0000000000..98e51d6878 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListEmptyState.tsx @@ -0,0 +1,182 @@ +/* + * 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, type PropsWithChildren, type ReactNode } from "react"; +import { Button } from "@vector-im/compound-web"; +import ChatIcon from "@vector-im/compound-design-tokens/assets/web/icons/chat"; +import RoomIcon from "@vector-im/compound-design-tokens/assets/web/icons/room"; + +import { Flex } from "../../utils/Flex"; +import { _t } from "../../utils/i18n"; +import { useViewModel } from "../../viewmodel"; +import type { RoomListViewModel } from "./RoomListView"; +import styles from "./RoomListEmptyState.module.css"; + +/** + * Props for RoomListEmptyState component + */ +export interface RoomListEmptyStateProps { + /** The view model containing all data and callbacks */ + vm: RoomListViewModel; +} + +/** + * Empty state component for the room list. + * Displays appropriate message and actions based on the active filter. + */ +export const RoomListEmptyState: React.FC = ({ vm }): JSX.Element => { + const snapshot = useViewModel(vm); + + // If there is no active filter, show the default empty state + if (!snapshot.activeFilterId) { + return ( + + + + {snapshot.canCreateRoom && ( + + )} + + + ); + } + + // Handle different filter cases based on filter ID + switch (snapshot.activeFilterId) { + case "favourite": + return ( + + ); + case "people": + return ( + + ); + case "rooms": + return ( + + ); + case "unread": + return ( + vm.onToggleFilter(snapshot.activeFilterId!)} + /> + ); + case "invites": + return ( + vm.onToggleFilter(snapshot.activeFilterId!)} + /> + ); + case "mentions": + return ( + vm.onToggleFilter(snapshot.activeFilterId!)} + /> + ); + case "low_priority": + return ( + vm.onToggleFilter(snapshot.activeFilterId!)} + /> + ); + default: + return ( + + ); + } +}; + +interface GenericPlaceholderProps { + /** The title of the placeholder */ + title: string; + /** The description of the placeholder */ + description?: string; + /** Optional children (e.g., action buttons) */ + children?: ReactNode; +} + +/** + * A generic placeholder for the room list + */ +function GenericPlaceholder({ title, description, children }: PropsWithChildren): JSX.Element { + return ( + + {title} + {description && {description}} + {children} + + ); +} + +interface ActionPlaceholderProps { + /** The title to display */ + title: string; + /** The action button text */ + action: string; + /** Callback when the action button is clicked */ + onAction?: () => void; +} + +/** + * A placeholder for the room list when a filter is active + * The user can take action to toggle the filter + */ +function ActionPlaceholder({ title, action, onAction }: ActionPlaceholderProps): JSX.Element { + return ( + + {onAction && ( + + )} + + ); +} diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.module.css b/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.module.css new file mode 100644 index 0000000000..2f65f7969d --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.module.css @@ -0,0 +1,24 @@ +/* + * Copyright 2025 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. + */ + +.skeleton { + position: relative; + margin-left: 4px; + height: 100%; + flex: 1; +} + +.skeleton::before { + background-color: var(--cpd-color-bg-subtle-secondary); + width: 100%; + height: 100%; + content: ""; + position: absolute; + mask-repeat: repeat-y; + mask-size: auto 96px; + mask-image: url("./assets/skeleton.svg"); +} diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.tsx b/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.tsx new file mode 100644 index 0000000000..6ab8b80de3 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListLoadingSkeleton.tsx @@ -0,0 +1,18 @@ +/* + * 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 styles from "./RoomListLoadingSkeleton.module.css"; + +/** + * Loading skeleton component for the room list. + * Displays a repeating skeleton pattern while rooms are being fetched. + */ +export const RoomListLoadingSkeleton: React.FC = (): JSX.Element => { + return
; +}; diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListView.stories.tsx b/packages/shared-components/src/room-list/RoomListView/RoomListView.stories.tsx new file mode 100644 index 0000000000..af812d7347 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListView.stories.tsx @@ -0,0 +1,220 @@ +/* + * 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 { fn } from "storybook/test"; + +import type { Meta, StoryObj } from "@storybook/react-vite"; +import type { FilterId } from "../RoomListPrimaryFilters"; +import { RoomListView, type RoomListSnapshot, type RoomListViewActions } from "./RoomListView"; +import { useMockedViewModel } from "../../viewmodel"; +import { + renderAvatar, + createGetRoomItemViewModel, + mockRoomIds, + smallListRoomIds, + largeListRoomIds, +} from "../story-mocks"; + +type RoomListViewProps = RoomListSnapshot & RoomListViewActions & { renderAvatar: (room: any) => React.ReactElement }; + +const mockFilterIds: FilterId[] = ["unread", "people", "rooms", "favourite"]; + +// Wrapper component that creates a mocked ViewModel +const RoomListViewWrapper = ({ + onToggleFilter, + createChatRoom, + createRoom, + getRoomItemViewModel, + updateVisibleRooms, + renderAvatar: renderAvatarProp, + ...rest +}: RoomListViewProps): JSX.Element => { + const vm = useMockedViewModel(rest, { + onToggleFilter, + createChatRoom, + createRoom, + getRoomItemViewModel, + updateVisibleRooms, + }); + return ; +}; + +const meta = { + title: "Room List/RoomListView", + component: RoomListViewWrapper, + tags: ["autodocs"], + decorators: [ + (Story) => ( +
+ +
+ ), + ], + args: { + // Snapshot properties (state) + isLoadingRooms: false, + isRoomListEmpty: false, + filterIds: mockFilterIds, + activeFilterId: undefined, + roomListState: { + activeRoomIndex: undefined, + spaceId: "!space:server", + filterKeys: undefined, + }, + roomIds: mockRoomIds, + canCreateRoom: true, + // Action properties (callbacks) + onToggleFilter: fn(), + createChatRoom: fn(), + createRoom: fn(), + getRoomItemViewModel: createGetRoomItemViewModel(mockRoomIds), + updateVisibleRooms: fn(), + renderAvatar, + }, + parameters: { + design: { + type: "figma", + url: "https://www.figma.com/design/vlmt46QDdE4dgXDiyBJXqp/ER-33-Left-Panel?node-id=2925-19126", + }, + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = {}; + +export const Loading: Story = { + args: { + isLoadingRooms: true, + }, +}; + +export const Empty: Story = { + args: { + isRoomListEmpty: true, + }, +}; + +export const EmptyWithoutCreatePermission: Story = { + args: { + isRoomListEmpty: true, + canCreateRoom: false, + }, +}; + +export const WithActiveFilter: Story = { + args: { + filterIds: ["unread", "people", "rooms", "favourite"], + activeFilterId: "favourite", + roomListState: { + activeRoomIndex: undefined, + spaceId: "!space:server", + filterKeys: ["favourites"], + }, + }, +}; + +export const WithSelection: Story = { + args: { + roomListState: { + activeRoomIndex: 0, + spaceId: "!space:server", + filterKeys: undefined, + }, + }, +}; + +export const EmptyFavouriteFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["favourite", "people"], + activeFilterId: "favourite", + }, +}; + +export const EmptyPeopleFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["people", "rooms"], + activeFilterId: "people", + }, +}; + +export const EmptyRoomsFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["rooms", "people"], + activeFilterId: "rooms", + }, +}; + +export const EmptyUnreadFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["unread", "people"], + activeFilterId: "unread", + }, +}; + +export const EmptyInvitesFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["invites", "people"], + activeFilterId: "invites", + }, +}; + +export const EmptyMentionsFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["mentions", "people"], + activeFilterId: "mentions", + }, +}; + +export const EmptyLowPriorityFilter: Story = { + args: { + isRoomListEmpty: true, + roomIds: [], + filterIds: ["low_priority", "people"], + activeFilterId: "low_priority", + }, +}; + +export const SmallList: Story = { + args: { + roomIds: smallListRoomIds, + getRoomItemViewModel: createGetRoomItemViewModel(smallListRoomIds), + }, +}; + +export const LargeList: Story = { + args: { + roomIds: largeListRoomIds, + getRoomItemViewModel: createGetRoomItemViewModel(largeListRoomIds), + }, +}; diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListView.test.tsx b/packages/shared-components/src/room-list/RoomListView/RoomListView.test.tsx new file mode 100644 index 0000000000..15237eed7e --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListView.test.tsx @@ -0,0 +1,177 @@ +/* + * 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 from "react"; +import { render, screen } from "@test-utils"; +import userEvent from "@testing-library/user-event"; +import { VirtuosoMockContext } from "react-virtuoso"; +import { composeStories } from "@storybook/react-vite"; +import { describe, it, expect } from "vitest"; + +import * as stories from "./RoomListView.stories"; + +const { + Default, + Loading, + Empty, + EmptyWithoutCreatePermission, + WithActiveFilter, + SmallList, + LargeList, + EmptyFavouriteFilter, + EmptyPeopleFilter, + EmptyRoomsFilter, + EmptyUnreadFilter, + EmptyInvitesFilter, + EmptyMentionsFilter, + EmptyLowPriorityFilter, +} = composeStories(stories); + +const renderWithMockContext = (component: React.ReactElement): ReturnType => { + return render(component, { + wrapper: ({ children }) => ( + + {children} + + ), + }); +}; + +describe("", () => { + it("renders Default story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders Loading story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders Empty story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyWithoutCreatePermission story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders WithActiveFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders SmallList story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders LargeList story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyFavouriteFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyPeopleFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyRoomsFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyUnreadFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyInvitesFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyMentionsFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("renders EmptyLowPriorityFilter story", () => { + const { container } = renderWithMockContext(); + expect(container).toMatchSnapshot(); + }); + + it("should call onToggleFilter when filter is clicked", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("option", { name: "People" })); + + expect(Default.args.onToggleFilter).toHaveBeenCalled(); + }); + + it("should call createRoom when New room button is clicked", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "New room" })); + + expect(Empty.args.createRoom).toHaveBeenCalled(); + }); + + it("should call createChatRoom when Start chat button is clicked", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "Start chat" })); + + expect(Empty.args.createChatRoom).toHaveBeenCalled(); + }); + + it("should call onToggleFilter when Show all chats is clicked in unread empty state", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "Show all chats" })); + + expect(EmptyUnreadFilter.args.onToggleFilter).toHaveBeenCalled(); + }); + + it("should call onToggleFilter when See all activity is clicked in invites empty state", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "See all activity" })); + + expect(EmptyInvitesFilter.args.onToggleFilter).toHaveBeenCalled(); + }); + + it("should call onToggleFilter when See all activity is clicked in mentions empty state", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "See all activity" })); + + expect(EmptyMentionsFilter.args.onToggleFilter).toHaveBeenCalled(); + }); + + it("should call onToggleFilter when See all activity is clicked in low priority empty state", async () => { + const user = userEvent.setup(); + renderWithMockContext(); + + await user.click(screen.getByRole("button", { name: "See all activity" })); + + expect(EmptyLowPriorityFilter.args.onToggleFilter).toHaveBeenCalled(); + }); +}); diff --git a/packages/shared-components/src/room-list/RoomListView/RoomListView.tsx b/packages/shared-components/src/room-list/RoomListView/RoomListView.tsx new file mode 100644 index 0000000000..0abf9aa0e1 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/RoomListView.tsx @@ -0,0 +1,101 @@ +/* + * 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, type ReactNode } from "react"; + +import { useViewModel, type ViewModel } from "../../viewmodel"; +import { RoomListPrimaryFilters, type FilterId } from "../RoomListPrimaryFilters"; +import { RoomListLoadingSkeleton } from "./RoomListLoadingSkeleton"; +import { RoomListEmptyState } from "./RoomListEmptyState"; +import { RoomList, type RoomListViewState } from "../RoomList"; +import { type RoomListItemSnapshot } from "../RoomListItem"; + +/** + * Snapshot for the room list view + */ +export type RoomListSnapshot = { + /** Whether the rooms are currently loading */ + isLoadingRooms: boolean; + /** Whether the room list is empty */ + isRoomListEmpty: boolean; + /** Array of filter IDs */ + filterIds: FilterId[]; + /** Currently active filter ID (if any) */ + activeFilterId?: FilterId; + /** Room list state */ + roomListState: RoomListViewState; + /** Array of room IDs for virtualization */ + roomIds: string[]; + /** Optional description for the empty state */ + emptyStateDescription?: string; + /** Optional action element for the empty state */ + emptyStateAction?: ReactNode; + /** Whether the user can create rooms */ + canCreateRoom?: boolean; +}; + +/** + * Actions interface for room list operations + */ +export interface RoomListViewActions { + /** Called when a filter is toggled */ + onToggleFilter: (filterId: FilterId) => void; + /** Called to create a new chat room */ + createChatRoom: () => void; + /** Called to create a new room */ + createRoom: () => void; + /** Get view model for a specific room (virtualization API) */ + getRoomItemViewModel: (roomId: string) => any; + /** Called when the visible range changes (virtualization API) */ + updateVisibleRooms: (startIndex: number, endIndex: number) => void; +} + +/** + * The view model type for the room list view + */ +export type RoomListViewModel = ViewModel & RoomListViewActions; + +/** + * Props for RoomListView component + */ +export interface RoomListViewProps { + /** The view model containing all data and callbacks */ + vm: RoomListViewModel; + /** Render function for room avatar */ + renderAvatar: (roomItem: RoomListItemSnapshot) => ReactNode; + /** Optional callback for keyboard events on the room list */ + onKeyDown?: (e: React.KeyboardEvent) => void; +} + +/** + * Room list view component that manages filters, loading states, empty states, and the room list. + */ +export const RoomListView: React.FC = ({ vm, renderAvatar, onKeyDown }): JSX.Element => { + const snapshot = useViewModel(vm); + let listBody: ReactNode; + + if (snapshot.isLoadingRooms) { + listBody = ; + } else if (snapshot.isRoomListEmpty) { + listBody = ; + } else { + listBody = ; + } + + return ( + <> +
+ +
+ {listBody} + + ); +}; diff --git a/packages/shared-components/src/room-list/RoomListView/__snapshots__/RoomListView.test.tsx.snap b/packages/shared-components/src/room-list/RoomListView/__snapshots__/RoomListView.test.tsx.snap new file mode 100644 index 0000000000..c518632039 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/__snapshots__/RoomListView.test.tsx.snap @@ -0,0 +1,11387 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders Default story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+
+
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ +
+ + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + + + + + +`; + +exports[` > renders Empty story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+ + No chats yet + + + Get started by messaging someone or by creating a room + +
+ + +
+
+
+
+`; + +exports[` > renders EmptyFavouriteFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You don't have favourite chats yet + + + You can add a chat to your favourites in the chat settings + +
+
+
+`; + +exports[` > renders EmptyInvitesFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You don't have any unread invites + + +
+
+
+`; + +exports[` > renders EmptyLowPriorityFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You don't have any low priority rooms + + +
+
+
+`; + +exports[` > renders EmptyMentionsFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You don't have any unread mentions + + +
+
+
+`; + +exports[` > renders EmptyPeopleFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You don’t have direct chats with anyone yet + + + You can deselect filters in order to see your other chats + +
+
+
+`; + +exports[` > renders EmptyRoomsFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + You’re not in any room yet + + + You can deselect filters in order to see your other chats + +
+
+
+`; + +exports[` > renders EmptyUnreadFilter story 1`] = ` +
+
+
+
+
+ + +
+
+
+
+ + Congrats! You don’t have any unread messages + + +
+
+
+`; + +exports[` > renders EmptyWithoutCreatePermission story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+ + No chats yet + + + Get started by messaging someone + +
+ +
+
+
+
+`; + +exports[` > renders LargeList story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+
+
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + + + + + + +`; + +exports[` > renders Loading story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+
+
+`; + +exports[` > renders SmallList story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+
+
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + + + +`; + +exports[` > renders WithActiveFilter story 1`] = ` +
+
+
+
+
+ + + + +
+
+
+
+
+
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + +
+
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + + + + + + +`; diff --git a/packages/shared-components/src/room-list/RoomListView/assets/skeleton.svg b/packages/shared-components/src/room-list/RoomListView/assets/skeleton.svg new file mode 100644 index 0000000000..adf56e4ed8 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/assets/skeleton.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/packages/shared-components/src/room-list/RoomListView/index.tsx b/packages/shared-components/src/room-list/RoomListView/index.tsx new file mode 100644 index 0000000000..ecfbb6d5a2 --- /dev/null +++ b/packages/shared-components/src/room-list/RoomListView/index.tsx @@ -0,0 +1,12 @@ +/* + * 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. + */ + +export { RoomListView } from "./RoomListView"; +export type { RoomListViewProps, RoomListViewModel, RoomListSnapshot, RoomListViewActions } from "./RoomListView"; +export { RoomListLoadingSkeleton } from "./RoomListLoadingSkeleton"; +export { RoomListEmptyState } from "./RoomListEmptyState"; +export type { RoomListEmptyStateProps } from "./RoomListEmptyState";