From bcb8379b7a4efc6a1dbef1b60d9c6094adc62737 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 26 Jul 2022 03:23:10 -0400 Subject: [PATCH] Profile w2l pagination --- .../Profile_W2lTemplateListFc.tsx | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/packages/fakeyou/src/v2/view/profile/profile_view/Profile_W2lTemplateListFc.tsx b/packages/fakeyou/src/v2/view/profile/profile_view/Profile_W2lTemplateListFc.tsx index d3d3a26c2a..ca8d5abd6c 100644 --- a/packages/fakeyou/src/v2/view/profile/profile_view/Profile_W2lTemplateListFc.tsx +++ b/packages/fakeyou/src/v2/view/profile/profile_view/Profile_W2lTemplateListFc.tsx @@ -1,11 +1,15 @@ import React, { useState, useEffect } from "react"; import { ApiConfig } from "@storyteller/components"; import { Link } from "react-router-dom"; -//import { getRandomInt } from '../../../../v1/api/Utils'; import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; import { distance, duration } from "../../../../data/animation"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons"; + const Fade = require("react-reveal/Fade"); +const PER_PAGE = 8; + interface W2lTemplateListResponsePayload { success: boolean; templates: Array; @@ -15,8 +19,8 @@ interface W2lTemplate { template_token: string; template_type: string; creator_user_token: string; - username: string; - display_name: string; + creator_username: string; + creator_display_name: string; title: string; frame_width: number; frame_height: number; @@ -33,6 +37,7 @@ interface Props { function ProfileW2lTemplateListFc(props: Props) { const [w2lTemplates, setW2lTemplates] = useState>([]); + const [currentPageIndex, setCurrentPageIndex] = useState(0); useEffect(() => { const api = new ApiConfig(); @@ -59,9 +64,21 @@ function ProfileW2lTemplateListFc(props: Props) { }); }, [props.username]); // NB: Empty array dependency sets to run ONLY on mount + const nextPage = () => { + setCurrentPageIndex(currentPageIndex + 1); + }; + + const previousPage = () => { + setCurrentPageIndex(Math.max(currentPageIndex - 1, 0)); + }; + let templateElements: Array = []; - w2lTemplates.slice(0, 8).forEach((t) => { + const start = currentPageIndex * PER_PAGE; + const end = start + PER_PAGE; + const pageW2lTemplates = w2lTemplates.slice(start, end); + + pageW2lTemplates.forEach((t) => { let object = null; if ( @@ -87,8 +104,8 @@ function ProfileW2lTemplateListFc(props: Props) {
-
Title
-

by NAME

+
{t.title}
+

by {t.creator_display_name}

@@ -99,13 +116,12 @@ function ProfileW2lTemplateListFc(props: Props) { let allRowsOfTemplateElements: Array = []; let rowOfTemplateElements: Array = []; - //let nextRowSize = getRandomInt(3, 4); - let nextRowSize = 1; - // NB: To prevent React spamming about children having unique key props let rowKey = "row0"; let rowIndex = 0; + let nextRowSize = 1; + templateElements.forEach((el) => { rowOfTemplateElements.push(el); @@ -143,11 +159,35 @@ function ProfileW2lTemplateListFc(props: Props) { rowOfTemplateElements = []; } + const isLastButtonDisabled = currentPageIndex < 1; + const isNextButtonDisabled = w2lTemplates.length === 0 || end > w2lTemplates.length; + return (
{allRowsOfTemplateElements.map((el) => el)}
+
+ + + +
); }