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

Aperta Adatta ai principianti
#342 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
87/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, react, typescript

Direzione di ricerca

Leggi apps/web/src/components/Composer.tsx e verifica come ricava l’ID dell’utente attuale da apps/web/src/store/auth.ts. Poi segui il modello di archiviazione delle ricerche recenti in SearchPage.tsx ed esegui i test del componente Composer. Il lavoro è concluso quando le bozze vengono ripristinate per utente dopo il rimontaggio, eliminate quando vengono pubblicate o scartate e gli errori di archiviazione non causano il crash di Composer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
6
Fork
6
Merge medio
6h 7m
PR unite (30g)
167

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Haseeb-MernStack/commune

Tutte le issue di Haseeb-MernStack/commune

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.