Frontend optimizations
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import React, { useEffect, useMemo, useState } from "react"
|
import React, { useEffect, useMemo, useState } from "react"
|
||||||
import { ThemeProvider } from "@emotion/react";
|
import { ThemeProvider } from "@emotion/react";
|
||||||
import {
|
import {
|
||||||
Badge,
|
|
||||||
Box,
|
Box,
|
||||||
createTheme, CssBaseline,
|
createTheme, CssBaseline,
|
||||||
Divider,
|
Divider,
|
||||||
@@ -16,7 +15,7 @@ import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar';
|
|||||||
import {
|
import {
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
Dashboard,
|
Dashboard,
|
||||||
Download,
|
// Download,
|
||||||
Menu, Settings as SettingsIcon,
|
Menu, Settings as SettingsIcon,
|
||||||
SettingsEthernet,
|
SettingsEthernet,
|
||||||
Storage,
|
Storage,
|
||||||
@@ -35,7 +34,6 @@ import { RootState, store } from './stores/store';
|
|||||||
import { Provider, useSelector } from "react-redux";
|
import { Provider, useSelector } from "react-redux";
|
||||||
import ArchivedDownloads from "./Archived";
|
import ArchivedDownloads from "./Archived";
|
||||||
|
|
||||||
|
|
||||||
const drawerWidth: number = 240;
|
const drawerWidth: number = 240;
|
||||||
|
|
||||||
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
|
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
|
||||||
@@ -237,8 +235,8 @@ function AppContent() {
|
|||||||
>
|
>
|
||||||
<Toolbar />
|
<Toolbar />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Home></Home>}></Route>
|
<Route path="/" element={<Home socket={socket}></Home>}></Route>
|
||||||
<Route path="/settings" element={<Settings></Settings>}></Route>
|
<Route path="/settings" element={<Settings socket={socket}></Settings>}></Route>
|
||||||
<Route path="/downloaded" element={<ArchivedDownloads></ArchivedDownloads>}></Route>
|
<Route path="/downloaded" element={<ArchivedDownloads></ArchivedDownloads>}></Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import { IDLInfo, IDLInfoBase, IDownloadInfo, IMessage } from "./interfaces";
|
|||||||
import { RootState } from "./stores/store";
|
import { RootState } from "./stores/store";
|
||||||
import { toFormatArgs, updateInStateMap, } from "./utils";
|
import { toFormatArgs, updateInStateMap, } from "./utils";
|
||||||
|
|
||||||
let socket: Socket;
|
type Props = {
|
||||||
|
socket: Socket
|
||||||
|
}
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home({ socket }: Props) {
|
||||||
// redux state
|
// redux state
|
||||||
const settings = useSelector((state: RootState) => state.settings)
|
const settings = useSelector((state: RootState) => state.settings)
|
||||||
const status = useSelector((state: RootState) => state.status)
|
const status = useSelector((state: RootState) => state.status)
|
||||||
@@ -30,27 +32,16 @@ export default function Home() {
|
|||||||
const [showBackdrop, setShowBackdrop] = useState(false);
|
const [showBackdrop, setShowBackdrop] = useState(false);
|
||||||
|
|
||||||
/* -------------------- Effects -------------------- */
|
/* -------------------- Effects -------------------- */
|
||||||
useEffect(() => {
|
|
||||||
socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`);
|
|
||||||
return () => {
|
|
||||||
socket.disconnect()
|
|
||||||
};
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/* WebSocket connect event handler*/
|
/* WebSocket connect event handler*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
dispatch(connected());
|
dispatch(connected())
|
||||||
socket.emit('fetch-jobs')
|
socket.emit('fetch-jobs')
|
||||||
socket.emit('disk-space')
|
socket.emit('disk-space')
|
||||||
socket.emit('retrieve-jobs');
|
socket.emit('retrieve-jobs')
|
||||||
})
|
});
|
||||||
return () => {
|
|
||||||
socket.disconnect()
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
/* Ask server for pending jobs / background jobs */
|
/* Ask server for pending jobs / background jobs */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on('pending-jobs', (count: number) => {
|
socket.on('pending-jobs', (count: number) => {
|
||||||
@@ -62,7 +53,6 @@ export default function Home() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on('available-formats', (data: IDownloadInfo) => {
|
socket.on('available-formats', (data: IDownloadInfo) => {
|
||||||
setShowBackdrop(false)
|
setShowBackdrop(false)
|
||||||
console.log(data)
|
|
||||||
setDownloadFormats(data);
|
setDownloadFormats(data);
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@@ -19,15 +19,17 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { io } from "socket.io-client";
|
import { io, Socket } from "socket.io-client";
|
||||||
import { LanguageUnion, setCliArgs, setFormatSelection, setLanguage, setServerAddr, setTheme, ThemeUnion } from "./features/settings/settingsSlice";
|
import { LanguageUnion, setCliArgs, setFormatSelection, setLanguage, setServerAddr, setTheme, ThemeUnion } from "./features/settings/settingsSlice";
|
||||||
import { alreadyUpdated, updated } from "./features/status/statusSlice";
|
import { alreadyUpdated, updated } from "./features/status/statusSlice";
|
||||||
import { RootState } from "./stores/store";
|
import { RootState } from "./stores/store";
|
||||||
import { validateDomain, validateIP } from "./utils";
|
import { validateDomain, validateIP } from "./utils";
|
||||||
|
|
||||||
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
|
type Props = {
|
||||||
|
socket: Socket
|
||||||
|
}
|
||||||
|
|
||||||
export default function Settings() {
|
export default function Settings({ socket }: Props) {
|
||||||
const settings = useSelector((state: RootState) => state.settings)
|
const settings = useSelector((state: RootState) => state.settings)
|
||||||
const status = useSelector((state: RootState) => state.status)
|
const status = useSelector((state: RootState) => state.status)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ languages:
|
|||||||
bgReminder: Chiusa questa UI il download continuerà in background.
|
bgReminder: Chiusa questa UI il download continuerà in background.
|
||||||
toastConnected: 'Connesso a '
|
toastConnected: 'Connesso a '
|
||||||
toastUpdated: yt-dlp aggiornato con successo!
|
toastUpdated: yt-dlp aggiornato con successo!
|
||||||
|
formatSelectionEnabler: Abilita la selezione dei formati audio/video
|
||||||
chinese:
|
chinese:
|
||||||
urlInput: YouTube 或其他受支持服务的视频网址
|
urlInput: YouTube 或其他受支持服务的视频网址
|
||||||
statusTitle: 状态
|
statusTitle: 状态
|
||||||
@@ -49,6 +50,7 @@ languages:
|
|||||||
bgReminder: 关闭页面后,下载会继续在后台运行。
|
bgReminder: 关闭页面后,下载会继续在后台运行。
|
||||||
toastConnected: '已连接到 '
|
toastConnected: '已连接到 '
|
||||||
toastUpdated: 已更新 yt-dlp 可执行文件!
|
toastUpdated: 已更新 yt-dlp 可执行文件!
|
||||||
|
formatSelectionEnabler: Enable video/audio formats selection
|
||||||
spanish:
|
spanish:
|
||||||
urlInput: YouTube or other supported service video url
|
urlInput: YouTube or other supported service video url
|
||||||
statusTitle: Status
|
statusTitle: Status
|
||||||
@@ -65,6 +67,7 @@ languages:
|
|||||||
bgReminder: Once you close this page the download will continue in the background.
|
bgReminder: Once you close this page the download will continue in the background.
|
||||||
toastConnected: 'Connected to '
|
toastConnected: 'Connected to '
|
||||||
toastUpdated: Updated yt-dlp binary!
|
toastUpdated: Updated yt-dlp binary!
|
||||||
|
formatSelectionEnabler: Enable video/audio formats selection
|
||||||
russian:
|
russian:
|
||||||
urlInput: YouTube or other supported service video url
|
urlInput: YouTube or other supported service video url
|
||||||
statusTitle: Status
|
statusTitle: Status
|
||||||
@@ -81,6 +84,7 @@ languages:
|
|||||||
bgReminder: Once you close this page the download will continue in the background.
|
bgReminder: Once you close this page the download will continue in the background.
|
||||||
toastConnected: 'Connected to '
|
toastConnected: 'Connected to '
|
||||||
toastUpdated: Updated yt-dlp binary!
|
toastUpdated: Updated yt-dlp binary!
|
||||||
|
formatSelectionEnabler: Enable video/audio formats selection
|
||||||
korean:
|
korean:
|
||||||
urlInput: YouTube나 다른 지원되는 사이트의 URL
|
urlInput: YouTube나 다른 지원되는 사이트의 URL
|
||||||
statusTitle: 상태
|
statusTitle: 상태
|
||||||
@@ -97,3 +101,4 @@ languages:
|
|||||||
bgReminder: 이 페이지를 닫아도 백그라운드에서 다운로드가 계속됩니다
|
bgReminder: 이 페이지를 닫아도 백그라운드에서 다운로드가 계속됩니다
|
||||||
toastConnected: '다음으로 연결됨 '
|
toastConnected: '다음으로 연결됨 '
|
||||||
toastUpdated: yt-dlp 바이너리를 업데이트 했습니다
|
toastUpdated: yt-dlp 바이너리를 업데이트 했습니다
|
||||||
|
formatSelectionEnabler: Enable video/audio formats selection
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ io.on('connection', socket => {
|
|||||||
download(socket, args)
|
download(socket, args)
|
||||||
})
|
})
|
||||||
socket.on('send-url-format-selection', (args) => {
|
socket.on('send-url-format-selection', (args) => {
|
||||||
logger('ws', args?.url)
|
logger('ws', `Formats ${args?.url}`)
|
||||||
if (args.url) getFormatsAndInfo(socket, args?.url)
|
if (args.url) getFormatsAndInfo(socket, args?.url)
|
||||||
})
|
})
|
||||||
socket.on('abort', (args) => {
|
socket.on('abort', (args) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user