chore: refine NIP-88 polls code structure and reactivity #153

Closed
Khushvendra wants to merge 1 commits from Khushvendra/flotilla:chore/nip-88-polls-simplify into dev
Contributor

Summary

This PR addresses the code-style and reactivity overhead issues outlined in #151, bringing the NIP-88 Polls implementation fully in line with Flotilla's "Human-First Simplicity" and Svelte 5 guidelines. It reduces bundle bloat, cleans up component-level state, and removes unnecessary network fetches.

Resolves #151.

Changes Included

  • Simplified Progress Animation: Removed Svelte 4's tweened from svelte/motion and its manual $effect sync wrappers in PollOption.svelte. The progress bar now natively binds to the $derived vote count, leaning on the browser for rendering.
  • Removed Inline Event Handlers: Extracted all inline event handlers across PollCreate.svelte and PollOption.svelte into explicitly named functions in the <script> block, adhering to Flotilla's strictly defined event handler rules.
  • Optimized Array Manipulation: Cleaned up the drag-and-drop feature's verbose array-slicing logic in PollCreate.svelte, removing unused @welshman/lib imports like removeAt and insertAt for much more readable state logic.
  • Removed Component-Level Network Fetches: Removed the imperative network request inside onMount within NoteContentPoll.svelte. It was redundant and caused over-fetching since space sync (sync.ts) handles fetching and listening for PollResponse events naturally via the background logic constraint.

Validation

  • Type checking (pnpm run check) and linter tests all pass cleanly.
  • Dragging/dropping options in PollCreate functions seamlessly after optimizations.
  • Native <progress> correctly scales its max and value on incoming poll votes.
## Summary This PR addresses the code-style and reactivity overhead issues outlined in #151, bringing the NIP-88 Polls implementation fully in line with Flotilla's "Human-First Simplicity" and Svelte 5 guidelines. It reduces bundle bloat, cleans up component-level state, and removes unnecessary network fetches. Resolves #151. ## Changes Included - **Simplified Progress Animation**: Removed Svelte 4's `tweened` from `svelte/motion` and its manual `$effect` sync wrappers in `PollOption.svelte`. The progress bar now natively binds to the `$derived` vote count, leaning on the browser for rendering. - **Removed Inline Event Handlers**: Extracted all inline event handlers across `PollCreate.svelte` and `PollOption.svelte` into explicitly named functions in the `<script>` block, adhering to Flotilla's strictly defined event handler rules. - **Optimized Array Manipulation**: Cleaned up the drag-and-drop feature's verbose array-slicing logic in `PollCreate.svelte`, removing unused `@welshman/lib` imports like `removeAt` and `insertAt` for much more readable state logic. - **Removed Component-Level Network Fetches**: Removed the imperative network `request` inside `onMount` within `NoteContentPoll.svelte`. It was redundant and caused over-fetching since space sync (`sync.ts`) handles fetching and listening for `PollResponse` events naturally via the background logic constraint. ## Validation - Type checking (`pnpm run check`) and linter tests all pass cleanly. - Dragging/dropping options in `PollCreate` functions seamlessly after optimizations. - Native `<progress>` correctly scales its `max` and `value` on incoming poll votes.
Khushvendra added 1 commit 2026-04-04 10:54:48 +00:00
hodlbod reviewed 2026-04-04 14:54:24 +00:00
hodlbod left a comment
Owner

This is not a good PR:

  • Drag and drop no longer works
  • Progress bars no longer animate
  • This adds 34 lines net of mostly bloat and ceremony
This is not a good PR: - Drag and drop no longer works - Progress bars no longer animate - This adds 34 lines net of mostly bloat and ceremony
@@ -17,4 +7,0 @@
relays: [props.url],
filters: [{kinds: [PollResponse], "#e": [props.event.id]}],
})
})
Owner

We actually do need this, sync is only a best-effort thing to speed up page transitions.

We actually do need this, sync is only a best-effort thing to speed up page transitions.
@@ -68,0 +68,4 @@
const sourceOption = reordered[sourceIndex]
reordered[sourceIndex] = reordered[targetIndex]
reordered[targetIndex] = sourceOption
options = reordered
Owner

I think insertAt/removeAt is actually much cleaner

I think insertAt/removeAt is actually much cleaner
hodlbod closed this pull request 2026-04-04 14:54:27 +00:00

Pull request closed

Sign in to join this conversation.