Repository navigation
Refactor task editor - #29
Merged
Merged
Conversation
Added some test that check some actions that should work after the refactorization.
Avoid using some duplicated code, now everything is managed from the same variable and makes it easier to keep everything synchronized. Updated tests to match the new logic.
- Replace nullable `TaskEditorState` with a sealed interface (`Loading`, `Ready`, `NotFound`, `Error`) to cleanly handle multiple loading and error states. - Add `taskOrNull` extension property for safe access to the task only when in the `Ready` state. - Refactor task loading to use `repository.getTaskById(taskId)` directly instead of querying and filtering the entire list. - Prevent race conditions by cancelling previous load jobs (`loadTaskJob?.cancel()`) when a new task request comes in. - Properly propagate `CancellationException` while converting other repository failures into the `Error` state. - Centralize state updates via `updateReadyTask` to ensure editing actions only execute when the editor state is `Ready`. - Remove non-null assertions (`!!`) and safely handle deletion with `task?.let`. - Introduce `TaskEditorTopBar.actionsEnabled` parameter and disable action buttons while the task is loading. - Implement exhaustive `when` branches in `TaskEditorScreen` to render loading indicators, error views, retry buttons, and the main editor content. - Add localized resource strings for task-not-found, load errors, and retry actions across base, English, and Spanish values. - Update unit tests to mock `getTaskById` and explicitly verify new editor states (`Loading`, `NotFound`, `Error`, `taskOrNull`).
- Update TaskEditorState.Ready to include an autosaveRevision counter, allowing precise tracking of field modifications that require persistence. - Refactor TaskEditorViewModel with granular update methods (title, description, priority, dueDate, subtasks) that increment the autosave revision. - Re-architect TaskEditorSheetContent to use a revision-triggered LaunchedEffect for a cleaner 600ms debounce mechanism, avoiding full draft copy passing. - Refactor a DisposableEffect in the UI to safely flush any pending revisions on disposal. - Ensure robust concurrency control and alarm reconciliation via Mutex and persistedTask snapshots.
The UI doesn't need to know anything about the debounce, now that is separated from the Compose file.
The logic now cancels the debounced autosave and persists any pending changes. If the saving process fails the editor doesn't exit without showing a warning
Now the logic is hardened so if a pending update was waiting the lock after deleting a task doesn't recreate it.
A deletion may occur before flushed gets the lock, that's why I added a check inside, to return in that case and don't try persisting any change if the task was deleted.
The effect is no longer needed, if an emergency autosave is needed is managed by the flushPendingChanges method safely. That method is better because guarantees that the save is made before navigating back if fails shows an error instead of exiting without a warning.
Use the created methods to reconcile alarms.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed a lot of possible bugs connected to the architecture. Mainly the bugs were about possible race conditions or windows that should be ahrdened to avoid any problem.
Improve architecture and maintenance of the code.