Rewrite Scripts
Overview A web app for collaboratively editing scripts. Content is stored in Supabase and edited in a Quill-based rich text editor and is also saved to the users github account.
- Tech: React + Vite + TypeScript, React Quill, Supabase (auth, database), shadcn/ui for components.
Development
- Prerequisites: Node 18+, pnpm/npm
- Install and run
- Install:
npm install - Dev server:
npm run dev - Lint:
npm run lint - Build:
npm run build - Preview:
npm run preview
- Install:
Key Features
- A user connects to the app by visiting https://colaborative-writing.netlify.app/auth
- When the user connects with their GitHub account, they can create a script.
- Non-admins can submit edits as suggestions; admins see inline highlights and can approve or reject the edits.
- Inline review UI: Clickable highlights with a fixed popover for Approve/Reject.
- Versioning and GitHub: Admins can save versions and optionally commit the script to GitHub.
- Drafts: Non-admins can save personal drafts before submitting as suggestions (this is currently not working)
- Profiles and scripts: Basic profile management and a scripts list with create/rename functionality.
Project Structure Overview
components/UI and editor pieces (DeltaTextEditor, toolbar, dialogs, suggestions UI, profile and scripts views).hooks/data fetching and editor/suggestion logic (loader, manager, formatting, submit handlers, script data).services/API calls to Supabase and related composition logic.pages/top-level views (Index, Auth, Profile, ScriptEdit).utils/delta conversions, editor types, and save helpers.
How It Fits Together
- Routing:
App.tsxregisters routes for Auth, Profile, Index, ScriptEdit, etc. - Script editor page:
pages/ScriptEdit.tsxloads script data and pending suggestion counts, then renderscomponents/script/ScriptEditor.tsx. - Editor shell:
ScriptEditorwrapsDeltaTextEditorand the Save Version dialog. - Rich text editor:
components/DeltaTextEditor.tsxwires the Quill editor, toolbar, dialogs, suggestion overlay/controls, and submit handlers. - Supabase integration: All persistence (scripts, suggestions, drafts, versions, profiles) is via
integrations/supabase/client.ts.
Core Flows
- Loading content
hooks/useTextEditor.tsxfetches the current script content (or a user draft for non-admins), normalizes it to a Quill Delta, and provides aquillRefto control the editor.
- Making edits
- Non-admins: Use the editor to change content, then “Suggest Changes”. The app diffs original vs. edited and stores only the Quill delta diff (retain/insert/delete/attributes).
- Admins: Edit directly when there are no pending suggestions; otherwise review suggestions first.
- Suggestion lifecycle
- Load:
hooks/suggestion/useSuggestionLoader.tsfetches pending suggestions and joins usernames. - Render:
hooks/suggestion/useSuggestionManager.tsoverlays suggestion highlights into Quill and handles click/hover interactions. - Review:
components/suggestions/SuggestionPopover.tsxshows details and Approve/Reject actions;InlineSuggestionControlsoffers quick actions. - Persist:
services/suggestionService.tscomposes diffs onto thescriptscontent for approve, marks status, and updates other pending diffs where needed.
- Load:
- Versioning and GitHub
components/editor/SaveVersionDialog.tsxplushooks/script/useGithubIntegration.tscoordinate saving a named version and optional commit.
Data Model (Supabase)
- scripts: Current canonical content for each script (stored as a Quill Delta JSON) plus metadata.
- script_suggestions: Pending/approved/rejected suggestions as Quill delta diffs; includes author and timestamps.
- script_drafts: Per-user draft content for non-admin editing sessions.
- script_versions: Snapshot history of script content.
- profiles: User profile and username lookup for display.
Important Modules
- Editor composition
components/DeltaTextEditor.tsx: orchestrates editor content, toolbar (EditorToolbar), dialogs (EditorDialogs), and suggestion review.components/editor/EditorContent.tsx: the React Quill instance and supported formats (including suggestion marks).hooks/editor/useEditorFormat.ts: formatting state and handlers for bold/italic/align/direction.hooks/editor/useEditorSubmitHandlers.ts: routes actions to save edits, submit suggestions, and save versions.
- Suggestions
hooks/suggestion/useSuggestionLoader.ts: fetches pending suggestions and usernames.hooks/suggestion/useSuggestionManager.ts: overlays suggestions, handles clicks/hover, opens popovers, and calls approve/reject.components/suggestions/SuggestionPopover.tsx: fixed-position Approve/Reject popover.components/suggestions/InlineSuggestionControls.tsx: small inline hover controls (✓/✕).services/suggestionService.ts: server interactions for approve/reject and content composition.
- Listing and navigation
pages/Index.tsxlists scripts;pages/Profile.tsxmanages profile;pages/Auth.tsxhandles auth;pages/ScriptEdit.tsxis the main editor page.
How Suggestions Are Stored
- Each suggestion is a Quill Delta diff, not a full copy. Typical operations:
- retain: move the index forward without changing content (optionally includes attribute changes).
- insert: proposed new text.
- delete: proposed removal length.
- Block-level attributes (align/direction) are highlighted across full lines so admins can review and act on them.
Admin vs Contributor UX
- Contributor
- Create or open a script, edit in the Quill editor, and click “Suggest Changes”.
- Optionally save a draft without submitting.
- Admin
- If pending suggestions exist, the editor shows highlights with Approve/Reject controls.
- Approving composes the diff into
scripts.contentand records a version. Rejecting marks it rejected. - With no pending suggestions, the admin can edit and save changes directly or save a named version; GitHub commit is available if configured.