Skip to content

Commit

Permalink
Merge pull request #579 from IT-Start-Gjovik/development
Browse files Browse the repository at this point in the history
Show previous events
  • Loading branch information
Mosazghi authored Nov 9, 2024
2 parents 0062243 + a36f05b commit 16474d3
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 56 deletions.
39 changes: 27 additions & 12 deletions app/(site)/arrangementer/[eventPage]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function PageForEvent({ params }: Props) {

// Information time and date formatted correctly
let { dateFormat, timeFormat } = getDateTimeFormat(eventPage.datetime);
let isOver: Boolean = new Date() > new Date(eventPage.datetime);
let isOver: boolean = new Date() > new Date(eventPage.datetime);

const EventOverBadge = () => {
return isOver ? (
Expand Down Expand Up @@ -77,20 +77,20 @@ export default function PageForEvent({ params }: Props) {

<PortableText
value={eventPage.content}
// @ts-ignore
components={RichTextComponent}
/>

<div className='mt-6 flex justify-center items-center space-x-4 text-white'>
<BackButton
link='/'
text='Tilbake'
direction='left'
disabled={isOver}
/>
<BackButton link='/' text='Tilbake' direction='left' />
<BackButton
link={eventPage.url}
text='Påmelding'
direction='right'
disabled={isOver}
style={{
cursor: isOver ? 'not-allowed' : 'pointer',
}}
/>
</div>
</div>
Expand All @@ -100,13 +100,14 @@ export default function PageForEvent({ params }: Props) {
);
}

const RichTextComponent = {
const RichTextComponent = {
block: {
h1: ({ children }: any) => <h1 className='text-4xl'>{children}</h1>,
h2: ({ children }: any) => <h1 className='text-3xl'>{children}</h1>,
h3: ({ children }: any) => <h1 className='text-2l'>{children}</h1>,
h4: ({ children }: any) => <h1 className='text-xl'>{children}</h1>,
h5: ({ children }: any) => <h1 className='text-lg'>{children}</h1>,
h2: ({ children }: any) => <h2 className='text-3xl'>{children}</h2>,
h3: ({ children }: any) => <h3 className='text-2xl'>{children}</h3>,
h4: ({ children }: any) => <h4 className='text-xl'>{children}</h4>,
h5: ({ children }: any) => <h5 className='text-lg'>{children}</h5>,
normal: ({ children }: any) => <p className='text-base'>{children}</p>, // Default for normal paragraphs
},
marks: {
link: ({ children, value }: any) => {
Expand Down Expand Up @@ -137,4 +138,18 @@ const RichTextComponent = {
);
},
},
list: {
bullet: ({ children }: { children: any }) => (
<ul className='list-disc ml-4'>{children}</ul>
),

number: ({ children }: { children: any }) => (
<ol className='list-decimal ml-4'>{children}</ol>
),
},
listItem: {
bullet: ({ children }: { children: any }) => <li>{children}</li>,
number: ({ children }: { children: any }) => <li>{children}</li>,
},
hardBreak: () => <br />,
};
2 changes: 1 addition & 1 deletion app/(site)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async function Home() {
return (
<div className='flex flex-col overflow-y-auto min-h-screen bg-gradient-to-tl from-gradient-end via-gradient-mid to-gradient-start'>
{/** Header */}
<main className='min-h-screen'>
<main className=''>
<Hero {...homePageProps} imageSrc={homePic?.asset.url || ''} />
{/**List of events */}
<EventSection events={events}></EventSection>
Expand Down
2 changes: 1 addition & 1 deletion backend/sanity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getEventCards(): Promise<EventCardType[]> {
const currentDate = new Date().toISOString();

return client.fetch(
groq`*[_type == "event" && datetime > $currentDate] | order(datetime asc){
groq`*[_type == "event"] | order(datetime asc){
_id,
title,
description,
Expand Down
28 changes: 14 additions & 14 deletions components/Button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactNode, ButtonHTMLAttributes } from 'react';

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
text: string;
link: string;
link?: string;
dark?: boolean;
adaptiv?: boolean;
children?: ReactNode;
Expand All @@ -18,18 +18,18 @@ export default function Button({
children,
...rest
}: ButtonProps) {
return (
<Link href={link}>
<button
className={`ring-2 ${children && 'flex flex-row items-center'}
${dark ? 'bg-btn-secondary text-bg-primary-dark ring-white hover:text-bg-primary' : 'bg-btn-secondary-dark ring-bg-primary-dark hover:text-black'}
hover:bg-transparent hover:ease-out hover:duration-300
rounded-full font-semibold text-xl py-3 px-5 my-3
${adaptiv ? 'w-full' : 'w-auto'}`}
{...rest}>
{text}
{children && <span>{children}</span>}
</button>
</Link>
const buttonElement = (
<button
className={`ring-2 ${children && 'flex flex-row items-center'}
${dark ? 'bg-btn-secondary text-bg-primary-dark ring-white hover:text-bg-primary' : 'bg-btn-secondary-dark ring-bg-primary-dark hover:text-black'}
hover:bg-transparent hover:ease-out hover:duration-300
rounded-full font-semibold text-xl py-3 px-5 my-3
${adaptiv ? 'w-full' : 'w-auto'}`}
{...rest}>
{text}
{children && <span>{children}</span>}
</button>
);

return link ? <Link href={link}>{buttonElement}</Link> : buttonElement;
}
3 changes: 2 additions & 1 deletion components/UI/backbutton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ButtonHTMLAttributes } from 'react';
import Button from '../Button/button';

interface ButtonProps {
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
link: string;
text: string;
direction?: 'left' | 'right';
Expand Down
88 changes: 83 additions & 5 deletions components/UI/noEventsFound.tsx
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>
);
}
39 changes: 20 additions & 19 deletions components/eventSection/eventSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import NoEvents from '../UI/noEventsFound';
import EventCardList from '../events/eventCardList';

export default function EventSection({ events }: { events: EventCardType[] }) {
const validEvents = events.filter(
(event) => new Date(event.datetime) > new Date(),
);
let previousEvents = events.filter(
(event) => new Date(event.datetime) < new Date(),
);
previousEvents = [...previousEvents, ...previousEvents, ...previousEvents];
return (
<>
{/**List of events */}
<div className='bg-white pt-10 pb-3'>
<h3 className='text-[#132D4E] font-semibold md:text-center text-4xl md:text-5xl py-5 px-8'>
Kommende arrangementer
</h3>
<div className='bg-white pt-10 pb-3'>
<h3 className='text-[#132D4E] font-semibold md:text-center text-4xl md:text-5xl py-5 px-8'>
Kommende arrangementer
</h3>

{/** Listing all events if there are any */}
<div
id='allEvents'
className='flex flex-wrap justify-center gap-6 p-8'>
{events && events.length > 0 ? (
<>
<EventCardList events={events} />
</>
) : (
<NoEvents />
)}
</div>
<div id='allEvents' className='flex flex-wrap justify-center gap-6 p-2'>
{events && validEvents.length > 0 ? (
<>
<EventCardList events={validEvents} />
</>
) : (
<NoEvents events={previousEvents} />
)}
</div>
</>
</div>
);
}
4 changes: 1 addition & 3 deletions components/events/eventCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Image from 'next/image';
import Button from '../Button/button';

// Interface for the event card
interface EventProps {
imageUrl: string;
title: string;
Expand All @@ -11,7 +10,6 @@ interface EventProps {
slug: string;
}

// Event card itself
const EventCard: React.FC<EventProps> = ({
date,
title,
Expand All @@ -29,7 +27,7 @@ const EventCard: React.FC<EventProps> = ({
alt='event image'
layout='fill'
objectFit='cover'
className='rounded-t-[50px] opacity-70 '
className='rounded-t-[50px] opacity-60'
/>
<div className='absolute inset-0 flex flex-col items-center justify-end mb-5'>
<p className='text-[36px] font-bold text-center'>{title}</p>
Expand Down
37 changes: 37 additions & 0 deletions components/events/miniEventCard.tsx
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;

0 comments on commit 16474d3

Please sign in to comment.