copy url to clipboard, code refactoring

This commit is contained in:
2023-06-23 11:58:11 +02:00
parent 53045be65c
commit 12300d43c5
5 changed files with 46 additions and 28 deletions

View File

@@ -31,6 +31,7 @@ languages:
rpcConnErr: Error while conencting to RPC server rpcConnErr: Error while conencting to RPC server
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
italian: italian:
urlInput: URL di YouTube o di qualsiasi altro servizio supportato urlInput: URL di YouTube o di qualsiasi altro servizio supportato
statusTitle: Stato statusTitle: Stato
@@ -61,6 +62,7 @@ languages:
rpcConnErr: Error nella connessione al server RPC rpcConnErr: Error nella connessione al server RPC
splashText: Nessun download attivo splashText: Nessun download attivo
archiveTitle: Archivio archiveTitle: Archivio
clipboardAction: URL copiato negli appunti
chinese: chinese:
urlInput: YouTube 或其他受支持服务的视频网址 urlInput: YouTube 或其他受支持服务的视频网址
statusTitle: 状态 statusTitle: 状态
@@ -91,6 +93,7 @@ languages:
rpcConnErr: Error while conencting to RPC server rpcConnErr: Error while conencting to RPC server
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
spanish: spanish:
urlInput: URL de YouTube u otro servicio compatible urlInput: URL de YouTube u otro servicio compatible
statusTitle: Estado statusTitle: Estado
@@ -121,6 +124,7 @@ languages:
rpcConnErr: Error al conectarse al servidor RPC rpcConnErr: Error al conectarse al servidor RPC
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
russian: russian:
urlInput: YouTube or other supported service video url urlInput: YouTube or other supported service video url
statusTitle: Status statusTitle: Status
@@ -151,6 +155,7 @@ languages:
rpcConnErr: Error while conencting to RPC server rpcConnErr: Error while conencting to RPC server
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
korean: korean:
urlInput: YouTube나 다른 지원되는 사이트의 URL urlInput: YouTube나 다른 지원되는 사이트의 URL
statusTitle: 상태 statusTitle: 상태
@@ -181,6 +186,7 @@ languages:
rpcConnErr: Error while conencting to RPC server rpcConnErr: Error while conencting to RPC server
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
japanese: japanese:
urlInput: YouTubeまたはサポート済み動画のURL urlInput: YouTubeまたはサポート済み動画のURL
statusTitle: 状態 statusTitle: 状態
@@ -212,6 +218,7 @@ languages:
rpcConnErr: Error while conencting to RPC server rpcConnErr: Error while conencting to RPC server
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard
catalan: catalan:
urlInput: URL de YouTube o d'un altre servei compatible urlInput: URL de YouTube o d'un altre servei compatible
statusTitle: Estat statusTitle: Estat
@@ -242,3 +249,4 @@ languages:
rpcConnErr: Error en connectar-se al servidor RPC rpcConnErr: Error en connectar-se al servidor RPC
splashText: No active downloads splashText: No active downloads
archiveTitle: Archive archiveTitle: Archive
clipboardAction: Copied URL to clipboard

View File

@@ -1,14 +1,19 @@
import { Grid } from "@mui/material" import { Grid, Snackbar } from "@mui/material"
import { Fragment } from "react" import { Fragment, useContext, useEffect, useState } from "react"
import type { RPCResult } from "../types" import type { RPCResult } from "../types"
import { StackableResult } from "./StackableResult" import { StackableResult } from "./StackableResult"
import { I18nContext } from "../providers/i18nProvider"
type Props = { type Props = {
downloads: RPCResult[] downloads: RPCResult[]
abortFunction: (id: string) => void onStop: (id: string) => void
} }
export function DownloadsCardView({ downloads, abortFunction }: Props) { export function DownloadsCardView({ downloads, onStop }: Props) {
const [openSB, setOpenSB] = useState(false)
const { i18n } = useContext(I18nContext)
return ( return (
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}> <Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}>
{ {
@@ -20,7 +25,8 @@ export function DownloadsCardView({ downloads, abortFunction }: Props) {
title={download.info.title} title={download.info.title}
thumbnail={download.info.thumbnail} thumbnail={download.info.thumbnail}
percentage={download.progress.percentage} percentage={download.progress.percentage}
stopCallback={() => abortFunction(download.id)} onStop={() => onStop(download.id)}
onCopy={() => setOpenSB(true)}
resolution={download.info.resolution ?? ''} resolution={download.info.resolution ?? ''}
speed={download.progress.speed} speed={download.progress.speed}
size={download.info.filesize_approx ?? 0} size={download.info.filesize_approx ?? 0}
@@ -29,6 +35,12 @@ export function DownloadsCardView({ downloads, abortFunction }: Props) {
</Grid> </Grid>
)) ))
} }
<Snackbar
open={openSB}
autoHideDuration={1250}
onClose={() => setOpenSB(false)}
message={i18n.t('clipboardAction')}
/>
</Grid> </Grid>
) )
} }

