feat(web): save the post you are writing as a draft

Open Beginner friendly
#342 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
87/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active

Research direction

Read apps/web/src/components/Composer.tsx and check how it gets the current user id from apps/web/src/store/auth.ts. Then follow the recent-search storage pattern in SearchPage.tsx and run the composer component tests. Done means drafts restore per user after remounting, clear on posting or discard, and storage errors do not crash the composer.

Written by the indexing model from the issue text.

Description

enhancement good first issue web

Summary

If someone closes the tab or refreshes while writing a post, the text is lost today. Save it locally and restore it.

Why this matters

Losing a long post is frustrating and makes people stop writing. A draft that survives a refresh or a flaky mobile connection is a basic quality of a production app.

Proposed solution

  • Save the composer text to localStorage (debounced, about 500 ms) under a key that includes the user id, for example commune:draft:<userId>.
  • Restore it when the composer mounts, show a small "Draft restored" note with a Discard button, and remove it after a successful post.
  • Do not save empty text, and wrap every storage call in try/catch because storage can be blocked.

Where to start in the code

  • apps/web/src/components/Composer.tsx
  • apps/web/src/store/auth.ts for the current user id
  • Follow the same storage pattern used by recent searches in SearchPage.tsx

Acceptance criteria

  • Refreshing the page keeps the text.
  • Posting clears the draft; discarding clears it too.
  • Another account on the same browser never sees someone else's draft.
  • Nothing breaks when localStorage throws.

Tests

  • Component test: typing, remounting the composer and finding the restored text.
  • Test that a failing localStorage does not crash the composer.

Want to work on this?

Comment on this issue to claim it, then follow First contribution and CONTRIBUTING.md. Keep the pull request to this one feature, use a conventional title (for example feat(web): save the post you are writing as a draft), write Closes #<this issue> in the description, and run npx prettier --write on the files you changed before pushing. Questions are welcome here or on Discord.


Generated by Claude Code

Dominant language
TypeScript
Stars
6
Forks
6
Avg merge
6h 7m
Merged PRs (30d)
167

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Haseeb-MernStack/commune

All issues in Haseeb-MernStack/commune

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.