refactor: extract components and utilities to keep files under 210 lines

- Extract types to src/types/bookmarks.ts
- Extract utility functions to src/utils/bookmarkUtils.tsx
- Extract BookmarkItem component to src/components/BookmarkItem.tsx
- Extract BookmarkList component to src/components/BookmarkList.tsx
- Extract bookmark fetching logic to src/services/bookmarkService.ts
- Reduce main Bookmarks component from 416 to 100 lines
- Maintain all functionality while improving code organization
- Pass all linting and type checking
This commit is contained in:
Gigi
2025-10-02 09:19:44 +02:00
parent 15d155c565
commit 2253172e04
6 changed files with 383 additions and 328 deletions

View File

@@ -0,0 +1,67 @@
import React from 'react'
import { ParsedContent, ParsedNode } from '../types/bookmarks'
export const formatDate = (timestamp: number) => {
return new Date(timestamp * 1000).toLocaleDateString()
}
// Component to render parsed content using applesauce-content
export const renderParsedContent = (parsedContent: ParsedContent) => {
if (!parsedContent || !parsedContent.children) {
return null
}
const renderNode = (node: ParsedNode, index: number): React.ReactNode => {
if (node.type === 'text') {
return <span key={index}>{node.value}</span>
}
if (node.type === 'mention') {
return (
<a
key={index}
href={`nostr:${node.encoded}`}
className="nostr-mention"
target="_blank"
rel="noopener noreferrer"
>
{node.encoded}
</a>
)
}
if (node.type === 'link') {
return (
<a
key={index}
href={node.url}
className="nostr-link"
target="_blank"
rel="noopener noreferrer"
>
{node.url}
</a>
)
}
if (node.children) {
return (
<span key={index}>
{node.children.map((child: ParsedNode, childIndex: number) =>
renderNode(child, childIndex)
)}
</span>
)
}
return null
}
return (
<div className="parsed-content">
{parsedContent.children.map((node: ParsedNode, index: number) =>
renderNode(node, index)
)}
</div>
)
}