refactor: replace mocked time with injected clock prop and implement conversion logic
This commit is contained in:
committed by
Loic Coenen (aider)
parent
88ce663b44
commit
2c84312947
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user