feat: add user preferences management and settings UI#3
Conversation
rchandu
commented
May 27, 2025
- Implemented user preferences structure and loading/saving functionality in TimerManager.
- Added settings modal for adjusting timer durations and auto-start options.
- Integrated settings button in the main app interface to open the settings modal.
- Updated styles for the settings modal and buttons for better user experience.
- Enhanced timer functionality to reflect user preferences for work and break durations.
- Added reset to defaults functionality in settings.
- Implemented user preferences structure and loading/saving functionality in TimerManager. - Added settings modal for adjusting timer durations and auto-start options. - Integrated settings button in the main app interface to open the settings modal. - Updated styles for the settings modal and buttons for better user experience. - Enhanced timer functionality to reflect user preferences for work and break durations. - Added reset to defaults functionality in settings.
There was a problem hiding this comment.
Pull Request Overview
This PR adds persistent user preferences management in the backend and a new Settings modal in the UI so users can customize and save timer durations and auto-start options.
- Introduces
UserPreferencesstorage/load/save inTimerManager(Rust). - Adds a
Settingscomponent with a modal UI for editing preferences. - Integrates a settings button in
App.tsxand updates timer buttons to reflect user-configured durations.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Settings.tsx | New Settings React component; load, update, reset, save |
| src/Settings.css | Styles for the Settings modal and its controls |
| src/App.tsx | Added preferences state, settings button, and modal hook |
| src/App.css | Header and settings button styling |
| src-tauri/src/lib.rs | TimerManager extended with preferences load/save API |
| src-tauri/Cargo.toml | Added dirs crate for config directory resolution |
| eslint.config.js | Added globals configuration for ESLint |
| package.json | Added globals dependency |
Comments suppressed due to low confidence (1)
src-tauri/src/lib.rs:112
- [nitpick] There are no unit tests covering
get_preferencesandupdate_preferences. Consider adding tests for loading, updating, and persistingUserPreferencesto prevent regressions.
pub fn update_preferences(&self, new_preferences: UserPreferences) -> Result<(), String> {
| onMount(() => { | ||
| if (props.isOpen) { | ||
| loadPreferences(); | ||
| } | ||
| }); | ||
|
|
||
| // Load preferences when modal opens | ||
| const handleModalOpen = () => { | ||
| if (props.isOpen) { | ||
| loadPreferences(); | ||
| } | ||
| }; | ||
|
|
||
| // Watch for isOpen changes | ||
| onMount(() => { | ||
| handleModalOpen(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Using onMount twice with a separate handleModalOpen won’t reload preferences each time the modal opens. Replace both onMount blocks with a createEffect that watches props.isOpen to call loadPreferences whenever the modal opens.
| onMount(() => { | |
| if (props.isOpen) { | |
| loadPreferences(); | |
| } | |
| }); | |
| // Load preferences when modal opens | |
| const handleModalOpen = () => { | |
| if (props.isOpen) { | |
| loadPreferences(); | |
| } | |
| }; | |
| // Watch for isOpen changes | |
| onMount(() => { | |
| handleModalOpen(); | |
| }); | |
| // Watch for isOpen changes and load preferences when modal opens | |
| createEffect(() => { | |
| if (props.isOpen) { | |
| loadPreferences(); | |
| } | |
| }); |
|
|
||
| fn get_preferences_path() -> Result<PathBuf, Box<dyn std::error::Error>> { | ||
| let mut path = dirs::config_dir() | ||
| .ok_or("Could not get config directory")?; |
There was a problem hiding this comment.
Using ok_or("…")? with an &str won’t compile because &str doesn’t implement std::error::Error. Consider returning a concrete error (e.g., io::Error) or converting to a boxed error type.
| .ok_or("Could not get config directory")?; | |
| .ok_or_else(|| "Could not get config directory".into())?; |