From 80f2965697359ae94fa9f008b0959bef40576e08 Mon Sep 17 00:00:00 2001 From: Adetoye Adewoye <71382301+adetoye-dev@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:40:26 +0100 Subject: [PATCH] Create RHS cards slider --- src/components/RHSCardSlides.tsx | 147 +++++++++++++++++++++++++++++++ tailwind.config.js | 5 ++ 2 files changed, 152 insertions(+) create mode 100644 src/components/RHSCardSlides.tsx diff --git a/src/components/RHSCardSlides.tsx b/src/components/RHSCardSlides.tsx new file mode 100644 index 0000000000..e79e24e0c3 --- /dev/null +++ b/src/components/RHSCardSlides.tsx @@ -0,0 +1,147 @@ +// Copyright 2019-2025 @polkassembly/polkassembly authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import Image from 'next/image'; +import React, { useState, useEffect } from 'react'; +import NavigateNextIcon from '~assets/icons/navigate-next.svg'; +import NavigatePrevIcon from '~assets/icons/navigate-prev.svg'; +import { usePostDataContext } from '~src/context'; +import { useUserDetailsSelector } from '~src/redux/selectors'; + +type card = { title: string; description: string; icon: string; tag: string }; + +enum cardTags { + ADD_DEADLINE = 'add-deadline', + LINK_DISCUSSION = 'link-discussion', + DECISION_DEPOSIT = 'decision-deposit', + ADD_TAGS = 'add-tags' +} + +const cardsData: card[] = [ + { + description: 'Deadlines increase accountability and improve likelihood of success.', + icon: '/assets/icons/rhs-card-icons/Calendar.png', + tag: cardTags.ADD_DEADLINE, + title: 'Add Deadline' + }, + { + description: 'Please add contextual info for voters to make an informed decision', + icon: '/assets/icons/rhs-card-icons/Doc.png', + tag: cardTags.LINK_DISCUSSION, + title: 'Link Discussion' + }, + { description: 'Please include relevant tags to enhance post discoverability.', icon: '/assets/icons/rhs-card-icons/Plus.png', tag: 'add-tags', title: cardTags.ADD_TAGS }, + { + description: 'To be paid before completion of decision period; payable by anyone', + icon: '/assets/icons/rhs-card-icons/Crystal.png', + tag: cardTags.DECISION_DEPOSIT, + title: 'Decision Deposit' + } +]; + +const RHSCardSlides = () => { + const [currentIndex, setCurrentIndex] = useState(0); + const [isReversed, setIsReversed] = useState(false); + const [RHSCards, setRHSCards] = useState(cardsData); + const { username } = useUserDetailsSelector(); + + const { postData } = usePostDataContext(); + + const nextSlide = () => { + setCurrentIndex((prevIndex) => { + const newIndex = prevIndex === RHSCards.length - 1 ? 0 : prevIndex + 1; + return isReversed && newIndex === 0 ? prevIndex : newIndex; + }); + }; + + const prevSlide = () => { + setCurrentIndex((prevIndex) => { + const newIndex = prevIndex === 0 ? RHSCards.length - 1 : prevIndex - 1; + return !isReversed && newIndex === RHSCards.length - 1 ? prevIndex : newIndex; + }); + }; + + useEffect(() => { + if (postData.tags.length) { + setRHSCards((prevCards) => { + return prevCards.filter((card) => card.tag !== cardTags.ADD_TAGS); + }); + } + + if (postData.post_link) { + setRHSCards((prevCards) => { + return prevCards.filter((card) => card.tag !== cardTags.LINK_DISCUSSION); + }); + } + + if (postData.username !== username) { + setRHSCards((prevCards) => { + return prevCards.filter((card) => card.tag !== cardTags.ADD_DEADLINE); + }); + } + }, [postData, username]); + + useEffect(() => { + if (RHSCards.length <= 1) { + return; + } + if (currentIndex === RHSCards.length - 1 && !isReversed) { + setIsReversed(true); + } else if (currentIndex === 0 && isReversed) { + setIsReversed(false); + } + }, [currentIndex, isReversed, RHSCards]); + + const handleTransitionButtonClick = () => { + if (!isReversed) { + nextSlide(); + } else { + prevSlide(); + } + }; + + return ( +
+
+
+
+ {!isReversed ? : } +
+
+
+ {RHSCards.map((card, index) => ( +
+ {card.title} +
+

{card.title}

+ {card.description} +
+
+ ))} +
+
+ {RHSCards.map((_, index) => ( +
+ ))} +
+
+
+ ); +}; + +export default RHSCardSlides; diff --git a/tailwind.config.js b/tailwind.config.js index 34c46f3d07..55ab7a5fa7 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -108,6 +108,11 @@ module.exports = { }, borderRadius: { xxl: '0.875rem' + }, + backgroundImage: { + 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', + 'rhs-card-gradient': 'linear-gradient(97deg, #04d9bb 0.25%, #06d7bb 0.26%, #6e49c9 112.25%)', + 'rhs-indicator-gradient': 'linear-gradient(153deg, #08D4BB 16.67%, #6F47C9 100%)' } } },