diff --git a/src/client/components/chart-cards/common/chart/y-axis.tsx b/src/client/components/chart-cards/common/chart/y-axis.tsx
new file mode 100644
index 0000000..fabd8a3
--- /dev/null
+++ b/src/client/components/chart-cards/common/chart/y-axis.tsx
@@ -0,0 +1,15 @@
+import { type FormatOptions, formatValue } from '@/utils/format';
+
+type Props = {
+ formatOptions?: FormatOptions;
+ max: number;
+};
+
+export const YAxis = ({ max, formatOptions }: Props) => (
+
+ {Array.from({ length: 5 }).map((_, index) => (
+ // biome-ignore lint/suspicious/noArrayIndexKey: supress react console error
+
{formatValue((max * (4 - index)) / 4, formatOptions)}
+ ))}
+
+);
diff --git a/src/client/components/chart-cards/static.tsx b/src/client/components/chart-cards/static.tsx
index a7f7875..530952a 100644
--- a/src/client/components/chart-cards/static.tsx
+++ b/src/client/components/chart-cards/static.tsx
@@ -1,6 +1,6 @@
import { useAnimationFrame } from '@/hooks/use-animation-frame';
import { useQuery } from '@tanstack/react-query';
-import { useRef, useState } from 'react';
+import { useState } from 'react';
const formatUptime = (value: number) => {
const seconds = String(Math.floor(value % 60)).padStart(2, '0');
@@ -24,14 +24,8 @@ const formatUptime = (value: number) => {
const Uptime = ({ boot_time }: Pick
) => {
const [uptime, setUptime] = useState(formatUptime(Date.now() / 1000 - boot_time));
- const lastUpdate = useRef(0);
- useAnimationFrame(dt => {
- lastUpdate.current += dt;
- if (lastUpdate.current > 1000) {
- setUptime(formatUptime(Date.now() / 1000 - boot_time));
- }
- });
+ useAnimationFrame(() => setUptime(formatUptime(Date.now() / 1000 - boot_time)), 1);
return (
<>
diff --git a/src/client/hooks/use-animation-frame.ts b/src/client/hooks/use-animation-frame.ts
index 96f2211..97957a6 100644
--- a/src/client/hooks/use-animation-frame.ts
+++ b/src/client/hooks/use-animation-frame.ts
@@ -1,6 +1,7 @@
import { useEffect, useRef } from 'react';
-export const useAnimationFrame = (callback: (dt: number) => void) => {
+export const useAnimationFrame = (callback: (dt: number) => void, fps = 60) => {
+ const ignored = useRef(0);
const requestRef = useRef();
const previousTimeRef = useRef();
@@ -8,7 +9,12 @@ export const useAnimationFrame = (callback: (dt: number) => void) => {
const animate: FrameRequestCallback = time => {
if (previousTimeRef.current !== undefined) {
const deltaTime = time - previousTimeRef.current;
- callback(deltaTime);
+ ignored.current += deltaTime;
+
+ if (ignored.current > 1000 / fps) {
+ ignored.current = 0;
+ callback(deltaTime);
+ }
}
previousTimeRef.current = time;
requestRef.current = requestAnimationFrame(animate);
@@ -20,5 +26,5 @@ export const useAnimationFrame = (callback: (dt: number) => void) => {
cancelAnimationFrame(requestRef.current);
}
};
- }, [callback]);
+ }, [callback, fps]);
};