Files
element-call/src/grid/SpotlightLandscapeLayout.tsx

84 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-05-17 16:38:00 -04:00
/*
Copyright 2024 New Vector Ltd.
2024-05-17 16:38:00 -04:00
SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
2024-05-17 16:38:00 -04:00
*/
import { forwardRef, useMemo } from "react";
2024-05-17 16:38:00 -04:00
import { useObservableEagerState } from "observable-hooks";
import classNames from "classnames";
2024-05-17 16:38:00 -04:00
import { CallLayout, GridTileModel, TileModel } from "./CallLayout";
import { SpotlightLandscapeLayout as SpotlightLandscapeLayoutModel } from "../state/CallViewModel";
import styles from "./SpotlightLandscapeLayout.module.css";
2024-07-25 12:50:28 -04:00
import { useUpdateLayout } from "./Grid";
2024-05-17 16:38:00 -04:00
2024-07-18 11:33:20 -04:00
/**
* An implementation of the "spotlight landscape" layout, in which the spotlight
* tile takes up most of the space on the left, and the grid of participants is
* shown as a scrolling rail on the right.
*/
export const makeSpotlightLandscapeLayout: CallLayout<
SpotlightLandscapeLayoutModel
> = ({ minBounds }) => ({
scrollingOnTop: false,
2024-05-17 16:38:00 -04:00
fixed: forwardRef(function SpotlightLandscapeLayoutFixed(
{ model, Slot },
ref,
) {
2024-07-25 12:50:28 -04:00
useUpdateLayout();
useObservableEagerState(minBounds);
const tileModel: TileModel = useMemo(
() => ({
type: "spotlight",
vms: model.spotlight,
maximised: false,
}),
[model.spotlight],
);
2024-05-17 16:38:00 -04:00
return (
<div ref={ref} className={styles.layer}>
<div className={styles.spotlight}>
<Slot className={styles.slot} id="spotlight" model={tileModel} />
2024-05-17 16:38:00 -04:00
</div>
<div className={styles.grid} />
</div>
);
}),
2024-05-17 16:38:00 -04:00
scrolling: forwardRef(function SpotlightLandscapeLayoutScrolling(
{ model, Slot },
ref,
) {
2024-07-25 12:50:28 -04:00
useUpdateLayout();
useObservableEagerState(minBounds);
const tileModels: GridTileModel[] = useMemo(
() => model.grid.map((vm) => ({ type: "grid", vm })),
[model.grid],
);
2024-05-17 16:38:00 -04:00
return (
<div ref={ref} className={styles.layer}>
2024-05-17 16:38:00 -04:00
<div
className={classNames(styles.spotlight, {
[styles.withIndicators]: model.spotlight.length > 1,
})}
/>
<div className={styles.grid}>
{tileModels.map((m) => (
<Slot
key={m.vm.id}
className={styles.slot}
id={m.vm.id}
model={m}
/>
))}
2024-05-17 16:38:00 -04:00
</div>
</div>
);
}),
2024-05-17 16:38:00 -04:00
});