mirror of
https://github.com/dergigi/boris.git
synced 2025-12-26 02:54:29 +01:00
fix(ui): show filename for videos instead of 'Error Loading Content'
- Add getFilenameFromUrl helper to extract filename from URL - Use filename as title when content loading fails (e.g., for video files) - Decode URI component to handle special characters in filenames - Improves UX for video and media file viewing
This commit is contained in:
@@ -4,6 +4,19 @@ import { fetchReadableContent, ReadableContent } from '../services/readerService
|
||||
import { fetchHighlightsForUrl } from '../services/highlightService'
|
||||
import { Highlight } from '../types/highlights'
|
||||
|
||||
// Helper to extract filename from URL
|
||||
function getFilenameFromUrl(url: string): string {
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
const pathname = urlObj.pathname
|
||||
const filename = pathname.substring(pathname.lastIndexOf('/') + 1)
|
||||
// Decode URI component to handle special characters
|
||||
return decodeURIComponent(filename) || url
|
||||
} catch {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
interface UseExternalUrlLoaderProps {
|
||||
url: string | undefined
|
||||
relayPool: RelayPool | null
|
||||
@@ -84,8 +97,10 @@ export function useExternalUrlLoader({
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load external URL:', err)
|
||||
// For videos and other media files, use the filename as the title
|
||||
const filename = getFilenameFromUrl(url)
|
||||
setReaderContent({
|
||||
title: 'Error Loading Content',
|
||||
title: filename,
|
||||
html: `<p>Failed to load content: ${err instanceof Error ? err.message : 'Unknown error'}</p>`,
|
||||
url
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user