fix: button state reset on switching models #4356
Merged
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.
Describe Your Changes
This PR resolved the issue where switching to a new button would cause the stop button to disappear.
Changes made
This pull request includes several changes to improve state management and streamline the codebase in the
web
directory. The changes focus on the use of Jotai atoms for state management, the addition of new utility atoms, and the removal of redundant code.State Management Improvements:
web/containers/Providers/ModelHandler.tsx
: Replaced the use ofuseAtom
withuseAtomValue
forsubscribedGeneratingMessageAtom
to simplify state retrieval.web/helpers/atoms/Thread.atom.ts
: AddedisWaitingForResponseAtom
andisBlockingSendAtom
to manage thread states and reduce unnecessary re-renders.Utility Atom Additions:
web/helpers/atoms/Thread.atom.ts
: IntroducedresetThreadWaitingForResponseAtom
andresetGeneratingResponseAtom
to reset thread states and generating states.Code Simplification:
web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx
: Replaced multiple state checks withisBlockingSendAtom
to streamline the logic for blocking send operations. [1] [2] [3]web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
: Removed redundant state checks and replaced them withisBlockingSendAtom
for cleaner code. [1] [2] [3]Test Updates:
web/hooks/useCreateNewThread.test.ts
: Removed unnecessary assertions formockSetAtom
calls to focus on essential test validations. [1] [2] [3]