-
Notifications
You must be signed in to change notification settings - Fork 6
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 #579 from IT-Start-Gjovik/development
Show previous events
- Loading branch information
Showing
9 changed files
with
186 additions
and
56 deletions.
There are no files selected for viewing
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
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,9 +1,87 @@ | ||
export default function NoEvents() { | ||
'use client'; | ||
import { useState, useRef, useEffect } from 'react'; | ||
import { EventCardType } from '@/types/EventCardType'; | ||
import getDateTimeFormat from '@/utils/date'; | ||
import MiniEventCard from '../events/miniEventCard'; | ||
import Button from '../Button/button'; | ||
|
||
const DEFAULT_VISIBLE_COUNT = 4; | ||
|
||
export default function NoEvents({ events }: { events: EventCardType[] }) { | ||
const [showPreviousEvents, setShowPreviousEvents] = useState(false); | ||
const [visibleCount, setVisibleCount] = useState(DEFAULT_VISIBLE_COUNT); | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const buttonContainerRef = useRef<HTMLDivElement>(null); | ||
const [containerHeight, setContainerHeight] = useState('0px'); | ||
|
||
const previousEvents = events.filter( | ||
(event) => new Date(event.datetime) < new Date(), | ||
); | ||
|
||
const loadMoreEvents = () => { | ||
setVisibleCount((prevCount) => prevCount + DEFAULT_VISIBLE_COUNT); | ||
|
||
setTimeout(() => { | ||
buttonContainerRef.current?.scrollIntoView({ | ||
behavior: 'smooth', | ||
block: 'center', | ||
}); | ||
}, 100); | ||
}; | ||
|
||
useEffect(() => { | ||
if (containerRef.current) { | ||
setContainerHeight( | ||
showPreviousEvents | ||
? `${containerRef.current.scrollHeight}px` | ||
: '0px', | ||
); | ||
} | ||
}, [showPreviousEvents, visibleCount]); | ||
|
||
return ( | ||
<div className='flex flex-col justify-center items-center'> | ||
<h2 className='text-[#132D4E] xl:text-lg text-md text-center font-semibold'> | ||
Foreløpig ingen planlagte arrangementer... | ||
</h2> | ||
<div className='min-h-full mt-4 px-2'> | ||
<div className='flex flex-col items-center'> | ||
<Button | ||
onClick={() => { | ||
setShowPreviousEvents(!showPreviousEvents); | ||
if (!showPreviousEvents) | ||
setVisibleCount(DEFAULT_VISIBLE_COUNT); | ||
}} | ||
text={ | ||
showPreviousEvents | ||
? 'Skjul tidligere arrangementer' | ||
: 'Vis tidligere arrangementer' | ||
} | ||
/> | ||
</div> | ||
<div | ||
ref={containerRef} | ||
className='transition-max-height duration-500 ease-in-out overflow-hidden' | ||
style={{ maxHeight: containerHeight }}> | ||
<div className='mt-2 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4'> | ||
{previousEvents.slice(0, visibleCount).map((event) => { | ||
const { timeFormat } = getDateTimeFormat(event.datetime); | ||
|
||
return ( | ||
<MiniEventCard | ||
key={event._id} | ||
imageUrl={event.image} | ||
title={event.title} | ||
date={new Date(event.datetime).toLocaleDateString( | ||
'en-GB', | ||
)} | ||
time={timeFormat} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
{showPreviousEvents && visibleCount < previousEvents.length && ( | ||
<div ref={buttonContainerRef} className='flex justify-center mt-4'> | ||
<Button text='Vis flere' onClick={loadMoreEvents} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Image from 'next/image'; | ||
|
||
interface MiniEventProps { | ||
imageUrl: string; | ||
title: string; | ||
date?: string; | ||
time?: string; | ||
} | ||
|
||
const MiniEventCard: React.FC<MiniEventProps> = ({ | ||
imageUrl, | ||
title, | ||
date, | ||
time, | ||
}) => { | ||
return ( | ||
<div className='p-10 relative max-w-56 max-h-44 rounded-xl overflow-hidden shadow-md m-2 flex items-center justify-center text-white'> | ||
<Image | ||
src={imageUrl} | ||
alt='event image' | ||
layout='fill' | ||
objectFit='cover' | ||
className='absolute inset-0 w-full h-full object-cover' | ||
/> | ||
|
||
<div className='absolute inset-0 bg-black bg-opacity-50'></div> | ||
|
||
<div className='relative z-10 text-center px-1'> | ||
<p className='text-md font-semibold'>{title}</p> | ||
<p className='text-sm'>{date}</p> | ||
<p className='text-sm'>{time}</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MiniEventCard; |