diff --git a/src/renderer/views/PinsView/PinsViewComponent.tsx b/src/renderer/views/PinsView/PinsViewComponent.tsx index 2cd2975..631f068 100644 --- a/src/renderer/views/PinsView/PinsViewComponent.tsx +++ b/src/renderer/views/PinsView/PinsViewComponent.tsx @@ -1,33 +1,32 @@ // Path: src\renderer\views\PinsView\PinsViewComponent.tsx -import React from 'react'; +import React from 'react' import { Button, Col, Dropdown, Row, Table } from 'react-bootstrap' import { CustomPinsViewToggle } from './CustomToggle' import { CustomPinsViewMenu } from './CustomMenu' import DateTime from 'date-and-time' export interface PinsViewProps { - pinRows: React.ReactNode; - showExplorer: boolean; - newVideos: any[]; - trendingVideos: any[]; - actionSelect: (key: string) => Promise; - removePin: (reflink: string) => Promise; - PinLocally: (cids: string[], title: string, _id: string) => Promise; - setShowExplorer: (show: boolean) => void; - updateSearchTables: (community?: string, creator?: string) => Promise; + pinRows: React.ReactNode + showExplorer: boolean + newVideos: any[] + trendingVideos: any[] + actionSelect: (key: string) => Promise + removePin: (reflink: string) => Promise + PinLocally: (cids: string[], title: string, _id: string) => Promise + setShowExplorer: (show: boolean) => void + updateSearchTables: (community?: string, creator?: string) => Promise } -export const PinsViewComponent: React.FC = - ({ - pinRows, - showExplorer, - newVideos, - trendingVideos, - actionSelect, - removePin, - PinLocally, - setShowExplorer, - updateSearchTables, - }) => { +export const PinsViewComponent: React.FC = ({ + pinRows, + showExplorer, + newVideos, + trendingVideos, + actionSelect, + removePin, + PinLocally, + setShowExplorer, + updateSearchTables, +}) => { return (
@@ -41,23 +40,24 @@ export const PinsViewComponent: React.FC = Manual Pin Manual GC + IPFS Folder - - - - - - - - - - - + + + + + + + + + + + {pinRows}
ReflinkTitleCID(s)SourceExpirationPin DateSize/StatusRemove?SPoA
ReflinkTitleCID(s)SourceExpirationPin DateSize/StatusRemove?SPoA
@@ -92,61 +92,61 @@ export const PinsViewComponent: React.FC = - - - - - - + + + + + + - {/* {this.state[`${type}Videos`].map((video) => ( */} - {(type === 'new' ? newVideos : trendingVideos).map((video) => ( - - + - - - - - ))} + + + + + + ))}
{type} videosTitleCreatorpinned
{type} videosTitleCreatorpinned
-
-
- {(() => { - const pattern = DateTime.compile('mm:ss') - return DateTime.format(new Date(video.duration * 1000), pattern) - })()} + {/* {this.state[`${type}Videos`].map((video) => ( */} + {(type === 'new' ? newVideos : trendingVideos).map((video) => ( +
+
+
+ {(() => { + const pattern = DateTime.compile('mm:ss') + return DateTime.format(new Date(video.duration * 1000), pattern) + })()} +
+ + +
- - - - -
{video.title}{video.author} - {video.isPinned ? ( - - ) : ( - - )} -
{video.title}{video.author} + {video.isPinned ? ( + + ) : ( + + )} +
@@ -156,6 +156,5 @@ export const PinsViewComponent: React.FC = )}
- ); -}; - + ) +} diff --git a/src/renderer/views/PinsView/pinningUtils.tsx b/src/renderer/views/PinsView/pinningUtils.tsx index f53f7a6..1949a10 100644 --- a/src/renderer/views/PinsView/pinningUtils.tsx +++ b/src/renderer/views/PinsView/pinningUtils.tsx @@ -1,67 +1,71 @@ -import React, { useEffect, useRef, useState } from 'react'; -import { Button, Form, FormControl } from 'react-bootstrap'; -import { IpfsHandler } from '../../../main/core/components/ipfsHandler'; -import { AccountService } from '../../services/account.service'; -import { FormUtils } from '../../renderer_utils'; -import { NotificationManager } from 'react-notifications'; -import Popup from 'react-popup'; -import CID from 'cids'; -import PromiseIpc from 'electron-promise-ipc'; +import React, { useEffect, useRef, useState } from 'react' +import { Button, Form, FormControl } from 'react-bootstrap' +import { IpfsHandler } from '../../../main/core/components/ipfsHandler' +import { AccountService } from '../../services/account.service' +import { FormUtils } from '../../renderer_utils' +import { NotificationManager } from 'react-notifications' +import Popup from 'react-popup' +import CID from 'cids' +import PromiseIpc from 'electron-promise-ipc' +import Config from '../../../main/core/components/Config' +import { shell } from 'electron' + +const Utils = require('../../../main/core/utils') export const usePinningUtils = () => { - const [newVideos, setNewVideos] = useState([]); - const [trendingVideos, setTrendingVideos] = useState([]); - const [pinList, setPinList] = useState([]); - const pid = useRef(null); + const [newVideos, setNewVideos] = useState([]) + const [trendingVideos, setTrendingVideos] = useState([]) + const [pinList, setPinList] = useState([]) + const pid = useRef(null) const updateSearchTables = async (community = null, creator = null) => { - const ids = pinList.map((x) => x._id); - console.log('ids', ids); - const params = '?limit=10&ipfsOnly=true'; - let newUrl = `https://3speak.tv/apiv2/feeds/new${params}`; - let trendingUrl = `https://3speak.tv/apiv2/feeds/trending${params}`; + const ids = pinList.map((x) => x._id) + console.log('ids', ids) + const params = '?limit=10&ipfsOnly=true' + let newUrl = `https://3speak.tv/apiv2/feeds/new${params}` + let trendingUrl = `https://3speak.tv/apiv2/feeds/trending${params}` if (community) { - newUrl = `https://3speak.tv/apiv2/feeds/community/${community}/new${params}`; - trendingUrl = `https://3speak.tv/apiv2/feeds/community/${community}/trending${params}`; + newUrl = `https://3speak.tv/apiv2/feeds/community/${community}/new${params}` + trendingUrl = `https://3speak.tv/apiv2/feeds/community/${community}/trending${params}` } else if (creator && creator.length > 2) { - newUrl = `https://3speak.tv/apiv2/feeds/@${creator}`; - trendingUrl = null; + newUrl = `https://3speak.tv/apiv2/feeds/@${creator}` + trendingUrl = null } try { - const newResponse = await fetch(newUrl); - const newVideos = await newResponse.json(); + const newResponse = await fetch(newUrl) + const newVideos = await newResponse.json() newVideos.forEach((video) => { - const id = `hive:${video.author}:${video.permlink}`; - video.isPinned = ids.includes(id); - video.id = id; - }); - setNewVideos(newVideos); + const id = `hive:${video.author}:${video.permlink}` + video.isPinned = ids.includes(id) + video.id = id + }) + setNewVideos(newVideos) if (trendingUrl) { - const trendingResponse = await fetch(trendingUrl); - const trendingVideos = await trendingResponse.json(); + const trendingResponse = await fetch(trendingUrl) + const trendingVideos = await trendingResponse.json() trendingVideos.forEach((video) => { - const id = `hive:${video.author}:${video.permlink}`; - video.isPinned = ids.includes(id); - video.id = id; - }); - setTrendingVideos(trendingVideos); + const id = `hive:${video.author}:${video.permlink}` + video.isPinned = ids.includes(id) + video.id = id + }) + setTrendingVideos(trendingVideos) } else { - setTrendingVideos([]); + setTrendingVideos([]) } } catch (error) { - console.error('Error fetching data:', error); + console.error('Error fetching data:', error) } - }; + } const generate = async () => { // type error - 2 arguments expected setPinList(await PromiseIpc.send('pins.ls', undefined as any)) } const PinLocally = async (cids, title, _id) => { if (cids.length !== 0) { - NotificationManager.info('Pinning in progress'); + NotificationManager.info('Pinning in progress') try { await PromiseIpc.send('pins.add', { @@ -72,74 +76,72 @@ export const usePinningUtils = () => { meta: { title, }, - }); + }) NotificationManager.success( `Video with title of ${title} has been successfully pinned! Thank you for contributing!`, 'Pin Successful', - ); + ) } catch (error) { - console.error('Error pinning video:', error); - NotificationManager.error('Error pinning video', 'Pin Failed'); + console.error('Error pinning video:', error) + NotificationManager.error('Error pinning video', 'Pin Failed') } } else { - NotificationManager.warning('This video is not available on IPFS'); + NotificationManager.warning('This video is not available on IPFS') } - await generate(); - }; - const getReflinkFromPopup = () => new Promise(async (resolve) => { - const ref = React.createRef() as any - Popup.create({ - content: ( -
-
- Reflink - -
-
- ), - buttons: { - left: [ - { - text: 'Cancel', - className: 'secondary', - action: () => Popup.close(), - }, - ], - right: [ - { - text: 'Done', - className: 'success', - action: () => { - resolve(FormUtils.formToObj(new FormData(ref.current))); - Popup.close(); - }, + await generate() + } + const getReflinkFromPopup = () => + new Promise(async (resolve) => { + const ref = React.createRef() as any + Popup.create({ + content: ( +
+
+ Reflink + +
+
+ ), + buttons: { + left: [ + { + text: 'Cancel', + className: 'secondary', + action: () => Popup.close(), + }, + ], + right: [ + { + text: 'Done', + className: 'success', + action: () => { + resolve(FormUtils.formToObj(new FormData(ref.current))) + Popup.close() + }, + }, + ], }, - ], - }, - }); - }); + }) + }) const handleCase1 = async () => { - const ret = (await getReflinkFromPopup()) as any; - const video_info = await AccountService.permalinkToVideoInfo(ret.reflink); + const ret = (await getReflinkFromPopup()) as any + const video_info = await AccountService.permalinkToVideoInfo(ret.reflink) const cids = video_info.sources .map((source) => new (require('url').URL)(source.url)) .filter((url) => { try { - new CID(url.host); - return true; + new CID(url.host) + return true } catch (ex) { - console.error(ex); - return false; + console.error(ex) + return false } }) - .map((url) => url.host); + .map((url) => url.host) if (cids.length !== 0) { - NotificationManager.info('Pinning in progress'); + NotificationManager.info('Pinning in progress') await PromiseIpc.send('pins.add', { _id: ret.reflink, source: 'Manual Add', @@ -148,33 +150,44 @@ export const usePinningUtils = () => { meta: { title: video_info.title, }, - } as any); + } as any) NotificationManager.success( `Video with reflink of ${ret.reflink} has been successfully pinned! Thank you for contributing!`, 'Pin Successful', - ); + ) } else { - NotificationManager.warning('This video is not available on IPFS'); + NotificationManager.warning('This video is not available on IPFS') } - }; + } const handleCase2 = async () => { - NotificationManager.info('GC has started'); - const { ipfs } = await IpfsHandler.getIpfs(); - ipfs.repo.gc(); - }; + NotificationManager.info('GC has started') + const { ipfs } = await IpfsHandler.getIpfs() + ipfs.repo.gc() + } + const handleCase3 = async () => { + const config = new Config(Utils.getRepoPath()) + await config.open() + let ipfsPath = config.get('ipfsPath') + console.log('ipfsPath') + console.log(ipfsPath) + shell.openPath(ipfsPath) + } - const actionSelect = async (key) => { + const actionSelect = async (key) => { switch (key) { case '1': - await handleCase1(); - break; + await handleCase1() + break case '2': - await handleCase2(); - break; + await handleCase2() + break + case '3': + await handleCase3() + break default: } - }; - const removePin = async (reflink) => { + } + const removePin = async (reflink) => { try { await PromiseIpc.send('pins.rm', reflink) NotificationManager.success('IPFS pin removal complete') @@ -186,15 +199,15 @@ export const usePinningUtils = () => { } useEffect(() => { - document.title = '3Speak - Tokenised video communities'; - generate(); - pid.current = setInterval(generate, 40000); - updateSearchTables(); + document.title = '3Speak - Tokenised video communities' + generate() + pid.current = setInterval(generate, 40000) + updateSearchTables() return () => { - clearInterval(pid.current); - }; - }, []); + clearInterval(pid.current) + } + }, []) return { newVideos, trendingVideos, @@ -203,6 +216,5 @@ export const usePinningUtils = () => { PinLocally, actionSelect, removePin, - }; -}; - + } +}