-
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 #121 from UoaWDCC/74_history-component
74 History Component
- Loading branch information
Showing
9 changed files
with
174 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import History from "@/components/history/History"; | ||
import { aboutPageSchema, TimelineElement } from "@/schemas/single/AboutPage"; | ||
import fetchStrapi from "@/util/strapi"; | ||
|
||
export default async function HistoryTest() { | ||
const data = await fetchStrapi("about-page", aboutPageSchema); | ||
|
||
// Get Timeline part of About Page (with Date objects) | ||
const timelineElements: TimelineElement[] = data.Timeline.map((e) => { | ||
const date = new Date(e.Date); | ||
return { | ||
...e, | ||
Date: date, | ||
}; | ||
}); | ||
|
||
return ( | ||
<div className="mt-56"> | ||
<History timelineElements={timelineElements} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type FloatingDateProps = { | ||
date: Date; | ||
position: "top" | "bottom"; // Position of the main component | ||
}; | ||
|
||
export default function FloatingDate({ date, position }: FloatingDateProps) { | ||
const positionStyle = position === "top" ? "-bottom-10" : "-top-10"; | ||
|
||
return ( | ||
<div | ||
className={`absolute ${positionStyle} px-6 py-4 text-white text-xs font-bold`} | ||
> | ||
{date.toLocaleDateString()} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { TimelineElement } from "@/schemas/single/AboutPage"; | ||
import HistoryComponent from "./HistoryComponent"; | ||
|
||
type HistoryComponentProps = { | ||
timelineElements: TimelineElement[]; | ||
}; | ||
|
||
export default function History({ timelineElements }: HistoryComponentProps) { | ||
// Sort timeline by date | ||
const sortedTimelineElements: TimelineElement[] = timelineElements.sort( | ||
(a, b) => a.Date.getTime() - b.Date.getTime(), | ||
); | ||
|
||
// Split timeline + map TimelineElements -> components | ||
const topTimeline: TimelineElement[] = []; | ||
const bottomTimeline: TimelineElement[] = []; | ||
for (let i = 0; i < sortedTimelineElements.length; i++) { | ||
if (i % 2 == 0) { | ||
// Even elements go on top | ||
topTimeline.push(sortedTimelineElements[i]); | ||
} else { | ||
// Odd elements go on bottom | ||
bottomTimeline.push(sortedTimelineElements[i]); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="mx-16"> | ||
<div className="flex items-end"> | ||
{topTimeline.map((element) => ( | ||
<HistoryComponent element={element} position="top" /> | ||
))} | ||
</div> | ||
<div className="bg-white h-1 w-full" /> | ||
<div className="flex items-start ml-[12rem]"> | ||
{bottomTimeline.map((element) => ( | ||
<HistoryComponent element={element} position="bottom" /> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
ImageTimelineElement, | ||
TextTimelineElement, | ||
TimelineElement, | ||
} from "@/schemas/single/AboutPage"; | ||
import { getLargestImageUrl } from "@/util/image"; | ||
import HistoryImage from "./HistoryImage"; | ||
import HistoryText from "./HistoryText"; | ||
import FloatingDate from "./FloatingDate"; | ||
|
||
type HistoryComponentProps = { | ||
element: TimelineElement; | ||
position: "top" | "bottom"; | ||
}; | ||
|
||
export default function HistoryComponent({ | ||
element, | ||
position, | ||
}: HistoryComponentProps) { | ||
const line = <div className="bg-white w-1 h-14" />; | ||
const hasLineAbove = position === "bottom"; | ||
|
||
return ( | ||
<div className="relative flex flex-col items-center mx-12 h-56 w-72"> | ||
{hasLineAbove && line} | ||
{elementToComponent(element)} | ||
{!hasLineAbove && line} | ||
<FloatingDate date={element.Date} position={position} /> | ||
</div> | ||
); | ||
} | ||
|
||
// TimelineElement -> React component | ||
function elementToComponent(element: TimelineElement): React.ReactNode { | ||
if (element.__component == "project-timeline.text-timeline-item") { | ||
// Text components | ||
const textElement = element as TextTimelineElement; | ||
return ( | ||
<HistoryText | ||
title={textElement.Title} | ||
description={textElement.Description} | ||
/> | ||
); | ||
} else { | ||
// Image components | ||
const imageElement = element as ImageTimelineElement; | ||
return <HistoryImage src={getLargestImageUrl(imageElement.Image)} />; | ||
} | ||
} |
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,17 @@ | ||
import Image from "next/image"; | ||
|
||
type HistoryImageProps = { | ||
src: string; | ||
}; | ||
|
||
export default function HistoryImage({ src }: HistoryImageProps) { | ||
return ( | ||
<Image | ||
src={src} | ||
alt="" | ||
width={256} | ||
height={170} | ||
className="h-full w-auto rounded-3xl shadow-lg" | ||
/> | ||
); | ||
} |
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,14 @@ | ||
type HistoryTextProps = { | ||
title: string; | ||
description: string; | ||
}; | ||
|
||
export default function HistoryText({ title, description }: HistoryTextProps) { | ||
return ( | ||
<div className="bg-b-orange text-b-dark-blue px-6 py-4 rounded-3xl shadow-lg h-full w-full overflow-hidden"> | ||
{" "} | ||
<h1 className="text-lg font-semibold mb-2">{title}</h1> | ||
<p className="mb-4 text-base font-normal ">{description}</p> | ||
</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