Refactor: Extract bookmark and relay logic into custom hooks#38
Merged
pheuberger merged 6 commits intomainfrom Feb 6, 2026
Merged
Refactor: Extract bookmark and relay logic into custom hooks#38pheuberger merged 6 commits intomainfrom
pheuberger merged 6 commits intomainfrom
Conversation
…from useNostrSync Splits the 977-line useNostrSync.js into focused modules: - src/services/nostr-sync-debug.js: syncDebug singleton and window exposure - src/utils/bookmark-transform.js: bookmarkDataToYMap/ymapToBookmarkData - src/services/nostr-inbound-handlers.js: handleInboundBookmark/handleInboundDeletion The hook drops from 977 to 599 lines. All 879 tests pass unchanged. https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
…markList Splits BookmarkList.jsx (686 lines) into focused custom hooks: - useBookmarkFilters: filter view, sort, search, tag selection - useBookmarkSelection: multi-select, shift-select, bulk operations - useBookmarkKeyboardNav: j/k nav, hover, scroll-into-view BookmarkList drops from 686 to 487 lines (15 useState -> 6 + 3 hook calls). All 879 tests pass unchanged. https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
Introduces _result() and _runServiceCheck() template methods to eliminate repeated service-not-initialized guards and result object construction across 5 diagnostic check methods. Each method drops from 30-50 lines to 5-15 lines while preserving identical behavior. All 879 tests pass (including 30 diagnostics tests). https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
Introduces runValidationPipeline() to replace sequential if-return chains in validateNostrEvent(), and requireTag() to deduplicate tag-finding logic in validateBookmarkEvent() and validateDeleteEvent(). All 879 tests pass unchanged. https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
…ayConfigurationView Splits the 681-line RelayConfigurationView.jsx into focused modules: - src/utils/relay-utils.js: validateRelayUrl, testRelayConnection, storage helpers - src/components/ui/RelayItem.jsx: single relay display component - src/components/ui/AddRelayDialog.jsx: add-relay form dialog RelayConfigurationView drops from 681 to 297 lines. All 879 tests pass. https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
✅ Deploy Preview for hypermarkk ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Split nostr-sync.js (1,959 → 1,234 lines) into focused modules: - nostr-validation.js (517 lines): Event validation, VALIDATION_ERRORS, NOSTR_KINDS, validateEventStructure/Timestamp/Tags/ContentSize, validateBookmarkEvent, validateDeleteEvent, validateNostrEvent, extract* helpers - nostr-yjs-state.js (274 lines): Yjs state vector encode/decode/compare, extractYjsStateVector, compareStateVectors, hasRemoteChanges, encodeYjsState, applyYjsUpdate, getYjsDiff, etc. Re-exports from nostr-sync.js ensure zero import breakage. All 879 tests pass. https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the BookmarkList component and RelayConfigurationView by extracting complex state management and UI logic into reusable custom hooks and separate components. This improves code organization, testability, and maintainability.
Key Changes
BookmarkList Refactoring
Extracted
useBookmarkFiltershook: Manages filtering, sorting, and search state for bookmarksExtracted
useBookmarkKeyboardNavhook: Manages keyboard navigation stateExtracted
useBookmarkSelectionhook: Manages multi-select functionalityUpdated navigation callbacks: Wrapped filter navigation functions to also set currentView, reducing duplication
RelayConfigurationView Refactoring
Extracted
RelayItemcomponent: Displays individual relay status and actionsExtracted
AddRelayDialogcomponent: Modal for adding custom relaysExtracted relay utilities (
src/utils/relay-utils.js):validateRelayUrl(): URL validation with protocol checkingtestRelayConnection(): WebSocket connection testing with timeoutloadCustomRelays()/saveCustomRelays(): localStorage persistenceloadSyncEnabled()/saveSyncEnabled(): Sync preference persistenceImplementation Details
https://claude.ai/code/session_01JbRof8b6AKgKxUQdx3FFkX