Skip to content

Commit

Permalink
visually show downloaded pin
Browse files Browse the repository at this point in the history
  • Loading branch information
igormuba committed Aug 9, 2023
1 parent 9ef863c commit c68aa90
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions src/renderer/views/WatchView/WatchViewContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect, useState } from 'react'
import { Container, Col, Row } from 'react-bootstrap'
import { FollowWidget } from '../../components/widgets/FollowWidget'
import { FaDownload } from 'react-icons/fa'
Expand All @@ -12,7 +12,10 @@ import { LoopCircleLoading } from 'react-loadingg'
import DateTime from 'date-and-time'
import DOMPurify from 'dompurify'
import rehypeRaw from 'rehype-raw'
import { usePinningUtils } from '../PinsView/pinningUtils'
export const WatchViewContent = (props: any) => {
const [currentViewIsPinned, setCurrentViewIsPinned] = useState(false)

const {
loaded,
videoInfo,
Expand Down Expand Up @@ -49,6 +52,20 @@ export const WatchViewContent = (props: any) => {
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
}

const { pinList } = usePinningUtils()

useEffect(() => {
checkPins()
}, [pinList, rootCid])
const checkPins = () => {
let pins = pinList.flatMap((obj) => obj.cids)

if (pins.includes(rootCid)) {
setCurrentViewIsPinned(true)
} else {
setCurrentViewIsPinned(false)
}
}
return (
<div>
{loaded ? (
Expand Down Expand Up @@ -99,14 +116,29 @@ export const WatchViewContent = (props: any) => {
<Row>
<FollowWidget reflink={reflink} />
<div style={{ textAlign: 'center' }}>
<a
target="_blank"
style={{ marginRight: '5px', marginLeft: '5px' }}
className="btn btn-light btn-sm"
onClick={PinLocally}
>
<FaDownload /> Download to IPFS node
</a>
{currentViewIsPinned ? (
<button
style={{ marginRight: '5px', marginLeft: '5px' }}
className="btn btn-light btn-sm"
disabled={currentViewIsPinned}
>
{'Downloaded on IPFS'}
</button>
) : (
<a
target="_blank"
style={{ marginRight: '5px', marginLeft: '5px' }}
className="btn btn-light btn-sm"
onClick={async () => {
setCurrentViewIsPinned(true)
await PinLocally()
checkPins()
}}
>
<FaDownload /> Download to IPFS node
</a>
)}

<div>{formatBytes(videoInfo.size)}</div>
</div>
</Row>
Expand Down

0 comments on commit c68aa90

Please sign in to comment.