Skip to content

Commit

Permalink
Add carousel (#622)
Browse files Browse the repository at this point in the history
* add carousel

* Old react-multi-carousel

* fixed npm yarn

* remvoed packagelock.json

* fixing issues

* change height

* minor changes

* deleted a comment

* merging?

* delete one onClick

* change breakpoint
  • Loading branch information
owlester12 committed Apr 21, 2024
1 parent 29d9a12 commit fcab615
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 12 deletions.
145 changes: 145 additions & 0 deletions frontend/components/ClubPage/EventCarousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import 'react-multi-carousel/lib/styles.css'

import React, { useState } from 'react'
import Carousel from 'react-multi-carousel'
import styled from 'styled-components'

import { ClubEvent } from '../../types'
import { Icon, StrongText } from '../common'
import Modal from '../common/Modal'
import EventCard from '../EventPage/EventCard'
import EventModal from '../EventPage/EventModal'

const LeftArrow = styled.div`
left: -10px;
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 100;
opacity: 0.6;
transition-duration: 300ms;
cursor: pointer;
&:hover {
opacity: 1;
}
`
const RightArrow = styled.div`
right: -10px;
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 100;
opacity: 0.6;
transition-duration: 300ms;
cursor: pointer;
&:hover {
opacity: 1;
}
`

const CarouselWrapper = styled.div`
position: absolute;
box-sizing: border-box;
width: 100%;
`
const EventWrapper = styled.div`
@media only screen and (max-width: 580px) {
margin: 25px;
}
@media only screen and (min-width: 580px) and (max-width: 900px) {
margin: 8px;
}
@media only screen and (min-width: 900px) and (max-width: 1400px) {
margin: 12px;
}
@media only screen and (min-width: 1400px) {
margin: 5px;
}
`

type EventsProps = {
data: ClubEvent[]
}

const EventCarousel = ({ data }: EventsProps) => {
const [show, setShow] = useState(false)
const [modalData, setModalData] = useState<ClubEvent>()

const showModal = (entry: ClubEvent) => {
setModalData(entry)
setShow(true)
}
const hideModal = () => setShow(false)
const responsive = {
superLargeDesktop: {
breakpoint: { max: 4000, min: 1400 },
items: 3,
},
tablet: {
breakpoint: { max: 1400, min: 580 },
items: 2,
},
mobile: {
breakpoint: { max: 580, min: 0 },
items: 1,
},
}
return (
<div>
<div className="">
<StrongText className="mb-0">Events</StrongText>
<small>Click on an event to get more details.</small>
</div>
<div
style={{
height: '260px',
width: '100%',
boxSizing: 'border-box',
position: 'relative',
}}
>
<CarouselWrapper>
<div style={{ position: 'unset' }}>
<Carousel
responsive={responsive}
showDots={false}
draggable={true}
customLeftArrow={
<LeftArrow>
<Icon name="chevron-left" size={'2.2rem'} />
</LeftArrow>
}
customRightArrow={
<RightArrow>
<Icon name="chevron-right" size={'2.2rem'} />
</RightArrow>
}
>
{data.map((entry, index) => (
<div key={index}>
<EventWrapper>
<EventCard
event={entry}
key={index}
onClick={() => showModal(entry)}
onLinkClicked={() => hideModal()}
/>
</EventWrapper>
</div>
))}
</Carousel>
</div>
</CarouselWrapper>
</div>
{show && (
<Modal show={show} closeModal={hideModal} marginBottom={false}>
{modalData && (
<EventModal event={modalData} showDetailsButton={false} />
)}
</Modal>
)}
</div>
)
}

export default EventCarousel
10 changes: 2 additions & 8 deletions frontend/components/ClubPage/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { DARK_BLUE, HOVER_GRAY, PURPLE, WHITE } from '../../constants/colors'
import { M2, M3 } from '../../constants/measurements'
import { ClubEvent, ClubEventType } from '../../types'
import { Card, Icon, StrongText } from '../common'
import Modal from '../common/Modal'
import EventModal from '../EventPage/EventModal'

type EventsProps = {
data: ClubEvent[]
Expand All @@ -31,7 +29,8 @@ const Wrapper = styled.div`
margin-bottom: 0.5rem;
display: flex;
cursor: pointer;
border-radius: 3px;
border-radius: 8px;
padding: 2px;
&:hover {
background-color: ${HOVER_GRAY};
Expand Down Expand Up @@ -70,11 +69,6 @@ const Event = ({ entry }: { entry: ClubEvent }): ReactElement => {
</SmallParagraph>
</div>
</Wrapper>
{show && (
<Modal show={show} closeModal={hideModal} marginBottom={false}>
<EventModal event={entry} showDetailsButton={false} />
</Modal>
)}
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/EventPage/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ const EventCard = (props: {
{clipLink(url)}
</EventLink>
))}
{(badges.length > 0 || pinned) && (
{(badges?.length > 0 || pinned) && (
<div className="tags mt-2">
{pinned && (
<span className="tag is-primary">
<Icon name="map-pin" className="mr-1" /> Pinned
</span>
)}
{badges.map(({ id, label }) => (
{badges?.map(({ id, label }) => (
<span key={id} className="tag is-info">
{label}
</span>
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-ga": "^3.3.1",
"react-lazy-load": "^4.0.1",
"react-linkify": "^1.0.0-alpha",
"react-multi-carousel": "^2.8.5",
"react-places-autocomplete": "^7.3.0",
"react-select": "^5.8.0",
"react-table": "^7.8.0",
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/club/[club]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DesktopActions, MobileActions } from 'components/ClubPage/Actions'
import AdvisorList from 'components/ClubPage/AdvisorList'
import ClubApprovalDialog from 'components/ClubPage/ClubApprovalDialog'
import Description from 'components/ClubPage/Description'
import Events from 'components/ClubPage/Events'
import FilesList from 'components/ClubPage/FilesList'
import Header from 'components/ClubPage/Header'
import InfoBox from 'components/ClubPage/InfoBox'
Expand Down Expand Up @@ -43,6 +42,7 @@ import {
SITE_NAME,
} from 'utils/branding'

import EventCarousel from '~/components/ClubPage/EventCarousel'
import { CLUB_ALUMNI_ROUTE, CLUB_ORG_ROUTE } from '~/constants'
import { CLUBS_RED, SNOW, WHITE } from '~/constants/colors'
import { M0, M2, M3 } from '~/constants/measurements'
Expand Down Expand Up @@ -268,6 +268,7 @@ const ClubPage = ({
<MemberList club={club} />
</>
)}
{events.length > 0 && <EventCarousel data={events} />}
</div>
<div className="column is-one-third">
{userInfo && (
Expand Down Expand Up @@ -296,7 +297,6 @@ const ClubPage = ({
<div dangerouslySetInnerHTML={{ __html: involvement }} />
</StyledCard>
)}
<Events data={events} />
{isClubFieldShown('signature_events') &&
signatureEvents &&
!!signatureEvents.length && (
Expand Down
5 changes: 5 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8954,6 +8954,11 @@ react-motion@^0.5.2:
prop-types "^15.5.8"
raf "^3.1.0"

react-multi-carousel@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/react-multi-carousel/-/react-multi-carousel-2.8.5.tgz#033e35426ee2d2ddd46a5b3967a654cd901a80d1"
integrity sha512-C5DAvJkfzR2JK9YixZ3oyF9x6R4LW6nzTpIXrl9Oujxi4uqP9SzVVCjl+JLM3tSdqdjAx/oWZK3dTVBSR73Q+w==

react-onclickoutside@^6.10.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.13.0.tgz#e165ea4e5157f3da94f4376a3ab3e22a565f4ffc"
Expand Down

0 comments on commit fcab615

Please sign in to comment.