Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sorting in paginated grid #1129

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions packages/client/src/sorting/__tests__/presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,50 @@ describe('presets', () => {
},
}));

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'F',
'B',
'E',
'D',
'A',
'C',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"F",
"D",
"A",
"B",
"C",
"E",
]
`);

// server-pin C
ps.at(-1)!.pin = {
isLocalPin: false,
pinnedAt: Date.now(),
};

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'C',
'F',
'B',
'E',
'D',
'A',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"E",
"F",
"D",
"A",
"B",
"C",
]
`);

ps.at(-3)!.publishedTracks = [TrackType.AUDIO]; // E
ps.at(-2)!.isDominantSpeaker = false; // D
ps.at(-1)!.isDominantSpeaker = true; // A

expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name)).toEqual([
'C',
'F',
'B',
'A',
'E',
'D',
]);
expect(ps.sort(paginatedLayoutSortPreset).map((p) => p.name))
.toMatchInlineSnapshot(`
[
"E",
"F",
"D",
"C",
"B",
"A",
]
`);
});
});
3 changes: 1 addition & 2 deletions packages/client/src/sorting/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export const speakerLayoutSortPreset = combineComparators(
*/
export const paginatedLayoutSortPreset = combineComparators(
pinned,
screenSharing,
dominantSpeaker,
ifInvisibleOrUnknownBy(dominantSpeaker),
ifInvisibleOrUnknownBy(speaking),
ifInvisibleOrUnknownBy(reactionType('raised-hand')),
ifInvisibleOrUnknownBy(publishingVideo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const PaginatedGridLayout = ({
ParticipantViewUI = DefaultParticipantViewUI,
}: PaginatedGridLayoutProps) => {
const [page, setPage] = useState(0);
const [
paginatedGridLayoutWrapperElement,
setPaginatedGridLayoutWrapperElement,
] = useState<HTMLDivElement | null>(null);

const call = useCall();
const { useParticipants, useRemoteParticipants } = useCallStateHooks();
Expand All @@ -88,6 +92,14 @@ export const PaginatedGridLayout = ({

usePaginatedLayoutSortPreset(call);

useEffect(() => {
if (!paginatedGridLayoutWrapperElement || !call) return;

const cleanup = call.setViewport(paginatedGridLayoutWrapperElement);

return () => cleanup();
}, [paginatedGridLayoutWrapperElement, call]);

// only used to render video elements
const participantGroups = useMemo(
() =>
Expand All @@ -112,7 +124,10 @@ export const PaginatedGridLayout = ({
if (!call) return null;

return (
<div className="str-video__paginated-grid-layout__wrapper">
<div
className="str-video__paginated-grid-layout__wrapper"
ref={setPaginatedGridLayoutWrapperElement}
>
<ParticipantsAudio participants={remoteParticipants} />
<div className="str-video__paginated-grid-layout">
{pageArrowsVisible && pageCount > 1 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const SpeakerLayout = ({
if (!participantsBarWrapperElement || !call) return;

const cleanup = call.setViewport(participantsBarWrapperElement);

return () => cleanup();
}, [participantsBarWrapperElement, call]);

Expand Down
Loading