Introduce a composer reducer and move image state there #5547
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.
Stacked on #5535.
This continues taking apart / adapting #4163.
Currently, all composer-related state lives in assorted state variables inside the
Composer
component. We're going to need to change this since we need to support composing multiple posts in a thread. So we're going to need to lift state up.As a first step towards that future, I am adding a reducer for composer state. Reducers are much easier to lift up because we'll be able to index individual posts state by the ID/index of that post. For now, this reducer only manages the
images
state. But similarly to #4163, I intend to move most composer state there, stacking individual behaviors on top of this PR.This PR implements enough logic in the reducer that we can delete the
images
state variable completely. However, I haven't changed any surrounding logic to keep the diff small. So theimages
is still being re-derived directly in the component. I will be changing that later.Note that I've also chosen to diverge from the data model in #4163. In #4163, the shape of the composer state tries to mimic the record shape. There are some benefits to that but I find it too clunky (and it's not truly the record shape anyway). Instead, I'm choosing a simpler data structure (an optional record + an optional media embed) which represents the same constraints ("can't have two record embeds") but is easier to update. (This PR does not use the
record
field yet.)Test Plan