fix(clock preview): static time

This commit is contained in:
alexsparkes
2024-12-15 22:35:34 +00:00
parent ce9089dcee
commit c51e8fa1d9
4 changed files with 22 additions and 6 deletions

View File

@@ -58,9 +58,9 @@ const ClockContent = () => {
);
};
const Clock = () => {
const Clock = ({ isPreview, staticTime }) => {
return (
<TimeProvider>
<TimeProvider staticTime={staticTime}>
<ClockContent />
</TimeProvider>
);

View File

@@ -3,10 +3,12 @@ import { convertTimezone } from 'utils/date';
const TimeContext = createContext();
export const TimeProvider = ({ children }) => {
const [currentDate, setCurrentDate] = useState(new Date());
export const TimeProvider = ({ children, staticTime }) => {
const [currentDate, setCurrentDate] = useState(staticTime || new Date());
const updateTime = () => {
if (staticTime) return; // Don't update if using static time
let now = new Date();
const timezone = localStorage.getItem('timezone');

View File

@@ -0,0 +1,11 @@
import { useTime } from '../context/TimeContext';
import { usePreviewTime } from '../context/PreviewTimeContext';
export const useClockTime = (isPreview = false) => {
// Always call both hooks to maintain hook order
const previewContext = usePreviewTime();
const liveContext = useTime();
// Return the appropriate context based on isPreview
return isPreview ? previewContext : liveContext;
};

View File

@@ -1,11 +1,14 @@
import React from 'react';
import { motion } from 'framer-motion';
import Clock from 'features/time/Clock';
const ClockPreview = ({ zoomLevel = 100 }) => {
// Create a static time - 10:10:30
const previewTime = new Date();
previewTime.setHours(10, 10, 30);
return (
<div className="relative w-full h-[300px] bg-gradient-to-br from-neutral-900 to-neutral-800 rounded-lg overflow-hidden grid place-items-center">
<Clock isPreview={true} />
<Clock isPreview={true} staticTime={previewTime} />
</div>
);
};