-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from jakkemomo/feature/add_profile_events_lists
feat: add EventSliders on ProfilePage
- Loading branch information
Showing
25 changed files
with
472 additions
and
191 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,36 @@ | ||
import { SlickSlider } from "@/shared"; | ||
import { ISlickSliderProps } from "@/shared/ui/SlickSlider/SlickSlider"; | ||
import { ReactElement, useEffect, useState } from "react"; | ||
import { IEvent } from "@/entities/event/model/types"; | ||
import { EventCard } from "@/entities/event"; | ||
|
||
interface IEventSlider { | ||
events: IEvent[]; | ||
export interface IEventSlider extends Omit<ISlickSliderProps, 'extraSettings'> { | ||
slidesLength: number; | ||
} | ||
|
||
export function EventSlider({ events }: IEventSlider): ReactElement { | ||
const cards = events.map((el) => <EventCard key={el.id} event={el} />); | ||
|
||
const [width, setWidth] = useState(103.7); | ||
const [slidesToShow, setSlidesToShow] = useState(4); | ||
export function EventSlider({ children, slidesLength, arrowsExtraClasses }: IEventSlider): ReactElement { | ||
const [slidesToShow, setSlidesToShow] = useState(slidesLength); | ||
const [sliderWidth, setSliderWidth] = useState(100); | ||
|
||
useEffect(() => { | ||
switch (events.length) { | ||
case 1: | ||
setWidth(26); | ||
setSlidesToShow(1); | ||
break | ||
case 2: | ||
setWidth(52); | ||
setSlidesToShow(2); | ||
break | ||
case 3: | ||
setWidth(78); | ||
setSlidesToShow(3); | ||
break | ||
default: | ||
setWidth(103.7); | ||
setSlidesToShow(4); | ||
if (children.length < slidesLength) { | ||
setSlidesToShow(children.length); | ||
setSliderWidth(100 - ((slidesLength - children.length) * (100 / slidesLength))); | ||
} else { | ||
setSlidesToShow(slidesLength); | ||
setSliderWidth(100); | ||
} | ||
}, [events.length]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [children.length]); | ||
|
||
const settings = { | ||
slidesToShow, | ||
slidesToScroll: 2, | ||
speed: 400, | ||
className: `mt-3 w-[${width}%] min-h-[230px]` | ||
className: `mt-5 max-w-[${String(sliderWidth).slice(0, 4)}%] min-h-[230px]` | ||
} | ||
|
||
return ( | ||
<SlickSlider extraSettings={settings} arrowsExtraClasses={{rightArrow: 'right-[-12px] top-[110px]', leftArrow: 'left-[-42px] top-[110px]'}}> | ||
{cards} | ||
<SlickSlider extraSettings={settings} arrowsExtraClasses={arrowsExtraClasses}> | ||
{children} | ||
</SlickSlider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.