View File

@@ -16,10 +16,10 @@ import type { RPCResult } from "../types"
type Props = { type Props = {
downloads: RPCResult[] downloads: RPCResult[]
abortFunction: Function onStop: (id: string) => void
} }
export function DownloadsListView({ downloads, abortFunction }: Props) { export function DownloadsListView({ downloads, onStop }: Props) {
return ( return (
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}> <Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}>
<Grid item xs={12}> <Grid item xs={12}>
@@ -65,7 +65,7 @@ export function DownloadsListView({ downloads, abortFunction }: Props) {
<Button <Button
variant="contained" variant="contained"
size="small" size="small"
onClick={() => abortFunction(download.id)} onClick={() => onStop(download.id)}
> >
{download.progress.percentage === '-1' ? 'Remove' : 'Stop'} {download.progress.percentage === '-1' ? 'Remove' : 'Stop'}
</Button> </Button>

View File

@@ -16,14 +16,15 @@ import { useEffect, useState } from 'react'
import { ellipsis, formatSpeedMiB, roundMiB } from '../utils' import { ellipsis, formatSpeedMiB, roundMiB } from '../utils'
type Props = { type Props = {
title: string, title: string
url: string, url: string
thumbnail: string, thumbnail: string
resolution: string resolution: string
percentage: string, percentage: string
size: number, size: number
speed: number, speed: number
stopCallback: VoidFunction, onStop: () => void
onCopy: () => void
} }
export function StackableResult({ export function StackableResult({
@@ -34,7 +35,8 @@ export function StackableResult({
percentage, percentage,
speed, speed,
size, size,
stopCallback onStop,
onCopy,
}: Props) { }: Props) {
const [isCompleted, setIsCompleted] = useState(false) const [isCompleted, setIsCompleted] = useState(false)
@@ -57,7 +59,10 @@ export function StackableResult({
return ( return (
<Card> <Card>
<CardActionArea onClick={() => navigator.clipboard.writeText(url)}> <CardActionArea onClick={() => {
navigator.clipboard.writeText(url)
onCopy()
}}>
{thumbnail !== '' ? {thumbnail !== '' ?
<CardMedia <CardMedia
component="img" component="img"
@@ -99,7 +104,7 @@ export function StackableResult({
variant="contained" variant="contained"
size="small" size="small"
color="primary" color="primary"
onClick={stopCallback} onClick={onStop}
> >
{isCompleted ? "Clear" : "Stop"} {isCompleted ? "Clear" : "Stop"}
</Button> </Button>

View File

@@ -9,8 +9,7 @@ import {
Snackbar, Snackbar,
SpeedDial, SpeedDial,
SpeedDialAction, SpeedDialAction,
SpeedDialIcon, SpeedDialIcon
styled
} from '@mui/material' } from '@mui/material'
import { useContext, useEffect, useState } from 'react' import { useContext, useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
@@ -121,12 +120,6 @@ export default function Home() {
client.killAll() client.killAll()
} }
/* -------------------- styled components -------------------- */
const Input = styled('input')({
display: 'none',
})
return ( return (
<Container maxWidth="lg" sx={{ mt: 4, mb: 4 }}> <Container maxWidth="lg" sx={{ mt: 4, mb: 4 }}>
<Backdrop <Backdrop
@@ -140,8 +133,8 @@ export default function Home() {
} }
{ {
settings.listView ? settings.listView ?
<DownloadsListView downloads={activeDownloads ?? []} abortFunction={abort} /> : <DownloadsListView downloads={activeDownloads ?? []} onStop={abort} /> :
<DownloadsCardView downloads={activeDownloads ?? []} abortFunction={abort} /> <DownloadsCardView downloads={activeDownloads ?? []} onStop={abort} />
} }
<Snackbar <Snackbar
open={showToast === status.connected} open={showToast === status.connected}