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 #7 from bonz88/feat/timeline-chart
feat/timeline-chart
- Loading branch information
Showing
8 changed files
with
219 additions
and
19 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,14 @@ | ||
"use client"; | ||
import { useAppSelector } from "../../redux/store"; | ||
import TimelineDays from "./TimelineDays"; | ||
export default function Timeline() { | ||
const timeline = useAppSelector((state) => state.timeline.timeline); | ||
|
||
return ( | ||
<div className="w-[463px] h-[42px] dark:bg-[#232336] bg-[#CCCCFA] bg-opacity-40 rounded-md flex gap-2 p-1"> | ||
{timeline.map((t) => ( | ||
<TimelineDays timeline={t} key={t.id} /> | ||
))} | ||
</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,28 @@ | ||
import { useDispatch } from "react-redux"; | ||
import { AppDispatch } from "../../redux/store"; | ||
import { activeTimeline } from "../../redux/features/timelineSlice"; | ||
import { TimelineItem } from "../../redux/features/timelineSlice"; | ||
|
||
type TimelineDaysProps = { | ||
timeline: TimelineItem; | ||
}; | ||
|
||
export default function TimelineDays({ timeline }: TimelineDaysProps) { | ||
const dispatch: AppDispatch = useDispatch(); | ||
|
||
return ( | ||
<button | ||
className={`w-14 p-1 ${ | ||
timeline.active | ||
? "bg-[rgb(120,120,250,0.7)] border border-[#7878FA] shadow-md rounded-md" | ||
: "" | ||
}`} | ||
onClick={() => dispatch(activeTimeline(timeline.id))} | ||
key={timeline.id} | ||
> | ||
<span className="dark:text-[#E4E4F0] text-[#181825] text-sm"> | ||
{timeline.display} | ||
</span> | ||
</button> | ||
); | ||
} |
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,17 +1,21 @@ | ||
import NavHome from "./components/NavHome"; | ||
import CarouselCoins from "./components/CarouselCoins"; | ||
import GraphCoins from "./components/GraphCoins"; | ||
import Timeline from "./components/Timeline"; | ||
|
||
export default function Home() { | ||
return ( | ||
<main> | ||
<main className="pb-10"> | ||
<NavHome /> | ||
<div className="mt-[70px] max-w-[1440px] mx-auto xl:px-[72px] lg:px-[36px] md:px-[24px]"> | ||
<CarouselCoins /> | ||
</div> | ||
<div className="mt-10 max-w-[1440px] mx-auto xl:px-[72px] lg:px-[36px] md:px-[24px]"> | ||
<GraphCoins /> | ||
</div> | ||
<div className="mt-10 max-w-[1440px] mx-auto xl:px-[72px] lg:px-[36px] md:px-[24px]"> | ||
<Timeline /> | ||
</div> | ||
</main> | ||
); | ||
} |
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,29 @@ | ||
const formatDateGraphs = (tick: string, days: string): string => { | ||
const date = new Date(tick); | ||
let formattedDate: string; | ||
|
||
if (days === "1") { | ||
formattedDate = date.toLocaleTimeString(undefined, { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
}); | ||
} else if (["7", "14", "30"].includes(days)) { | ||
formattedDate = date.toLocaleDateString(undefined, { | ||
day: "numeric", | ||
month: "short", | ||
}); | ||
} else if (["90", "180", "365", "max"].includes(days)) { | ||
formattedDate = date.toLocaleDateString(undefined, { | ||
day: "numeric", | ||
month: "short", | ||
year: "numeric", | ||
}); | ||
} else { | ||
formattedDate = date.toLocaleDateString(); | ||
} | ||
|
||
return formattedDate; | ||
}; | ||
|
||
export default formatDateGraphs; |
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,93 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
|
||
export type TimelineItem = { | ||
id: number; | ||
days: string; | ||
display: string; | ||
active: boolean; | ||
}; | ||
|
||
type TimelineState = { | ||
currentTimeline: TimelineItem; | ||
timeline: TimelineItem[]; | ||
}; | ||
|
||
const initialState: TimelineState = { | ||
currentTimeline: { | ||
id: 1, | ||
days: "1", | ||
display: "1D", | ||
active: true, | ||
}, | ||
timeline: [ | ||
{ | ||
id: 1, | ||
days: "1", | ||
display: "1D", | ||
active: true, | ||
}, | ||
{ id: 2, days: "7", display: "7D", active: false }, | ||
{ | ||
id: 3, | ||
days: "14", | ||
display: "14D", | ||
active: false, | ||
}, | ||
{ | ||
id: 4, | ||
days: "30", | ||
display: "1M", | ||
active: false, | ||
}, | ||
{ | ||
id: 5, | ||
days: "90", | ||
display: "3M", | ||
active: false, | ||
}, | ||
{ | ||
id: 6, | ||
days: "180", | ||
display: "6M", | ||
active: false, | ||
}, | ||
{ | ||
id: 7, | ||
days: "365", | ||
display: "1Y", | ||
active: false, | ||
}, | ||
{ | ||
id: 8, | ||
days: "max", | ||
display: "MAX", | ||
active: false, | ||
}, | ||
], | ||
}; | ||
|
||
export const timelineSlice = createSlice({ | ||
name: "timeline", | ||
initialState, | ||
reducers: { | ||
activeTimeline: (state, action: PayloadAction<number>) => { | ||
const currentActiveIndex = state.timeline.findIndex( | ||
(item) => item.active | ||
); | ||
if (currentActiveIndex !== -1) { | ||
state.timeline[currentActiveIndex].active = false; | ||
} | ||
|
||
const newActiveIndex = state.timeline.findIndex( | ||
(item) => item.id === action.payload | ||
); | ||
if (newActiveIndex !== -1) { | ||
state.timeline[newActiveIndex].active = true; | ||
state.currentTimeline = { ...state.timeline[newActiveIndex] }; | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
export const { activeTimeline } = timelineSlice.actions; | ||
export default timelineSlice.reducer; |
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