Skip to content

fix(compose): autosave, first-save format and character counter fixes - #205

Open
kwstasna wants to merge 3 commits into
coollabsio:mainfrom
kwstasna:fix/compose-saves-and-counter
Open

kwstasna wants to merge 3 commits into
coollabsio:mainfrom
kwstasna:fix/compose-saves-and-counter

Conversation

@kwstasna

Copy link
Copy Markdown
Contributor

Summary

Three composer fixes, one commit each. The first and third both change createPost in use-autosave.ts, so they're in one PR rather than two that conflict.

  1. Edits made during an autosave could be lost. A change made while a save was in flight could be marked saved without ever reaching the server.
  2. The character counter turned red for problems that weren't about the text. An Instagram Reel without a video showed its caption count in red, as if the caption were too long.
  3. A format picked before a new draft's first save was dropped. The post was created as a feed post while the composer kept showing Reels.

1. Keep edits made while an autosave is running

To reproduce on main: pick an Instagram account, type a caption, then click Reels right away.

  1. The editor's blur flushes the caption and starts a save.
  2. The Reels click lands before that save's request starts.
  3. saveStarted overwrites the click's dirty flag.
  4. The save succeeds and the composer marks everything saved.

The composer keeps showing Reels, the post stays a feed post, and nothing triggers another save. Reloading the draft shows Feed.

There was a second gap: a debounced save that fired while another save was running was skipped, and nothing re-armed the debounce once the running save landed.

  • saveSucceeded carries the snapshot the save sent. The reducer keeps the composer dirty when any persisted field changed since that snapshot (hasEditsSince, over the fields buildPutBody sends), so the next debounce saves the change.
  • A debounced save no longer gives up when another save is running. It queues behind it.

2. Only color the character counter for problems with the text

The counter turned red whenever the active account was blocked for any reason. An Instagram Reel without a video showed its caption count in red, and a Story without media did the same.

The counter now goes red only for problems with the text: an empty post, a section over the limit, or too many sections. Any other block still marks the account's tab, and its reason is still listed where it was.

  • isTextBlockReason in precheck.ts names the text reasons (empty, section_too_long, too_many_sections).
  • severityFor in composer.tsx takes a scope. The counter asks for 'text'; the account tabs keep using every reason.

3. Keep a format picked before the draft's first save

To reproduce on main: pick an Instagram account, choose Reels, then type the caption. The first save creates the post, but createPost sends no per-account choices and StorePostRequest has no rules for them. The post is created as a feed post, the composer marks itself saved, and no later save sends the format. The composer keeps showing Reels until the draft is reloaded.

  • createPost sends targets on the first save, built by buildCreateTargets: each selected account's id and format. It sends the same snapshot the first fix tracks.
  • StorePostRequest validates them with the same format rule as an update (Rule::enum(PostFormat::class)). DraftData::fromArray already read targets; the request just didn't pass them through.

Screenshots

Only the counter fix changes anything visible. An Instagram account with Reels picked, an 83-character caption and no video. The before is upstream main run locally; the after is this branch. Same viewport, data and steps for both.

Before After
Composer on main: Reels selected, no video, the counter shows 83 / 2200 in red Composer on this branch: same draft, the counter shows 83 / 2200 in the normal color
Same draft on main in dark mode, counter in red Same draft on this branch in dark mode, counter in the normal color

The count "83" goes from red to the normal text color in both themes. The Instagram tab is still underlined in red, because the missing video still blocks it.

Testing

  • Autosave: reducer tests for hasEditsSince and saveSucceeded, and hook tests for an edit made during a save and for the queued save. Four of them fail on main.
  • Counter: precheck.test.ts covers which reasons count as text problems.
  • First save:
    • ComposeApiTest: a format sent on POST /posts is stored (on main it comes back as feed), and an unknown format is rejected (on main it is accepted with a 201).
    • buildCreateTargets unit tests, and an autosave test for the first save sending the format (fails on main).
  • oxlint, oxfmt, tsc, vitest (971), Pint, Larastan and Pest (2,133) pass.

A change made while a save was in flight could be marked saved without
ever reaching the server. Picking Reels right after typing a caption did
exactly that: the editor blur flushed the caption, the click landed
before the flush's request started, 'saveStarted' overwrote the click's
dirty flag, and the save's success marked everything saved. The composer
kept showing Reels while the post stayed a feed post.

A finished save now carries the snapshot it sent, and the composer stays
dirty when anything it persists changed since that snapshot. A debounced
save that fires while another is running now queues behind it instead of
being skipped, since nothing re-armed the debounce once the running save
landed.
…text

The counter turned red whenever the active account was blocked, so an
Instagram Reel without a video showed "85 / 2200" in red as if the
caption were too long. Stories without media did the same.

The counter now goes red only for an empty post, a section over the limit
or too many sections. Any other block still marks the account's tab, and
the reason is still listed where it was.
The first save of a new draft sent no per-account choices, and the store
request had no rules for them, so a format picked before the draft
existed was dropped. Picking Reels for an Instagram account and then
typing the caption was enough: the create made a feed post, marked the
composer saved, and no later save sent the format.

The first save now sends each account's format, and the store request
validates it with the same rule as an update.
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.

1 participant