mirror of
https://github.com/dergigi/boris.git
synced 2025-12-20 16:14:20 +01:00
feat(reader): show video duration for /r/ video URLs using react-player onDuration
This commit is contained in:
@@ -140,6 +140,19 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
const isNostrArticle = selectedUrl && selectedUrl.startsWith('nostr:')
|
const isNostrArticle = selectedUrl && selectedUrl.startsWith('nostr:')
|
||||||
const isExternalVideo = !isNostrArticle && !!selectedUrl && ['youtube', 'video'].includes(classifyUrl(selectedUrl).type)
|
const isExternalVideo = !isNostrArticle && !!selectedUrl && ['youtube', 'video'].includes(classifyUrl(selectedUrl).type)
|
||||||
|
|
||||||
|
// Track external video duration (in seconds) for display in header
|
||||||
|
const [videoDurationSec, setVideoDurationSec] = useState<number | null>(null)
|
||||||
|
|
||||||
|
const formatDuration = (totalSeconds: number): string => {
|
||||||
|
const hours = Math.floor(totalSeconds / 3600)
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||||
|
const seconds = Math.floor(totalSeconds % 60)
|
||||||
|
const mm = hours > 0 ? String(minutes).padStart(2, '0') : String(minutes)
|
||||||
|
const ss = String(seconds).padStart(2, '0')
|
||||||
|
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`
|
||||||
|
}
|
||||||
|
const isExternalVideo = !isNostrArticle && !!selectedUrl && ['youtube', 'video'].includes(classifyUrl(selectedUrl).type)
|
||||||
|
|
||||||
// Get article links for menu
|
// Get article links for menu
|
||||||
const getArticleLinks = () => {
|
const getArticleLinks = () => {
|
||||||
if (!currentArticle) return null
|
if (!currentArticle) return null
|
||||||
@@ -308,7 +321,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
image={image}
|
image={image}
|
||||||
summary={summary}
|
summary={summary}
|
||||||
published={published}
|
published={published}
|
||||||
readingTimeText={readingStats ? readingStats.text : null}
|
readingTimeText={isExternalVideo ? (videoDurationSec !== null ? formatDuration(videoDurationSec) : null) : (readingStats ? readingStats.text : null)}
|
||||||
hasHighlights={hasHighlights}
|
hasHighlights={hasHighlights}
|
||||||
highlightCount={relevantHighlights.length}
|
highlightCount={relevantHighlights.length}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
@@ -318,7 +331,13 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
{isExternalVideo ? (
|
{isExternalVideo ? (
|
||||||
<>
|
<>
|
||||||
<div className="reader-video">
|
<div className="reader-video">
|
||||||
<ReactPlayer url={selectedUrl as string} controls width="100%" height="60vh" />
|
<ReactPlayer
|
||||||
|
url={selectedUrl as string}
|
||||||
|
controls
|
||||||
|
width="100%"
|
||||||
|
height="60vh"
|
||||||
|
onDuration={(d) => setVideoDurationSec(Math.floor(d))}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{activeAccount && (
|
{activeAccount && (
|
||||||
<div className="mark-as-read-container">
|
<div className="mark-as-read-container">
|
||||||
|
|||||||
Reference in New Issue
Block a user