diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-06-13 17:41:18 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-06-13 17:41:27 +0530 |
| commit | 64b59dd227203e968bd95f482fd8ac2830dc3bd1 (patch) | |
| tree | bff7bc4d3ee8a4be51afbe31c292bc6ce3398460 | |
| parent | cc27f9d8d97b9fedd6edfbe9985104f5c3999e07 (diff) | |
| download | pomoru-64b59dd227203e968bd95f482fd8ac2830dc3bd1.tar.xz pomoru-64b59dd227203e968bd95f482fd8ac2830dc3bd1.zip | |
add timer, control buttons and tasks ui compenents
| -rw-r--r-- | desktop/src/components/Controls.tsx | 59 | ||||
| -rw-r--r-- | desktop/src/components/PixelTimer.tsx | 136 | ||||
| -rw-r--r-- | desktop/src/components/TaskItem.tsx | 112 | ||||
| -rw-r--r-- | desktop/src/components/TaskList.tsx | 172 |
4 files changed, 479 insertions, 0 deletions
diff --git a/desktop/src/components/Controls.tsx b/desktop/src/components/Controls.tsx new file mode 100644 index 0000000..8df050d --- /dev/null +++ b/desktop/src/components/Controls.tsx @@ -0,0 +1,59 @@ +import type { TimerState } from "../lib/commands"; + +interface ControlsProps { + timer: TimerState; + onToggle: () => void; + onReset: () => void; + onSkip: () => void; +} + +export default function Controls({ timer, onToggle, onReset, onSkip }: ControlsProps) { + return ( + <div className="controls" id="controls"> + <button + className="control-btn secondary" + onClick={onReset} + aria-label="Reset timer" + title="Reset (R)" + id="btn-reset" + > + <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> + <path d="M3 3v5h5" /> + </svg> + </button> + + <button + className={`control-btn primary ${timer.mode} ${timer.is_running ? "running" : ""}`} + onClick={onToggle} + aria-label={timer.is_running ? "Pause" : "Start"} + title="Space" + id="btn-toggle" + > + {timer.is_running ? ( + <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"> + <rect x="6" y="4" width="4" height="16" rx="1" /> + <rect x="14" y="4" width="4" height="16" rx="1" /> + </svg> + ) : ( + <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"> + <polygon points="6,3 20,12 6,21" /> + </svg> + )} + </button> + + <button + className="control-btn secondary" + onClick={onSkip} + aria-label="Skip session" + title="Skip (S)" + id="btn-skip" + > + <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <polygon points="5,4 15,12 5,20" /> + <line x1="19" y1="5" x2="19" y2="19" /> + </svg> + </button> + </div> + ); +} diff --git a/desktop/src/components/PixelTimer.tsx b/desktop/src/components/PixelTimer.tsx new file mode 100644 index 0000000..b3310d1 --- /dev/null +++ b/desktop/src/components/PixelTimer.tsx @@ -0,0 +1,136 @@ +import { useState, useRef, useEffect } from "react"; +import type { TimerState } from "../lib/commands"; + +interface PixelTimerProps { + timer: TimerState; + onSetDuration: (mins: number) => void; +} + +const ASCII_MAP: Record<string, string[]> = { + "0": [" ██████ ", "██ ██", "██ ██", "██ ██", " ██████ "], + "1": [" ██ ", " ███ ", " ██ ", " ██ ", " ██████ "], + "2": [" ██████ ", "██ ██", " ███ ", " ███ ", "████████"], + "3": [" ██████ ", " ██", " █████ ", " ██", " ██████ "], + "4": ["██ ██", "██ ██", "████████", " ██", " ██"], + "5": ["████████", "██ ", "███████ ", " ██", "███████ "], + "6": [" ██████ ", "██ ", "███████ ", "██ ██", " ██████ "], + "7": ["████████", " ██", " ██ ", " ██ ", " ██ "], + "8": [" ██████ ", "██ ██", " ██████ ", "██ ██", " ██████ "], + "9": [" ██████ ", "██ ██", " ███████", " ██", " ██████ "], + ":": [" ", " █ ", " ", " █ ", " "], +}; + +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 formatTimeStr(secs: number): string { + const m = Math.floor(secs / 60); + const s = secs % 60; + return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`; +} + +export default function PixelTimer({ timer, onSetDuration }: PixelTimerProps) { + const [isEditing, setIsEditing] = useState(false); + const [editValue, setEditValue] = useState(""); + const inputRef = useRef<HTMLInputElement>(null); + + useEffect(() => { + if (isEditing && inputRef.current) { + inputRef.current.focus(); + } + }, [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))); + setIsEditing(true); + } + + function handleSubmit() { + const mins = parseInt(editValue, 10); + if (!isNaN(mins) && mins >= 0) { + onSetDuration(mins); + } + setIsEditing(false); + } + + function handleKeyDown(e: React.KeyboardEvent) { + if (e.key === "Enter") { + handleSubmit(); + } else if (e.key === "Escape") { + setIsEditing(false); + } + } + + if (isEditing) { + return ( + <div className="pixel-timer-container editing"> + <input + ref={inputRef} + type="number" + className="timer-edit-input" + value={editValue} + onChange={(e) => setEditValue(e.target.value)} + onBlur={handleSubmit} + onKeyDown={handleKeyDown} + min="0" + max="999" + aria-label="Set minutes" + /> + <span className="timer-edit-label">minutes</span> + </div> + ); + } + + return ( + <div + className="pixel-timer-container" + onClick={handleStartEdit} + title="Click to edit timer" + role="button" + tabIndex={0} + onKeyDown={(e) => { + 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> + </div> + ); +} diff --git a/desktop/src/components/TaskItem.tsx b/desktop/src/components/TaskItem.tsx new file mode 100644 index 0000000..bb4b148 --- /dev/null +++ b/desktop/src/components/TaskItem.tsx @@ -0,0 +1,112 @@ +import { useState, useRef, useEffect } from "react"; +import type { Task } from "../lib/commands"; + +interface TaskItemProps { + task: Task; + index: number; + total: number; + onEdit: (index: number, title: string) => void; + onDelete: (index: number) => void; + onToggle: (index: number) => void; + onReorder: (index: number, direction: "up" | "down") => void; +} + +export default function TaskItem({ + task, + index, + total: _total, + onEdit, + onDelete, + onToggle, + onReorder: _onReorder, +}: TaskItemProps) { + const [isEditing, setIsEditing] = useState(false); + const [editTitle, setEditTitle] = useState(task.title); + const inputRef = useRef<HTMLInputElement>(null); + + useEffect(() => { + if (isEditing && inputRef.current) { + inputRef.current.focus(); + } + }, [isEditing]); + + function handleSubmit() { + if (editTitle.trim() && editTitle !== task.title) { + onEdit(index, editTitle.trim()); + } else { + setEditTitle(task.title); + } + setIsEditing(false); + } + + function handleKeyDown(e: React.KeyboardEvent) { + if (e.key === "Enter") { + handleSubmit(); + } else if (e.key === "Escape") { + setEditTitle(task.title); + setIsEditing(false); + } + } + + return ( + <div className={`task-item ${task.is_done ? "done" : ""}`}> + <button + className="task-checkbox" + onClick={() => onToggle(index)} + aria-label={task.is_done ? "Mark incomplete" : "Mark complete"} + > + {task.is_done ? ( + <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <rect x="3" y="3" width="18" height="18" rx="2" ry="2" /> + <path d="M9 12l2 2 4-4" /> + </svg> + ) : ( + <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <rect x="3" y="3" width="18" height="18" rx="2" ry="2" /> + </svg> + )} + </button> + + {isEditing ? ( + <input + ref={inputRef} + type="text" + className="task-edit-input" + value={editTitle} + onChange={(e) => setEditTitle(e.target.value)} + onBlur={handleSubmit} + onKeyDown={handleKeyDown} + /> + ) : ( + <div className="task-title" onDoubleClick={() => setIsEditing(true)}> + <span className="task-title-text">{task.title}</span> + </div> + )} + + <div className="task-actions"> + <button + className="task-action-btn edit" + onClick={() => setIsEditing(true)} + aria-label="Edit task" + title="Edit" + > + <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <path d="M12 20h9" /> + <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" /> + </svg> + </button> + <button + className="task-action-btn delete" + onClick={() => onDelete(index)} + aria-label="Delete task" + title="Delete" + > + <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> + <polyline points="3 6 5 6 21 6" /> + <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /> + </svg> + </button> + </div> + </div> + ); +} diff --git a/desktop/src/components/TaskList.tsx b/desktop/src/components/TaskList.tsx new file mode 100644 index 0000000..8de41fb --- /dev/null +++ b/desktop/src/components/TaskList.tsx @@ -0,0 +1,172 @@ +import { useState } from "react"; +import type { Task } from "../lib/commands"; +import TaskItem from "./TaskItem"; + +interface TaskListProps { + tasks: Task[]; + onAdd: (title: string) => void; + onEdit: (index: number, title: string) => void; + onDelete: (index: number) => void; + onToggle: (index: number) => void; + onReorder: (index: number, direction: "up" | "down") => void; + onMove: (from: number, to: number) => void; +} + +export default function TaskList({ + tasks, + onAdd, + onEdit, + onDelete, + onToggle, + onReorder, + onMove, +}: TaskListProps) { + const [newTaskTitle, setNewTaskTitle] = useState(""); + const [draggedIndex, setDraggedIndex] = useState<number | null>(null); + const [dragOverIndex, setDragOverIndex] = useState<number | null>(null); + + function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + if (newTaskTitle.trim()) { + onAdd(newTaskTitle.trim()); + setNewTaskTitle(""); + } + } + + function handleDragStart(e: React.DragEvent, index: number) { + setDraggedIndex(index); + if (e.dataTransfer) { + e.dataTransfer.effectAllowed = "move"; + e.dataTransfer.setData("text/plain", index.toString()); + + // Generate a small, clean drag ghost without relying on the browser's + // unpredictable DOM snapshotting on High DPI displays. + const task = tasks[index]; + const ghost = document.createElement("div"); + ghost.textContent = task.title; + ghost.style.position = "absolute"; + ghost.style.top = "-1000px"; + ghost.style.left = "-1000px"; + ghost.style.backgroundColor = "var(--surface)"; + ghost.style.color = "var(--text)"; + ghost.style.padding = "4px 8px"; + ghost.style.borderRadius = "var(--radius-sm)"; + // WebKit scaling fix: Make it 12px natively so it stays small even if scaled 2x + ghost.style.fontSize = "12px"; + ghost.style.fontFamily = "inherit"; + ghost.style.whiteSpace = "nowrap"; + ghost.style.boxShadow = "0 4px 12px rgba(0,0,0,0.5)"; + ghost.style.zIndex = "9999"; + + document.body.appendChild(ghost); + e.dataTransfer.setDragImage(ghost, 10, 10); + + setTimeout(() => { + if (document.body.contains(ghost)) { + document.body.removeChild(ghost); + } + }, 0); + } + } + + function handleDragOver(e: React.DragEvent, index: number) { + e.preventDefault(); + if (e.dataTransfer) { + e.dataTransfer.dropEffect = "move"; + } + if (draggedIndex !== null && draggedIndex !== index) { + setDragOverIndex(index); + } + } + + function handleDrop(e: React.DragEvent, dropIndex: number) { + e.preventDefault(); + if (draggedIndex !== null && draggedIndex !== dropIndex) { + onMove(draggedIndex, dropIndex); + } + setDraggedIndex(null); + setDragOverIndex(null); + } + + function handleDragEnd() { + setDraggedIndex(null); + setDragOverIndex(null); + } + + return ( + <div className="task-list-container"> + <div className="task-list-header"> + <h2 className="task-list-title">Focus Priorities</h2> + <span className="task-count"> + {tasks.filter((t) => !t.is_done).length}/{tasks.length} + </span> + </div> + + <form className="task-input-row" onSubmit={handleSubmit}> + <input + type="text" + className="task-input" + placeholder="Add a new task..." + value={newTaskTitle} + onChange={(e) => setNewTaskTitle(e.target.value)} + /> + <button + type="submit" + className="task-add-btn" + disabled={!newTaskTitle.trim()} + aria-label="Add task" + > + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"> + <line x1="12" y1="5" x2="12" y2="19" /> + <line x1="5" y1="12" x2="19" y2="12" /> + </svg> + </button> + </form> + + <div className="task-items"> + {tasks.map((task, index) => { + let transform = "none"; + if (draggedIndex !== null && dragOverIndex !== null) { + if (draggedIndex < dragOverIndex && index > draggedIndex && index <= dragOverIndex) { + transform = "translateY(-44px)"; + } else if (draggedIndex > dragOverIndex && index >= dragOverIndex && index < draggedIndex) { + transform = "translateY(44px)"; + } + } + + return ( + <div + key={`${task.title}-${index}`} + draggable + onDragStart={(e) => handleDragStart(e, index)} + onDragOver={(e) => handleDragOver(e, index)} + onDrop={(e) => handleDrop(e, index)} + onDragEnd={handleDragEnd} + className={`task-drag-wrapper ${draggedIndex === index ? "dragging" : ""}`} + style={{ + transform, + transition: draggedIndex !== null ? "transform 0.2s cubic-bezier(0.2, 0, 0, 1)" : "none", + }} + > + <TaskItem + task={task} + index={index} + total={tasks.length} + onEdit={onEdit} + onDelete={onDelete} + onToggle={onToggle} + onReorder={onReorder} + /> + </div> + ); + })} + {tasks.length === 0 && ( + <div className="task-empty"> + <p>No tasks yet</p> + <span className="task-empty-hint">Time to focus!</span> + </div> + )} + </div> + </div> + ); +} |