From 69f6b961f7a7a287e339a83247c8ba56c1f2f3ad Mon Sep 17 00:00:00 2001 From: Daria Oldenburg Date: Tue, 26 Nov 2024 20:31:22 +0100 Subject: [PATCH] feat(pagination): update design and logic for pagination --- .../calling/FullscreenVideoCall.tsx | 54 +++++++- src/script/components/calling/Pagination.tsx | 49 +++---- .../calling/useSyncCurrentRange.test.ts | 122 ++++++++++++++++++ .../components/calling/useSyncCurrentRange.ts | 53 ++++++++ 4 files changed, 244 insertions(+), 34 deletions(-) create mode 100644 src/script/components/calling/useSyncCurrentRange.test.ts create mode 100644 src/script/components/calling/useSyncCurrentRange.ts diff --git a/src/script/components/calling/FullscreenVideoCall.tsx b/src/script/components/calling/FullscreenVideoCall.tsx index 67290ca6ab1..5587562ba2f 100644 --- a/src/script/components/calling/FullscreenVideoCall.tsx +++ b/src/script/components/calling/FullscreenVideoCall.tsx @@ -66,6 +66,7 @@ import { } from './FullscreenVideoCall.styles'; import {GroupVideoGrid} from './GroupVideoGrid'; import {Pagination} from './Pagination'; +import {useSyncCurrentRange} from './useSyncCurrentRange'; import type {Call} from '../../calling/Call'; import {CallingViewMode, CallState, MuteState} from '../../calling/CallState'; @@ -113,6 +114,8 @@ const EMOJIS_LIST = ['👍', '🎉', '❤️', '😂', '😮', '👏', '🤔', ' const LOCAL_STORAGE_KEY_FOR_SCREEN_SHARING_CONFIRM_MODAL = 'DO_NOT_ASK_AGAIN_FOR_SCREEN_SHARING_CONFIRM_MODAL'; +const DEFAULT_VISIBLE_DOTS = 5; + const FullscreenVideoCall: React.FC = ({ call, canShareScreen, @@ -399,6 +402,46 @@ const FullscreenVideoCall: React.FC = ({ const isModerator = selfUser && roles[selfUser.id] === DefaultConversationRoleName.WIRE_ADMIN; + const [currentStart, setCurrentStart] = useState(0); + const visibleDots = DEFAULT_VISIBLE_DOTS > totalPages ? totalPages : DEFAULT_VISIBLE_DOTS; + + useSyncCurrentRange({ + currentStart, + currentPage, + totalPages, + visibleDots, + setCurrentStart, + }); + + const handlePreviousPage = () => { + if (currentPage === 0) { + return; + } + + const previousPage = currentPage - 1; + + // previousPage !== 0 --> jest niepotrzebne prawdopodnie + if (previousPage === currentStart && previousPage !== 0) { + setCurrentStart(currentStart => currentStart - 1); + } + + changePage(previousPage, call); + }; + + const handleNextPage = () => { + if (currentPage === totalPages - 1) { + return; + } + + const nextPage = currentPage + 1; + + if (nextPage === currentStart + visibleDots - 1 && nextPage !== totalPages - 1) { + setCurrentStart(currentStart => currentStart + 1); + } + + changePage(nextPage, call); + }; + return (
@@ -450,8 +493,8 @@ const FullscreenVideoCall: React.FC = ({