-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web/recent): display recently downloaded jobs
- Loading branch information
Showing
8 changed files
with
238 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Code generated by tygo. DO NOT EDIT. | ||
|
||
////////// | ||
// source: job.go | ||
|
||
export interface DownloadJob { | ||
ID: string; | ||
URL: string; | ||
TIMESTAMP: string /* RFC3339 */; | ||
} | ||
export interface JobData { | ||
ID: string; | ||
JobID: string; | ||
URL: string; | ||
IsPlaylist: boolean; | ||
STATUS: string; | ||
PROGRESS: number /* int */; | ||
CreatedAt: string /* RFC3339 */; | ||
UpdatedAt: string /* RFC3339 */; | ||
} | ||
|
||
////////// | ||
// source: metadata.go | ||
|
||
export interface VideoMetadata { | ||
id: string; | ||
title: string; | ||
uploader: string; | ||
filesize: number /* int64 */; | ||
duration: number /* float64 */; | ||
format: string; | ||
thumbnail: string; | ||
} | ||
export interface PlaylistMetadata { | ||
id: string; | ||
title: string; | ||
description: string; | ||
} | ||
|
||
////////// | ||
// source: video.go | ||
|
||
/** | ||
* Video represents metadata for a single video. | ||
*/ | ||
export interface Video { | ||
id: number /* int */; // Primary key in database | ||
job_id: string; // ID associated with the download job | ||
title: string; // Title of the video | ||
uploader: string; // Uploader or channel name | ||
file_path: string; // Path where the video file is stored | ||
last_downloaded_at: string /* RFC3339 */; // Timestamp of when the video was last downloaded | ||
length: number /* float64 */; // Duration of the video in seconds | ||
size: number /* int64 */; // File size in bytes | ||
quality: string; // Video quality | ||
} | ||
/** | ||
* Playlist represents metadata for a playlist or channel. | ||
*/ | ||
export interface Playlist { | ||
id: string; // Playlist or channel ID | ||
title: string; // Title of the playlist or channel | ||
description: string; // Description of the playlist or channel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {Card, CardHeader, CardContent, CardTitle} from "@/components/ui/card"; | ||
import {Progress} from "@/components/ui/progress"; | ||
import {JobData} from "@/types"; | ||
import useAppState from "@/store/appState"; | ||
|
||
const Recent: React.FC = () => { | ||
const [jobs, setJobs] = useState<JobData[]>(); | ||
const [message, setMessage] = useState(""); | ||
|
||
useEffect(() => { | ||
fetch(process.env.NEXT_PUBLIC_SERVER_URL + "/recent").then((res) => { | ||
if (!res.ok) { | ||
setMessage("No recent jobs found."); | ||
return; | ||
} | ||
return res.json() | ||
}).then((data) => { | ||
setJobs(data.message); | ||
}); | ||
|
||
const unsubscribe = useAppState.subscribe( | ||
(state) => { | ||
if (state.isDownloading) { | ||
setMessage('') | ||
unsubscribe(); | ||
} | ||
} | ||
); | ||
}, []); | ||
|
||
return ( | ||
<div className="space-y-4 max-w-screen-md"> | ||
{jobs && !message && jobs.map((job) => ( | ||
<Card key={job.JobID} className="w-full max-w-screen-sm"> | ||
<CardHeader> | ||
<CardTitle>{job.URL}</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<p> | ||
Progress: ({job.PROGRESS}%) | ||
</p> | ||
<Progress value={job.PROGRESS} className="mt-2"/> | ||
</CardContent> | ||
</Card> | ||
))} | ||
{message && <p>{message}</p>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Recent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { create } from 'zustand'; | ||
|
||
interface AppState { | ||
isDownloading: boolean; | ||
setIsDownloading: (value: boolean) => void; | ||
} | ||
|
||
const useAppState = create<AppState>((set) => ({ | ||
isDownloading: false, // Initial state | ||
setIsDownloading: (value) => set(() => ({ isDownloading: value })), // Mutator | ||
})); | ||
|
||
export default useAppState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Code generated by tygo. DO NOT EDIT. | ||
|
||
////////// | ||
// source: job.go | ||
|
||
export interface DownloadJob { | ||
ID: string; | ||
URL: string; | ||
TIMESTAMP: string /* RFC3339 */; | ||
} | ||
export interface JobData { | ||
ID: string; | ||
JobID: string; | ||
URL: string; | ||
IsPlaylist: boolean; | ||
STATUS: string; | ||
PROGRESS: number /* int */; | ||
CreatedAt: string /* RFC3339 */; | ||
UpdatedAt: string /* RFC3339 */; | ||
} | ||
|
||
////////// | ||
// source: metadata.go | ||
|
||
export interface VideoMetadata { | ||
id: string; | ||
title: string; | ||
uploader: string; | ||
filesize: number /* int64 */; | ||
duration: number /* float64 */; | ||
format: string; | ||
thumbnail: string; | ||
} | ||
export interface PlaylistMetadata { | ||
id: string; | ||
title: string; | ||
description: string; | ||
} | ||
|
||
////////// | ||
// source: video.go | ||
|
||
/** | ||
* Video represents metadata for a single video. | ||
*/ | ||
export interface Video { | ||
id: number /* int */; // Primary key in database | ||
job_id: string; // ID associated with the download job | ||
title: string; // Title of the video | ||
uploader: string; // Uploader or channel name | ||
file_path: string; // Path where the video file is stored | ||
last_downloaded_at: string /* RFC3339 */; // Timestamp of when the video was last downloaded | ||
length: number /* float64 */; // Duration of the video in seconds | ||
size: number /* int64 */; // File size in bytes | ||
quality: string; // Video quality | ||
} | ||
/** | ||
* Playlist represents metadata for a playlist or channel. | ||
*/ | ||
export interface Playlist { | ||
id: string; // Playlist or channel ID | ||
title: string; // Title of the playlist or channel | ||
description: string; // Description of the playlist or channel | ||
} |