-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move pomodoro-status file location * Add shadcn input component * Update input source classes * Add pomodoro timer setting * Fixed tailwind class order * WIP: Introduce redux to timer settings * Handle updating values * Add reducer * Handle data in settings modal * Complete implemention of redux * Remove unwanted commented out code
- Loading branch information
Showing
7 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/components/pomodoro-status.tsx → src/components/pomodoro/pomodoro-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { ChangeEvent, useState } from 'react'; | ||
import { Colours } from '@/lib/colours'; | ||
import { ReduxState, useSelector } from '@/lib/redux/store'; | ||
import { Input } from '../ui/input'; | ||
import { Label } from '../ui/label'; | ||
|
||
export interface PomodoroTimerData { | ||
pomodoro: number; | ||
shortBreak: number; | ||
longBreak: number; | ||
} | ||
|
||
interface PomodoroTimerSettingsProps { | ||
onTimerChange: (updatedTimerData: PomodoroTimerData) => void; | ||
} | ||
|
||
export default function PomodoroTimerSettings({ onTimerChange }: PomodoroTimerSettingsProps) { | ||
const { colour, time } = useSelector((state: ReduxState) => state.pomodoroSettings); | ||
const [selectedTime, setSelectedTime] = useState<PomodoroTimerData>(time); | ||
const inputRules = { | ||
min: 5, | ||
max: 60, | ||
step: 5, | ||
}; | ||
|
||
const updateTimeValues = (callback: (prevSelectedTime: PomodoroTimerData) => Partial<PomodoroTimerData>) => { | ||
const updatedProperties = callback(selectedTime); | ||
|
||
setSelectedTime((prevSelectedTime) => ({ | ||
...prevSelectedTime, | ||
...updatedProperties, | ||
})); | ||
|
||
onTimerChange({ ...selectedTime, ...updatedProperties }); | ||
}; | ||
|
||
const handleTimeChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
const { name, value } = event.target; | ||
updateTimeValues(() => ({ [name]: value })); | ||
}; | ||
|
||
function setRingOffsetColor(colour: string) { | ||
switch (colour) { | ||
case Colours.SecondaryAqua: | ||
return 'focus:border-secondary-aqua'; | ||
case Colours.SecondaryPurple: | ||
return 'focus:border-secondary-purple'; | ||
} | ||
return 'focus:border-secondary-peach'; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<Label className="pb-3 text-center text-xs font-bold uppercase tracking-[0.4em] md:self-start"> | ||
Time (Minutes) | ||
</Label> | ||
<div className="flex flex-col items-center gap-2 md:flex-row"> | ||
<div className="flex w-full items-center justify-between md:flex-col md:items-start md:gap-2"> | ||
<Label className="text-xs font-bold text-gray-400">pomodoro</Label> | ||
<Input | ||
name="pomodoro" | ||
className={`font-bold ${setRingOffsetColor(colour)}`} | ||
type="number" | ||
onChange={handleTimeChange} | ||
value={selectedTime.pomodoro} | ||
min={inputRules.min} | ||
max={inputRules.max} | ||
step={inputRules.step} | ||
/> | ||
</div> | ||
<div className="flex w-full items-center justify-between md:flex-col md:items-start md:gap-2"> | ||
<Label className="text-xs font-bold text-gray-400">short break</Label> | ||
<Input | ||
name="shortBreak" | ||
className={`font-bold ${setRingOffsetColor(colour)}`} | ||
type="number" | ||
onChange={handleTimeChange} | ||
value={selectedTime.shortBreak} | ||
min={inputRules.min} | ||
max={inputRules.max} | ||
step={inputRules.step} | ||
/> | ||
</div> | ||
<div className="flex w-full items-center justify-between md:flex-col md:items-start md:gap-2"> | ||
<Label className="text-xs font-bold text-gray-400">long break</Label> | ||
<Input | ||
name="longBreak" | ||
className={`font-bold ${setRingOffsetColor(colour)}`} | ||
type="number" | ||
onChange={handleTimeChange} | ||
value={selectedTime.longBreak} | ||
min={inputRules.min} | ||
max={inputRules.max} | ||
step={inputRules.step} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from "react" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
export interface InputProps | ||
extends React.InputHTMLAttributes<HTMLInputElement> {} | ||
|
||
const Input = React.forwardRef<HTMLInputElement, InputProps>( | ||
({ className, type, ...props }, ref) => { | ||
return ( | ||
<input | ||
type={type} | ||
className={cn( | ||
"flex h-10 w-[140px] rounded-lg border bg-on-light-background px-3 py-2 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:h-12", | ||
className | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
} | ||
) | ||
Input.displayName = "Input" | ||
|
||
export { Input } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters