mirror of
https://github.com/dergigi/boris.git
synced 2026-01-11 02:44:42 +01:00
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:
67
src/utils/bookmarkUtils.tsx
Normal file
67
src/utils/bookmarkUtils.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user