refactor: replace mocked time with injected clock prop and implement conversion logic

This commit is contained in:
Loic Coenen
2026-06-24 16:54:57 +02:00
committed by Loic Coenen (aider)
parent 88ce663b44
commit 2c84312947
7 changed files with 117 additions and 112 deletions

View File

@@ -1,15 +1,14 @@
import { useState } from 'react';
import { BerlinClock } from './BerlinClock';
import { DigitalClock } from './DigitalClock';
import { useCurrentTime } from '../hooks/useCurrentTime';
import { useState } from "react";
import { BerlinClock } from "./BerlinClock";
import { DigitalClock } from "./DigitalClock";
import { useCurrentTime } from "../hooks/useCurrentTime";
import { dateToBerlin } from "../utils";
export function TimeConverter() {
const { currentTime, setCurrentTime } = useCurrentTime();
const [useSystemTime, setUseSystemTime] = useState(false);
const handleTimeChange = (newTime: Date) => {
setCurrentTime(newTime);
};
const enabled = !useSystemTime;
const berlinClock = dateToBerlin(currentTime);
return (
<div>
@@ -22,11 +21,11 @@ export function TimeConverter() {
/>
Use system time
</label>
<BerlinClock enabled={!useSystemTime} />
<BerlinClock enabled={enabled} clock={berlinClock} />
<DigitalClock
enabled={!useSystemTime}
enabled={enabled}
currentTime={currentTime}
onTimeChange={handleTimeChange}
onTimeChange={setCurrentTime}
/>
</div>
);