Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a composer reducer and move image state there #5547

Merged
merged 4 commits into from
Oct 1, 2024
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Oct 1, 2024

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 the images 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

  • Verify adding, editing (alt text, crop), removing images works.
  • Verify removing actually does remove the image (on post).
  • Verify removing all images creates a post with no images.
  • Verify the image limit is respected.
  • Verify attaching videos and quotes works like before.
  • Verify sharing image from intent works.

Copy link

github-actions bot commented Oct 1, 2024

Old size New size Diff
7.9 MB 7.9 MB -167 B (-0.00%)

@mary-ext
Copy link
Contributor

mary-ext commented Oct 1, 2024

Agreed on not fully mimicking the actual post records wrt embed and instead having a media and record field always available, it's rather awful otherwise as you'd have to keep unwrapping/wrapping the embeds

Copy link
Member

@estrattonbailey estrattonbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test, code LGTM

Base automatically changed from embed-1 to main October 1, 2024 15:03
@arcalinea arcalinea temporarily deployed to embed-2 - social-app PR #5547 October 1, 2024 15:04 — with Render Destroyed
@gaearon gaearon merged commit d2fd558 into main Oct 1, 2024
6 checks passed
@gaearon gaearon deleted the embed-2 branch October 1, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants