mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 00:17:02 +02:00
f24db916347907d042d2fda5f9fa9553210a18f7
This commit makes the preview pages production-ready by: 1. Created useNip19Decode hook (src/hooks/useNip19Decode.ts): - Reusable hook for decoding NIP-19 identifiers (npub, note, nevent, naddr, nprofile) - Type-safe with discriminated union for decoded entities - Comprehensive error handling with retry functionality - Loading states and error messages - Well-documented with JSDoc comments and usage examples 2. Comprehensive test coverage (src/hooks/useNip19Decode.test.ts): - 11 tests covering all entity types (npub, note, nevent, naddr) - Tests for error handling (missing identifier, invalid format, corrupted bech32) - Tests for retry functionality and state changes - Uses jsdom environment for React hook testing - All tests passing ✓ 3. Refactored preview pages to use the hook: - PreviewProfilePage: Simplified from 80 to 81 lines with cleaner logic - PreviewEventPage: Improved type safety and error handling - PreviewAddressPage: Better separation of concerns - All pages now have consistent error handling and retry functionality - Better user experience with improved error messages 4. Dependencies added: - @testing-library/react for React hook testing - @testing-library/dom for DOM testing utilities - jsdom and happy-dom for browser environment simulation in tests Benefits: - Code deduplication: Preview pages share decoding logic - Type safety: Discriminated union prevents type errors - Testability: Hook can be tested independently - Maintainability: Single source of truth for NIP-19 decoding - User experience: Consistent error handling and retry across all preview pages - Production-ready: Comprehensive tests and error handling
Languages
TypeScript
98.9%
CSS
0.8%
JavaScript
0.3%