Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useState, useEffect } from "react";
import React, { useEffect, useState } from "react";
import { getTimeAgoShort } from "@/helpers/Helpers";

interface BrainLeftSidebarWaveDropTimeProps {
Expand All @@ -10,19 +10,21 @@ interface BrainLeftSidebarWaveDropTimeProps {
const BrainLeftSidebarWaveDropTime: React.FC<
BrainLeftSidebarWaveDropTimeProps
> = ({ time }) => {
const [_, setTick] = useState(0);
const [now, setNow] = useState(() => Date.now());

useEffect(() => {
const intervalId = setInterval(() => {
setTick((prev) => prev + 1);
const intervalId = window.setInterval(() => {
setNow(Date.now());
}, 60000); // Update every minute (60000ms)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return () => {
clearInterval(intervalId);
window.clearInterval(intervalId);
};
}, []);

return <span className="tw-text-iron-300">{getTimeAgoShort(time)}</span>;
const label = getTimeAgoShort(time, now);

return <span className="tw-text-iron-300">{label}</span>;
};

export default BrainLeftSidebarWaveDropTime;
8 changes: 5 additions & 3 deletions helpers/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ export const getTimeAgo = (milliseconds: number): string => {
}
};

export const getTimeAgoShort = (milliseconds: number): string => {
const currentTime = new Date().getTime();
const timeDifference = currentTime - milliseconds;
export const getTimeAgoShort = (
milliseconds: number,
referenceTime: number = Date.now()
): string => {
const timeDifference = referenceTime - milliseconds;

const seconds = Math.floor(timeDifference / 1000);
const minutes = Math.floor(seconds / 60);
Expand Down