Creating Event and Flag systems. Events are used to send and display a toast to the App. Flags are used to signal if some action has been performed, or if a package is installed.

This commit is contained in:
Roland 2022-12-23 16:04:09 -07:00
parent 5cbea1ba15
commit 93f0e7494f
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
45 changed files with 923 additions and 355 deletions

View file

@ -20,7 +20,7 @@ import {
BackButton,
CardLink, cardTitleWrapper,
defaultSearchOrder,
epochToDateString,
isoDatetimeToString,
ExternalCardLink,
FileIcon,
HelpHeader,
@ -151,7 +151,7 @@ function ArchivePage() {
<ExternalCardLink to={singlefileUrl}>
<Header as='h2'>{textEllipsis(archive.title || archive.url)}</Header>
</ExternalCardLink>
<Header as='h3'>{epochToDateString(archive.archive_datetime)}</Header>
<Header as='h3'>{isoDatetimeToString(archive.archive_datetime)}</Header>
{domainHeader}
{urlHeader}
@ -208,7 +208,7 @@ export function ArchiveCard({file}) {
</CardLink>}
<CardMeta {...s}>
<p>
{epochToDateString(archive.archive_datetime)}
{isoDatetimeToString(archive.archive_datetime)}
</p>
</CardMeta>
<CardDescription>

View file

@ -80,6 +80,11 @@ export function secondsToElapsedPopup(seconds) {
/>
}
export function isoDatetimeToElapsedPopup(dt) {
const d = new Date(`${dt}+00:00`);
return secondsToElapsedPopup(d.getTime() / 1000);
}
export function secondsToDuration(video) {
let duration = video.duration;
let hours = Math.floor(duration / 3600);
@ -106,11 +111,11 @@ export function Duration({video}) {
}
}
export function epochToDateString(date) {
// Convert a date integer to a human-readable date format.
export function isoDatetimeToString(dt) {
// Convert a datetime to a human-readable date format.
let d = <></>;
if (date) {
d = new Date(date * 1000);
if (dt) {
d = new Date(`${dt}+00:00`);
d = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
}
return d;

View file

@ -13,7 +13,13 @@ class Downloader extends React.Component {
constructor(props) {
super(props);
this.state = {
advancedOpen: false, destination: '', downloader: props.downloader, pending: false, urls: '', valid: true,
advancedOpen: false,
destination: '',
disabled: this.props.disabled,
downloader: props.downloader,
pending: false,
urls: '',
valid: true,
};
}
@ -336,7 +342,7 @@ class RSSDownload extends ChannelDownload {
}
}
export function DownloadMenu({onOpen}) {
export function DownloadMenu({onOpen, disabled}) {
const [downloader, setDownloader] = useState();
const localOnOpen = (name) => {
@ -345,11 +351,33 @@ export function DownloadMenu({onOpen}) {
}
let body = (<>
<Button color='blue' content='Videos' onClick={() => localOnOpen('video')} style={{marginBottom: '1em'}}/>
<Button color='green' content='Archive' onClick={() => localOnOpen('archive')} style={{marginBottom: '1em'}}/>
<Button color='blue' content='Channel/Playlist' onClick={() => localOnOpen('video_channel')}
style={{marginBottom: '1em'}}/>
<Button content='RSS Feed' onClick={() => localOnOpen('rss')} style={{marginBottom: '1em'}}/>
<Button
color='blue'
content='Videos'
disabled={disabled}
onClick={() => localOnOpen('video')}
style={{marginBottom: '1em'}}
/>
<Button
color='green'
content='Archive'
disabled={disabled}
onClick={() => localOnOpen('archive')}
style={{marginBottom: '1em'}}
/>
<Button
color='blue'
content='Channel/Playlist'
disabled={disabled}
onClick={() => localOnOpen('video_channel')}
style={{marginBottom: '1em'}}
/>
<Button
content='RSS Feed'
disabled={disabled}
onClick={() => localOnOpen('rss')}
style={{marginBottom: '1em'}}
/>
</>);
function clearSelected() {
@ -358,12 +386,19 @@ export function DownloadMenu({onOpen}) {
}
const downloaders = {
'archive': <Downloader clearSelected={clearSelected} header={<><Icon name='file alternate'/> Archive</>}
downloader='archive'/>,
'video': <Downloader clearSelected={clearSelected} header={<><Icon name='video'/> Videos</>}
downloader='video' withDestination={true}/>,
'video_channel': <ChannelDownload clearSelected={clearSelected}/>,
'rss': <RSSDownload clearSelected={clearSelected} header={<><Icon name='rss square'/> RSS</>}/>,
archive: <Downloader
clearSelected={clearSelected}
header={<><Icon name='file alternate'/> Archive</>}
downloader='archive'/>,
video: <Downloader
clearSelected={clearSelected}
header={<><Icon name='video'/> Videos</>}
downloader='video'
withDestination={true}/>,
video_channel: <ChannelDownload clearSelected={clearSelected}/>,
rss: <RSSDownload
clearSelected={clearSelected}
header={<><Icon name='rss square'/> RSS</>}/>,
};
body = downloader in downloaders ? downloaders[downloader] : body;

View file

@ -22,7 +22,7 @@ import {deleteFile, refreshDirectoryFiles, refreshFiles} from "../api";
import {
CardGroupCentered,
CardPosterLink, cardTitleWrapper,
epochToDateString,
isoDatetimeToString,
ExternalCardLink,
FileIcon,
humanFileSize,
@ -242,7 +242,7 @@ function ImageCard({file}) {
</ExternalCardLink>
</CardHeader>
<CardMeta {...s}>
<p>{epochToDateString(file.modified / 1000)}</p>
<p>{isoDatetimeToString(file.modified / 1000)}</p>
</CardMeta>
<CardDescription {...s}>
<p>{humanFileSize(file.size)}</p>
@ -284,7 +284,7 @@ function FileCard({file}) {
{cardTitleWrapper(file.title || file.stem || file.path)}
</ExternalCardLink>
</CardHeader>
<p>{epochToDateString(file.modified / 1000)}</p>
<p>{isoDatetimeToString(file.modified / 1000)}</p>
<p>{size}</p>
</CardContent>
</Card>

View file

@ -2,7 +2,7 @@ import React, {useContext, useState} from 'react';
import {deleteVideos} from "../api";
import {Link, useNavigate, useParams} from "react-router-dom";
import _ from "lodash";
import {BackButton, epochToDateString, humanFileSize, humanNumber, PageContainer, useTitle} from "./Common";
import {BackButton, isoDatetimeToString, humanFileSize, humanNumber, PageContainer, useTitle} from "./Common";
import {Confirm} from "semantic-ui-react";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import Container from "semantic-ui-react/dist/commonjs/elements/Container";
@ -175,7 +175,7 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
<Segment>
<Header as='h2'>{video.title || video.video_path}</Header>
{video.upload_date && <h3>{epochToDateString(video.upload_date)}</h3>}
{video.upload_date && <h3>{isoDatetimeToString(video.upload_date)}</h3>}
<h3>
{channel && <Link to={`/videos/channel/${channel.id}/video`}>
{channel.name}

View file

@ -6,7 +6,7 @@ import {
defaultSearchOrder,
defaultVideoOrder,
Duration,
epochToDateString,
isoDatetimeToString,
FileIcon,
isEmpty,
mimetypeColor,
@ -310,7 +310,7 @@ export function VideoCard({file}) {
const {s} = useContext(ThemeContext);
let video_url = `/videos/video/${video.id}`;
const upload_date = epochToDateString(video.upload_date);
const upload_date = isoDatetimeToString(video.upload_date);
// A video may not have a channel.
const channel = video.channel ? video.channel : null;
let channel_url = null;

View file

@ -4,7 +4,7 @@ import {Link} from "react-router-dom";
import {
DisableDownloadsToggle,
isEmpty,
secondsToElapsedPopup,
isoDatetimeToElapsedPopup,
secondsToFrequency,
textEllipsis,
useTitle,
@ -162,10 +162,10 @@ class DownloadRow extends React.Component {
</TableCell>
<TableCell>{secondsToFrequency(frequency)}</TableCell>
<TableCell>
{last_successful_download ? secondsToElapsedPopup(last_successful_download) : null}
{last_successful_download ? isoDatetimeToElapsedPopup(last_successful_download) : null}
{status === 'pending' ? <Loader active inline size='tiny'/> : null}
</TableCell>
<TableCell>{secondsToElapsedPopup(next_download)}</TableCell>
<TableCell>{next_download ? isoDatetimeToElapsedPopup(next_download) : null}</TableCell>
<TableCell>
{error && errorModal}
{deleteButton}
@ -223,7 +223,7 @@ class StoppableRow extends React.Component {
(text) => <Link to={location}>{text}</Link> :
(text) => <a href={url} target='_blank' rel='noopener noreferrer'>{text}</a>;
let completedAtCell = last_successful_download ? secondsToElapsedPopup(last_successful_download) : null;
let completedAtCell = last_successful_download ? isoDatetimeToElapsedPopup(last_successful_download) : null;
let buttonCell = <TableCell/>;
if (status === 'pending' || status === 'new') {
buttonCell = (

View file

@ -28,7 +28,6 @@ export class Settings extends React.Component {
hotspot_status: null,
throttle_on_startup: null,
throttle_status: null,
timezone: {timezone: null},
}
this.handleSubmit = this.handleSubmit.bind(this);
@ -50,7 +49,6 @@ export class Settings extends React.Component {
hotspot_status: settings.hotspot_status,
throttle_on_startup: settings.throttle_on_startup,
throttle_status: settings.throttle_status,
timezone: {value: settings.timezone, label: settings.timezone},
}, this.handleHotspotChange);
} catch (e) {
console.error(e);
@ -68,7 +66,6 @@ export class Settings extends React.Component {
hotspot_password: this.state.hotspot_password,
hotspot_ssid: this.state.hotspot_ssid,
throttle_on_startup: this.state.throttle_on_startup,
timezone: this.state.timezone.value,
}
await saveSettings(settings);
this.setState({disabled: false, pending: false});