Skip to content

Commit dc1e93d

Browse files
committed
dynamic pomodoro circle radius on FontSizeChange
1 parent 946ce1d commit dc1e93d

2 files changed

Lines changed: 49 additions & 18 deletions

File tree

src/components/PomodoroTimer.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ export const PomodoroTimer = () => {
2323
const playCompletionSound = () => {
2424
try {
2525
// Create a simple success sound using Web Audio API
26-
const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
26+
// Extend the Window type to include webkitAudioContext for older browsers
27+
type WindowWithWebkitAudioContext = Window & {
28+
webkitAudioContext?: typeof AudioContext;
29+
};
30+
31+
const audioContext = new (
32+
window.AudioContext ||
33+
(window as WindowWithWebkitAudioContext).webkitAudioContext
34+
)();
2735
const oscillator = audioContext.createOscillator();
2836
const gainNode = audioContext.createGain();
2937

@@ -46,7 +54,7 @@ export const PomodoroTimer = () => {
4654

4755
const showCelebration = () => {
4856
toast({
49-
title: "🎉 Good Job! You're doing numbers!",
57+
title: "🎉 Good Job! You're doing numbers.",
5058
description: mode === 'work'
5159
? "Time for a well-deserved break!"
5260
: "Ready to get back to work?",
@@ -81,7 +89,8 @@ export const PomodoroTimer = () => {
8189
clearInterval(intervalRef.current);
8290
}
8391
};
84-
}, [isActive, minutes, seconds]);
92+
// eslint-disable-next-line react-hooks/exhaustive-deps
93+
}, [isActive, seconds, minutes, mode]);
8594

8695
const handleModeSwitch = () => {
8796
if (mode === 'work') {
@@ -110,7 +119,7 @@ export const PomodoroTimer = () => {
110119
setSeconds(0);
111120
};
112121

113-
const radius = 60;
122+
const radius: number = 60; // Radius of the circle in pixels
114123
const circumference = 2 * Math.PI * radius;
115124
const strokeDasharray = circumference;
116125
const strokeDashoffset = circumference - (progress / 100) * circumference;
@@ -139,6 +148,7 @@ export const PomodoroTimer = () => {
139148
cx="64"
140149
cy="64"
141150
r={radius}
151+
id="circle"
142152
stroke="rgba(255, 255, 255, 0.1)"
143153
strokeWidth="4"
144154
fill="transparent"

src/components/Settings.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const Settings = ({ isOpen, onClose }: SettingsProps) => {
3232
const [reducedMotion, setReducedMotion] = useState(false);
3333
const [dataCleared, setDataCleared] = useState(false);
3434
const [isImportingData, setIsImportingData] = useState(false);
35+
const [radius, setRadius] = useState<30 | 60 | 90>(60); // Default radius for the settings sheet
3536

3637
useEffect(() => {
3738
const storedTheme = localStorage.getItem("current-theme");
@@ -58,10 +59,10 @@ export const Settings = ({ isOpen, onClose }: SettingsProps) => {
5859

5960

6061
useEffect(() => {
61-
const handleDataCleared = () => setDataCleared(true);
62-
window.addEventListener("data-cleared", handleDataCleared);
63-
return () => window.removeEventListener("data-cleared", handleDataCleared);
64-
}, []);
62+
const handleDataCleared = () => setDataCleared(true);
63+
window.addEventListener("data-cleared", handleDataCleared);
64+
return () => window.removeEventListener("data-cleared", handleDataCleared);
65+
}, []);
6566

6667
const handleImportData = () => {
6768
// Open file browser and look for json files
@@ -117,16 +118,16 @@ export const Settings = ({ isOpen, onClose }: SettingsProps) => {
117118
input.click();
118119
};
119120

120-
const clearData = () => {
121-
indexedDBStorage.clearAllData().then(() => {
122-
setDataCleared(true);
123-
// Optionally, dispatch event if other components need to know
124-
window.dispatchEvent(new Event("data-cleared"));
125-
}).catch((error) => {
126-
console.error("Error clearing data:", error);
127-
alert("Failed to clear data. Please try again.");
128-
});
129-
};
121+
const clearData = () => {
122+
indexedDBStorage.clearAllData().then(() => {
123+
setDataCleared(true);
124+
// Optionally, dispatch event if other components need to know
125+
window.dispatchEvent(new Event("data-cleared"));
126+
}).catch((error) => {
127+
console.error("Error clearing data:", error);
128+
alert("Failed to clear data. Please try again.");
129+
});
130+
};
130131

131132
const handleThemeChange = (newTheme: string) => {
132133
setTheme(newTheme);
@@ -142,6 +143,26 @@ const clearData = () => {
142143
large: '18px'
143144
};
144145
document.documentElement.style.fontSize = sizeMap[newSize as keyof typeof sizeMap];
146+
147+
const radiusMap = {
148+
small: 40,
149+
medium: 60,
150+
large: 65
151+
};
152+
const cxcyMap = {
153+
small: 55,
154+
medium: 72,
155+
large: 73
156+
};
157+
const timerCircle = document.getElementById("circle");
158+
if (timerCircle) {
159+
const r = radiusMap[newSize as keyof typeof radiusMap];
160+
const cxcy = cxcyMap[newSize as keyof typeof cxcyMap];
161+
timerCircle.setAttribute("r", r.toString());
162+
timerCircle.setAttribute("cx", cxcy.toString());
163+
timerCircle.setAttribute("cy", cxcy.toString());
164+
}
165+
145166
};
146167

147168
const toggleHighContrast = () => {

0 commit comments

Comments
 (0)