aboutsummaryrefslogtreecommitdiff
path: root/desktop/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/src/components')
-rw-r--r--desktop/src/components/Header.tsx6
-rw-r--r--desktop/src/components/PixelTimer.tsx77
2 files changed, 43 insertions, 40 deletions
diff --git a/desktop/src/components/Header.tsx b/desktop/src/components/Header.tsx
index 8d679cf..5ddb1f0 100644
--- a/desktop/src/components/Header.tsx
+++ b/desktop/src/components/Header.tsx
@@ -29,12 +29,12 @@ export default function Header({ timer, activeTaskTitle }: HeaderProps) {
</span>
</div>
<div className="header-time">{formatTime(timer.time_remaining_secs)}</div>
- {activeTaskTitle && (
+ <div className={`header-task-wrapper ${activeTaskTitle ? "visible" : ""}`}>
<div className="header-task">
<span className="task-indicator" />
- {activeTaskTitle}
+ {activeTaskTitle || "No task"}
</div>
- )}
+ </div>
</div>
);
}
diff --git a/desktop/src/components/PixelTimer.tsx b/desktop/src/components/PixelTimer.tsx
index b3310d1..5ad2904 100644
--- a/desktop/src/components/PixelTimer.tsx
+++ b/desktop/src/components/PixelTimer.tsx
@@ -20,19 +20,10 @@ const ASCII_MAP: Record<string, string[]> = {
":": [" ", " █ ", " ", " █ ", " "],
};
-function formatMonolithicAscii(timeStr: string): string {
- const lines = ["", "", "", "", ""];
- for (let i = 0; i < timeStr.length; i++) {
- const char = timeStr[i];
- const art = ASCII_MAP[char] || ASCII_MAP[":"];
- for (let j = 0; j < 5; j++) {
- lines[j] += art[j];
- if (i < timeStr.length - 1) {
- lines[j] += " ";
- }
- }
- }
- return lines.join("\n");
+function formatCharAscii(char: string): string {
+ if (!char) return "";
+ const art = ASCII_MAP[char] || ASCII_MAP[":"];
+ return art.join("\n");
}
function formatTimeStr(secs: number): string {
@@ -41,6 +32,38 @@ function formatTimeStr(secs: number): string {
return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
}
+function AnimatedDigit({ char, mode }: { char: string; mode: string }) {
+ const [current, setCurrent] = useState(char);
+ const [prev, setPrev] = useState("");
+ const [isAnimating, setIsAnimating] = useState(false);
+
+ useEffect(() => {
+ if (char !== current) {
+ setPrev(current);
+ setCurrent(char);
+ setIsAnimating(true);
+ const timeout = setTimeout(() => setIsAnimating(false), 300);
+ return () => clearTimeout(timeout);
+ }
+ }, [char, current]);
+
+ const ascii = formatCharAscii(current);
+ const prevAscii = formatCharAscii(prev);
+
+ return (
+ <div style={{ position: "relative", overflow: "hidden", display: "inline-block" }}>
+ {isAnimating && prev && (
+ <pre key={`${prev}-prev`} className={`ascii-art-timer ${mode} scroll-out`} style={{ position: "absolute", top: 0, left: 0, right: 0 }}>
+ {prevAscii}
+ </pre>
+ )}
+ <pre key={current} className={`ascii-art-timer ${mode} ${isAnimating ? "scroll-in" : ""}`}>
+ {ascii}
+ </pre>
+ </div>
+ );
+}
+
export default function PixelTimer({ timer, onSetDuration }: PixelTimerProps) {
const [isEditing, setIsEditing] = useState(false);
const [editValue, setEditValue] = useState("");
@@ -53,21 +76,6 @@ export default function PixelTimer({ timer, onSetDuration }: PixelTimerProps) {
}, [isEditing]);
const timeStr = formatTimeStr(timer.time_remaining_secs);
- const asciiArt = formatMonolithicAscii(timeStr);
-
- const [currentAscii, setCurrentAscii] = useState(asciiArt);
- const [prevAscii, setPrevAscii] = useState("");
- const [isFading, setIsFading] = useState(false);
-
- useEffect(() => {
- if (asciiArt !== currentAscii) {
- setPrevAscii(currentAscii);
- setCurrentAscii(asciiArt);
- setIsFading(true);
- const timeout = setTimeout(() => setIsFading(false), 300);
- return () => clearTimeout(timeout);
- }
- }, [asciiArt, currentAscii]);
function handleStartEdit() {
setEditValue(String(Math.floor(timer.time_remaining_secs / 60)));
@@ -121,15 +129,10 @@ export default function PixelTimer({ timer, onSetDuration }: PixelTimerProps) {
if (e.key === "Enter" || e.key === " ") handleStartEdit();
}}
>
- <div style={{ position: "relative" }}>
- {isFading && (
- <pre key={`${prevAscii}-prev`} className={`ascii-art-timer ${timer.mode} fade-out`} style={{ position: "absolute", top: 0, left: 0, right: 0 }}>
- {prevAscii}
- </pre>
- )}
- <pre key={currentAscii} className={`ascii-art-timer ${timer.mode} ${isFading ? "fade-in" : ""}`}>
- {currentAscii}
- </pre>
+ <div style={{ display: "flex", gap: "12px", alignItems: "center" }}>
+ {timeStr.split("").map((char, index) => (
+ <AnimatedDigit key={index} char={char} mode={timer.mode} />
+ ))}
</div>
</div>
);