diff --git a/explorer-nextjs/src/components/progressBar/ProgressBar.tsx b/explorer-nextjs/src/components/progressBar/ProgressBar.tsx index 3428017725..3f64129d7e 100644 --- a/explorer-nextjs/src/components/progressBar/ProgressBar.tsx +++ b/explorer-nextjs/src/components/progressBar/ProgressBar.tsx @@ -11,7 +11,7 @@ const ProgressBar = ({ ); diff --git a/explorer-nextjs/src/components/progressBars/DynamicProgressBar.tsx b/explorer-nextjs/src/components/progressBars/DynamicProgressBar.tsx deleted file mode 100644 index f71d023a85..0000000000 --- a/explorer-nextjs/src/components/progressBars/DynamicProgressBar.tsx +++ /dev/null @@ -1,109 +0,0 @@ -"use client"; - -import { Typography } from "@mui/material"; -import Box from "@mui/material/Box"; -import LinearProgress from "@mui/material/LinearProgress"; -import * as React from "react"; - -export interface IDynamicProgressBarProps { - overTitle?: string; - start: string; // Start timestamp as ISO 8601 string - showEpoch: boolean; -} - -export const DynamicProgressBar = (props: IDynamicProgressBarProps) => { - const { start, showEpoch, overTitle } = props; - const [progress, setProgress] = React.useState(0); - - React.useEffect(() => { - // Parse the start timestamp - const startTime = new Date(start).getTime(); - const endTime = startTime + 60 * 60 * 1000; // Add 1 hour to the start time - - // Validate start timestamp - if (Number.isNaN(startTime)) { - console.error("Invalid start timestamp:", { start }); - return; - } - - // Function to calculate progress - const calculateProgress = () => { - const currentTime = Date.now(); - if (currentTime < startTime) { - return 0; - } - if (currentTime >= endTime) { - return 100; - } - const elapsed = currentTime - startTime; - const total = endTime - startTime; - return (elapsed / total) * 100; - }; - - // Set initial progress and start timer - setProgress(calculateProgress()); - const timer = setInterval(() => { - setProgress(calculateProgress()); - }, 60000); // Update every minute (60000 milliseconds) - - // Cleanup on unmount - return () => { - clearInterval(timer); - }; - }, [start]); - - // Helper function to format date - const formatDate = (timestamp: number) => { - const date = new Date(timestamp); - const hours = String(date.getHours()).padStart(2, "0"); - const minutes = String(date.getMinutes()).padStart(2, "0"); - const day = String(date.getDate()).padStart(2, "0"); - const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are 0-based - const year = date.getFullYear(); - return `${hours}:${minutes}, ${day}/${month}/${year}`; - }; - - const startTime = new Date(start).getTime(); - const endTime = startTime + 60 * 60 * 1000; - - return ( - - {overTitle && ( - - {overTitle} - - )} - - - {showEpoch && ( - - - - START: - - - {startTime ? formatDate(startTime) : ""} - - - - - END: - - - {endTime ? formatDate(endTime) : ""} - - - - )} - - ); -}; diff --git a/explorer-nextjs/src/components/progressBars/EpochProgressBar.tsx b/explorer-nextjs/src/components/progressBars/EpochProgressBar.tsx new file mode 100644 index 0000000000..732ba6f936 --- /dev/null +++ b/explorer-nextjs/src/components/progressBars/EpochProgressBar.tsx @@ -0,0 +1,42 @@ +import { Stack } from "@mui/material"; +import Box from "@mui/material/Box"; +import { addHours, differenceInMinutes, format } from "date-fns"; +import * as React from "react"; +import ListItem from "../list/ListItem"; +import ProgressBar from "../progressBar/ProgressBar"; + +export interface IDynamicProgressBarProps { + start: string; // Start timestamp as ISO 8601 string + showEpoch: boolean; +} + +const EpochProgressBar = ({ start, showEpoch }: IDynamicProgressBarProps) => { + const startTime = format(new Date(start), "HH:mm dd-MM-yyyy"); + const endTime = format(addHours(new Date(start), 1), "HH:mm dd-MM-yyyy"); + const totalEpochTime = differenceInMinutes( + new Date(endTime), + new Date(startTime), + ); + + const progress = + (differenceInMinutes(new Date(), startTime) / totalEpochTime) * 100; + + console.log(progress); + + return ( + + + + {showEpoch && ( + + + + + + + )} + + ); +}; + +export default EpochProgressBar;