refactor: simplify toast reducer flow - #78
Merged
Conversation
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.
Simplification
Consolidate frontend toast creation in
pi-web/src/web/state.tsso both explicitshow_toastactions and failed server responses use the sametoast()helper.Why the current design is overcomplicated
The reducer had two implementations of the same responsibility:
show_toastincrementedtoastSeqinline and constructed theToastobject directly.toast()helper, which also incrementedtoastSeqand constructed the sameToastshape.That duplicate state-update path made toast sequencing and object construction slightly harder to audit than necessary. There is no behavior distinction between the two paths that justifies maintaining two implementations.
Behavioral contract
Behavior that must remain unchanged:
show_toastcreates a toast with a fresh numeric id, the requested text, and the requested kind.toastSeqcounter.dismiss_toaststill clears only the currently visible toast when the id matches.Before and after
Before:
show_toastduplicated the helper's logic by incrementingtoastSeqand constructing{ id, text, kind }inline.toast(state, msg.error, "error").After:
show_toastcallstoast(state, action.text, action.kind).Specific evidence:
pi-web/src/web/state.ts.pi-web/tests/state.test.tsto pin the shared toast behavior.Validation
Commands intended for this change:
cd pi-web && npm run buildcd pi-web && npm run typecheckcd pi-web && npm testI could not run local commands in this automation environment because repository cloning/execution was unavailable. Static validation performed instead:
pi-web/src/web/state.tsand confirmedshow_toastnow delegates to the existingtoast()helper without changing action inputs or resulting state shape.pi-web/tests/state.test.tscovering explicit toast creation, matching-id dismissal, and failed-response toast creation.pi-web/package.jsonrunsnode --test 'tests/*.test.ts', so the new test file is included by the existing test command.Risk assessment
Behavior-sensitive areas examined:
toastSeqincrement in the same helper already used by failed responses.{ id, text, kind }.The change is safe because it removes duplicated implementation while preserving the single existing helper's behavior.
Scope
Intentionally not simplified:
subagentscode, because existing open simplification PRs already touch that area.