From 88b7797679c4f7d3da098d06602442d67bce2a95 Mon Sep 17 00:00:00 2001 From: igormuba Date: Fri, 25 Nov 2022 14:46:06 -0300 Subject: [PATCH 1/5] graphql query for communities --- src/renderer/App.tsx | 5 +-- src/renderer/components/hooks/Feeds.ts | 53 +++++++++++++++++++++++++- src/renderer/views/CommunityView.tsx | 12 +++++- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 18ae88a..752f88b 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -24,13 +24,12 @@ import { TopNavbar } from './components/TopNavbar' import { SideNavbar } from './components/SideNavbar' import { StartUp } from './StartUp' import { CreatorStudioView } from './views/CreatorStudioView' -import {useQuery, gql, ApolloClient, InMemoryCache} from '@apollo/client'; - +import { useQuery, gql, ApolloClient, InMemoryCache } from '@apollo/client' export const IndexerClient = new ApolloClient({ uri: 'http://localhost:4568/v1/graphql', cache: new InMemoryCache(), -}); +}) export function App() { return ( diff --git a/src/renderer/components/hooks/Feeds.ts b/src/renderer/components/hooks/Feeds.ts index fbe0491..e29a914 100644 --- a/src/renderer/components/hooks/Feeds.ts +++ b/src/renderer/components/hooks/Feeds.ts @@ -107,6 +107,44 @@ const LASTEST_FEED = gql` } ` +const COMMUNITY_FEED = gql` + query Query($parent_permlink: String) { + latestFeed(parent_permlink: $parent_permlink, limit: 15) { + items { + ... on CeramicPost { + stream_id + version_id + parent_id + title + body + json_metadata + app_metadata + } + ... on HivePost { + created_at + updated_at + parent_author + parent_permlink + permlink + author + title + body + lang + post_type + app + tags + json_metadata + app_metadata + community_ref + + three_video + } + __typename + } + } + } +` + function transformGraphqlToNormal(data) { let blob = [] for (let video of data) { @@ -149,5 +187,18 @@ export function useNewFeed() { const videos = data?.latestFeed?.items || [] return useMemo(() => { - return transformGraphqlToNormal(videos)}, [videos]) + return transformGraphqlToNormal(videos) + }, [videos]) +} + +export function useCommunityFeed(parent_permlink) { + const { data, loading } = useQuery(COMMUNITY_FEED, { + client: IndexerClient, + variables: { parent_permlink }, + }) + const videos = data?.latestFeed?.items || [] + + return useMemo(() => { + return transformGraphqlToNormal(videos) + }, [videos]) } diff --git a/src/renderer/views/CommunityView.tsx b/src/renderer/views/CommunityView.tsx index efd84c3..9ed4c52 100644 --- a/src/renderer/views/CommunityView.tsx +++ b/src/renderer/views/CommunityView.tsx @@ -7,6 +7,7 @@ import ReactMarkdown from 'react-markdown' import RefLink from '../../main/RefLink' import { AccountService } from '../services/account.service' import { GridFeedView } from './GridFeedView' +import { useCommunityFeed } from '../components/hooks/Feeds' const { Client: HiveClient } = require('@hiveio/dhive') const client = new HiveClient('https://api.openhive.network') @@ -21,7 +22,12 @@ export function CommunityView(props: any) { const reflink = useMemo(() => { return RefLink.parse(props.match.params.reflink) }, [props.match]) - + const data = useCommunityFeed(reflink.root) + // for development purpouses: + useEffect(() => { + console.log('data') + console.log(data) + }, [data]) const generate = async () => { const commInfo = await client.call('bridge', 'get_community', { name: reflink.root, @@ -35,6 +41,10 @@ export function CommunityView(props: any) { const newVideosRes = ( await axios.get(`https://3speak.tv/apiv2/feeds/community/${reflink.root}/new`) ).data + console.log('trendingVideosRes') + console.log(trendingVideosRes) + console.log('newVideosRes') + console.log(newVideosRes) setTrendingVideos(trendingVideosRes) setNewVideos(newVideosRes) From 346f876db42b79676415db404905db2c34b107dd Mon Sep 17 00:00:00 2001 From: igormuba Date: Fri, 25 Nov 2022 20:36:42 -0300 Subject: [PATCH 2/5] using graphql for querying new community videos --- src/renderer/components/hooks/Feeds.ts | 55 +++++++++++++++++++++++--- src/renderer/views/CommunityView.tsx | 39 +++++++----------- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/renderer/components/hooks/Feeds.ts b/src/renderer/components/hooks/Feeds.ts index e29a914..5df2ac0 100644 --- a/src/renderer/components/hooks/Feeds.ts +++ b/src/renderer/components/hooks/Feeds.ts @@ -107,7 +107,7 @@ const LASTEST_FEED = gql` } ` -const COMMUNITY_FEED = gql` +const LATEST_COMMUNITY_FEED = gql` query Query($parent_permlink: String) { latestFeed(parent_permlink: $parent_permlink, limit: 15) { items { @@ -116,7 +116,6 @@ const COMMUNITY_FEED = gql` version_id parent_id title - body json_metadata app_metadata } @@ -128,7 +127,42 @@ const COMMUNITY_FEED = gql` permlink author title - body + lang + post_type + app + tags + json_metadata + app_metadata + community_ref + + three_video + } + __typename + } + } + } +` + +const TRENDING_COMMUNITY_FEED = gql` + query Query($parent_permlink: String) { + trendingFeed(parent_permlink: $parent_permlink, limit: 15) { + items { + ... on CeramicPost { + stream_id + version_id + parent_id + title + json_metadata + app_metadata + } + ... on HivePost { + created_at + updated_at + parent_author + parent_permlink + permlink + author + title lang post_type app @@ -191,8 +225,19 @@ export function useNewFeed() { }, [videos]) } -export function useCommunityFeed(parent_permlink) { - const { data, loading } = useQuery(COMMUNITY_FEED, { +export function useLatestCommunityFeed(parent_permlink) { + const { data, loading, error } = useQuery(LATEST_COMMUNITY_FEED, { + client: IndexerClient, + variables: { parent_permlink }, + }) + const videos = data?.latestFeed?.items || [] + + return useMemo(() => { + return transformGraphqlToNormal(videos) + }, [videos]) +} +export function useTrendingCommunityFeed(parent_permlink) { + const { data, loading, error } = useQuery(TRENDING_COMMUNITY_FEED, { client: IndexerClient, variables: { parent_permlink }, }) diff --git a/src/renderer/views/CommunityView.tsx b/src/renderer/views/CommunityView.tsx index 9ed4c52..4dfe305 100644 --- a/src/renderer/views/CommunityView.tsx +++ b/src/renderer/views/CommunityView.tsx @@ -7,47 +7,39 @@ import ReactMarkdown from 'react-markdown' import RefLink from '../../main/RefLink' import { AccountService } from '../services/account.service' import { GridFeedView } from './GridFeedView' -import { useCommunityFeed } from '../components/hooks/Feeds' +import { useLatestCommunityFeed, useTrendingCommunityFeed } from '../components/hooks/Feeds' const { Client: HiveClient } = require('@hiveio/dhive') const client = new HiveClient('https://api.openhive.network') export function CommunityView(props: any) { const [communityInfo, setCommunityInfo] = useState({} as any) - const [newVideos, setNewVideos] = useState([]) - const [trendingVideos, setTrendingVideos] = useState([]) - + // const [newVideos, setNewVideos] = useState([]) + // const [trendingVideos, setTrendingVideos] = useState([]) + const newVideos = useLatestCommunityFeed(reflink.root) + const trendingVideos = useTrendingCommunityFeed(reflink.root) const [backgroundUrl, setBackgroundUrl] = useState(null) const reflink = useMemo(() => { return RefLink.parse(props.match.params.reflink) }, [props.match]) - const data = useCommunityFeed(reflink.root) + // for development purpouses: - useEffect(() => { - console.log('data') - console.log(data) - }, [data]) + const generate = async () => { const commInfo = await client.call('bridge', 'get_community', { name: reflink.root, observer: 'alice', }) setCommunityInfo(commInfo) - - const trendingVideosRes = ( - await axios.get(`https://3speak.tv/apiv2/feeds/community/${reflink.root}/trending`) - ).data - const newVideosRes = ( - await axios.get(`https://3speak.tv/apiv2/feeds/community/${reflink.root}/new`) - ).data - console.log('trendingVideosRes') - console.log(trendingVideosRes) - console.log('newVideosRes') - console.log(newVideosRes) - setTrendingVideos(trendingVideosRes) - setNewVideos(newVideosRes) - + // const trendingVideosRes = ( + // await axios.get(`https://3speak.tv/apiv2/feeds/community/${reflink.root}/trending`) + // ).data + // const newVideosRes = ( + // await axios.get(`https://3speak.tv/apiv2/feeds/community/${reflink.root}/new`) + // ).data + // setTrendingVideos(trendingVideosRes) + // setNewVideos(newVideosRes) const bgUrlRes = await AccountService.getProfileBackgroundImageUrl(props.match.params.reflink) setBackgroundUrl(bgUrlRes) } @@ -55,7 +47,6 @@ export function CommunityView(props: any) { useEffect(() => { void generate() }, [reflink]) - return (
Date: Tue, 28 Mar 2023 16:41:17 +0100 Subject: [PATCH 3/5] fix progress percent --- src/main/core/components/EncoderService.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/core/components/EncoderService.ts b/src/main/core/components/EncoderService.ts index acd93e8..5e62fd9 100644 --- a/src/main/core/components/EncoderService.ts +++ b/src/main/core/components/EncoderService.ts @@ -178,11 +178,17 @@ export class EncoderService { sizes.push(profile.size) ret.size(profile.size) this.logger.info(`Profile size ${profile.size}`) + let totalTime + ret.on('codecData', (data) => { + totalTime = parseInt(data.duration.replace(/:/g, '')) + }) ret.on( 'progress', ((progress) => { - this.events.emit('progress', jobInfo.id, progress) - this.statusInfo[jobInfo.id].progress = progress + const time = parseInt(progress.timemark.replace(/:/g, '')) + const percent = (time / totalTime) * 100 + this.events.emit('progress', jobInfo.id, { ...progress, percent }) + this.statusInfo[jobInfo.id].progress = { ...progress, percent } }).bind(this), ) ret.on('end', () => { From 29d3ec0e320214002295e51148d5958b597906ca Mon Sep 17 00:00:00 2001 From: igormuba Date: Thu, 30 Mar 2023 18:25:28 +0100 Subject: [PATCH 4/5] fix time remaining using rule of 3 --- src/renderer/views/UploaderView.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/renderer/views/UploaderView.tsx b/src/renderer/views/UploaderView.tsx index 8dc71eb..e2d4dd9 100644 --- a/src/renderer/views/UploaderView.tsx +++ b/src/renderer/views/UploaderView.tsx @@ -206,7 +206,8 @@ export function UploaderView() { return } setEncodingInProgress(true) - setStartTime(new Date().getTime()) + const _startingTime = new Date().getTime() + setStartTime(_startingTime) setEndTime(null) const jobInfo = (await PromiseIpc.send('encoder.createJob', { @@ -240,6 +241,7 @@ export function UploaderView() { let savePct = 0 const progressTrack = async () => { + const _timeNow = new Date().getTime() const status = (await PromiseIpc.send('encoder.status', jobInfo.id)) as any console.log(`Encoder status: `, status) @@ -247,14 +249,14 @@ export function UploaderView() { setProgress(status.progress || {}) setStatusInfo(status) - const val = caluclatePercentage() - const diffPct = val - savePct - savePct = val - const pctPerSec = diffPct / 3 - const totalTimeRemaining = (100 - val) / pctPerSec - - setEstimatedTimeRemaining(secondsAsString(totalTimeRemaining)) - setEndTime(new Date().getTime()) + const val = status.progress.percent + // const diffPct = val - savePct + // savePct = val + // const pctPerSec = diffPct / 3 + // const totalTimeRemaining = (100 - val) / pctPerSec + const totalTimeRemaining = (100 * (_timeNow - _startingTime)) / val + setEstimatedTimeRemaining(millisecondsAsString(totalTimeRemaining)) + setEndTime(_timeNow) } const pid = setInterval(progressTrack, 3000) From 3ec86628c8db444bb7bbffaca8c93b8809836714 Mon Sep 17 00:00:00 2001 From: igormuba Date: Tue, 4 Apr 2023 16:41:52 +0100 Subject: [PATCH 5/5] drag drop video file --- src/renderer/views/UploaderView.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/renderer/views/UploaderView.tsx b/src/renderer/views/UploaderView.tsx index e2d4dd9..1b4f758 100644 --- a/src/renderer/views/UploaderView.tsx +++ b/src/renderer/views/UploaderView.tsx @@ -164,9 +164,16 @@ export function UploaderView() { } const handleVideoSelect = async (e) => { - const file = e.target.files[0] - setVideoSourceFile(file.path) - setLogData([...logData, `Selected: ${videoInfo.path}`]) + let file + if (e.target && e.target.files) { + file = e.target.files[0] + } else if (e.dataTransfer && e.dataTransfer.files) { + file = e.dataTransfer.files[0] + } + if (file) { + setVideoSourceFile(file.path) + setLogData([...logData, `Selected: ${videoInfo.path}`]) + } } const handleThumbnailSelect = async (e) => { @@ -307,6 +314,8 @@ export function UploaderView() { fontWeight: 'bold', cursor: 'pointer', }} + onDragOver={(e) => e.preventDefault()} + onDrop={handleVideoSelect} > Drop a file or click to start the upload