mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 16:06:19 -05:00
Modifying AddTagsButton with an internal state to track tags. Video captions are displayed again.
This commit is contained in:
parent
fbfb3458e3
commit
a893d44094
6 changed files with 114 additions and 86 deletions
117
app/src/Tags.js
117
app/src/Tags.js
|
|
@ -78,7 +78,7 @@ export function useTags() {
|
|||
size='large'
|
||||
{...props} // onClick passed here.
|
||||
style={style}
|
||||
className='clickable'
|
||||
className={props.onClick ? 'clickable' : null}
|
||||
>
|
||||
{name}
|
||||
</Label>;
|
||||
|
|
@ -248,110 +248,89 @@ function EditTagsModal() {
|
|||
</>
|
||||
}
|
||||
|
||||
export function AddTagsButton({fileGroup, afterTag}) {
|
||||
const {tags: usedTags} = fileGroup;
|
||||
const {tags: availableTags, TagsGroup} = React.useContext(TagsContext);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
export function AddTagsButton({selectedTagNames = [], onToggle = _.noop, onAdd = _.noop, onRemove = _.noop}) {
|
||||
// A button which displays a modal in which the user can add or remove tags.
|
||||
|
||||
const localAddTag = async (name) => {
|
||||
const {tagNames, TagsGroup} = React.useContext(TagsContext);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [localTags, setLocalTags] = React.useState(selectedTagNames);
|
||||
|
||||
const addTag = (name) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await addTag(fileGroup, name);
|
||||
console.debug('Added tag');
|
||||
if (afterTag) {
|
||||
console.debug('Calling afterTag');
|
||||
await afterTag();
|
||||
}
|
||||
const newTags = [...localTags, name];
|
||||
setLocalTags(newTags);
|
||||
onToggle(newTags);
|
||||
onAdd(name);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const localRemoveTag = async (name) => {
|
||||
const removeTag = (name) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await removeTag(fileGroup, name);
|
||||
console.debug('Removed tag');
|
||||
if (afterTag) {
|
||||
console.debug('Calling afterTag');
|
||||
await afterTag();
|
||||
}
|
||||
const newTags = localTags.filter(i => i !== name);
|
||||
setLocalTags(newTags);
|
||||
onToggle(newTags);
|
||||
onRemove(name);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const availableTagNames = availableTags && availableTags.length ? availableTags.map(i => i['name']) : [];
|
||||
|
||||
const unusedTags = _.difference(availableTagNames, usedTags);
|
||||
|
||||
let availableTagsGroup = <SLoader active inline/>;
|
||||
if (unusedTags && unusedTags.length) {
|
||||
availableTagsGroup = <TagsGroup tagNames={unusedTags} onClick={localAddTag}/>;
|
||||
}
|
||||
|
||||
let usedTagsGroup = 'Add tags by clicking them below';
|
||||
if (usedTags && usedTags.length) {
|
||||
// TODO sort these labels.
|
||||
usedTagsGroup = <TagsGroup tagNames={usedTags} onClick={localRemoveTag}/>;
|
||||
}
|
||||
|
||||
const modal = <Modal closeIcon
|
||||
open={open}
|
||||
onOpen={() => setOpen(true)}
|
||||
onClose={() => setOpen(false)}>
|
||||
<Modal.Content>
|
||||
{loading && <Dimmer active><SLoader/></Dimmer>}
|
||||
<Header as='h4'>Used Tags</Header>
|
||||
|
||||
{usedTagsGroup}
|
||||
|
||||
<Divider/>
|
||||
|
||||
{availableTagsGroup}
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<EditTagsModal/>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
const selectedTagsGroup = <TagsGroup tagNames={localTags} onClick={removeTag}/>;
|
||||
const unusedTags = _.difference(tagNames, localTags);
|
||||
const unusedTagsGroup = <TagsGroup tagNames={unusedTags} onClick={addTag}/>;
|
||||
|
||||
return <>
|
||||
<SButton icon='tag' onClick={() => setOpen(true)}/>
|
||||
{modal}
|
||||
<Modal closeIcon
|
||||
open={open}
|
||||
onOpen={() => setOpen(true)}
|
||||
onClose={() => setOpen(false)}>
|
||||
<Modal.Content>
|
||||
{loading && <Dimmer active><SLoader/></Dimmer>}
|
||||
<Header as='h4'>Applied Tags</Header>
|
||||
|
||||
{localTags && localTags.length > 0 ? selectedTagsGroup : 'Add tags below'}
|
||||
|
||||
<Divider/>
|
||||
|
||||
{unusedTags && unusedTags.length > 0 ? unusedTagsGroup : 'You have no tags'}
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<EditTagsModal/>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
|
||||
export const taggedImageLabel = {corner: 'left', icon: 'tag', color: 'green'};
|
||||
|
||||
const Display = ({fileGroup, afterTag}) => {
|
||||
export const TagsSelector = ({selectedTagNames = [], onToggle = _.noop, onAdd = _.noop, onRemove = _.noop}) => {
|
||||
// Provides a button to add tags to a list. Displays the tags of that list.
|
||||
const {TagsLinkGroup} = React.useContext(TagsContext);
|
||||
|
||||
if (!fileGroup || !TagsLinkGroup) {
|
||||
return
|
||||
if (!TagsLinkGroup) {
|
||||
// Tags have not been fetched.
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return <Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column mobile={2} computer={1}>
|
||||
<AddTagsButton fileGroup={fileGroup} afterTag={afterTag}/>
|
||||
<AddTagsButton selectedTagNames={selectedTagNames} onToggle={onToggle} onAdd={onAdd}
|
||||
onRemove={onRemove}/>
|
||||
</Grid.Column>
|
||||
<Grid.Column mobile={13} computer={14}>
|
||||
<TagsLinkGroup tagNames={fileGroup['tags']}/>
|
||||
{_.isEmpty(fileGroup['tags']) &&
|
||||
<HelpPopup content='Click the button to add tags' iconSize={null}/>
|
||||
}
|
||||
<TagsLinkGroup tagNames={selectedTagNames}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
}
|
||||
|
||||
export const TagsDisplay = ({fileGroup, afterTag, ...props}) => {
|
||||
return <TagsProvider>
|
||||
<Display fileGroup={fileGroup} afterTag={afterTag} {...props}/>
|
||||
</TagsProvider>
|
||||
}
|
||||
|
||||
const Dashboard = () => {
|
||||
const {tagNames, TagsLinkGroup} = React.useContext(TagsContext);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import {
|
|||
textEllipsis,
|
||||
useTitle
|
||||
} from "./Common";
|
||||
import {deleteArchives, postDownload} from "../api";
|
||||
import {addTag, deleteArchives, postDownload, removeTag} from "../api";
|
||||
import {Link, Route, Routes, useNavigate, useParams} from "react-router-dom";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {useArchive, useDomains, useQuery, useSearchArchives} from "../hooks/customHooks";
|
||||
|
|
@ -43,7 +43,7 @@ import _ from "lodash";
|
|||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {Button, Card, CardIcon, Header, Loader, Placeholder, Segment} from "./Theme";
|
||||
import {SortableTable} from "./SortableTable";
|
||||
import {taggedImageLabel, TagsDisplay} from "../Tags";
|
||||
import {taggedImageLabel, TagsProvider, TagsSelector} from "../Tags";
|
||||
|
||||
function ArchivePage() {
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
|
@ -144,6 +144,16 @@ function ArchivePage() {
|
|||
</Header>;
|
||||
}
|
||||
|
||||
const localAddTag = async (name) => {
|
||||
await addTag(archiveFile, name);
|
||||
await fetchArchive();
|
||||
}
|
||||
|
||||
const localRemoveTag = async (name) => {
|
||||
await removeTag(archiveFile, name);
|
||||
await fetchArchive();
|
||||
}
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
|
||||
|
|
@ -163,7 +173,9 @@ function ArchivePage() {
|
|||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<TagsDisplay fileGroup={archiveFile} onClick={fetchArchive}/>
|
||||
<TagsProvider>
|
||||
<TagsSelector selectedTagNames={archiveFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
||||
</TagsProvider>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {ThemeContext} from "../contexts/contexts";
|
|||
import {Accordion, Button, Form, FormField, FormGroup, FormInput, Header, Loader, Segment, TextArea} from "./Theme";
|
||||
import {AccordionContent, AccordionTitle, FormDropdown} from "semantic-ui-react";
|
||||
import {Link} from "react-router-dom";
|
||||
import {TagsProvider, TagsSelector} from "../Tags";
|
||||
|
||||
const validUrl = /^(http|https):\/\/[^ "]+$/;
|
||||
|
||||
|
|
@ -19,9 +20,10 @@ class Downloader extends React.Component {
|
|||
disabled: this.props.disabled,
|
||||
downloader: props.downloader,
|
||||
pending: false,
|
||||
submitted: false,
|
||||
tagNames: [],
|
||||
urls: '',
|
||||
valid: true,
|
||||
submitted: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +71,11 @@ class Downloader extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleSelectedTags = (tagNames) => {
|
||||
console.log(tagNames);
|
||||
this.setState({tagNames});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.addEventListener('keydown', this.handleKeydown);
|
||||
}
|
||||
|
|
@ -79,7 +86,7 @@ class Downloader extends React.Component {
|
|||
|
||||
render() {
|
||||
let disabled = !this.state.urls || !this.state.valid || this.state.pending || !this.state.downloader;
|
||||
const {advancedOpen, destination, submitted} = this.state;
|
||||
const {advancedOpen, destination, submitted, tagNames} = this.state;
|
||||
const {header, withDestination} = this.props;
|
||||
|
||||
const advancedAccordion = <Accordion>
|
||||
|
|
@ -99,6 +106,10 @@ class Downloader extends React.Component {
|
|||
/>
|
||||
</FormField>
|
||||
</FormGroup>
|
||||
<br/>
|
||||
<TagsProvider>
|
||||
<TagsSelector selectedTagNames={tagNames} onToggle={this.handleSelectedTags}/>
|
||||
</TagsProvider>
|
||||
</Segment>
|
||||
</AccordionContent>
|
||||
</Accordion>;
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import {
|
|||
ModalContent,
|
||||
ModalHeader
|
||||
} from "semantic-ui-react";
|
||||
import {TagsDisplay, TagsProvider} from "../Tags";
|
||||
import {TagsProvider, TagsSelector} from "../Tags";
|
||||
import {Media} from "../contexts/contexts";
|
||||
import {encodeMediaPath} from "./Common";
|
||||
import {fetchFile} from "../api";
|
||||
import {addTag, fetchFile, removeTag} from "../api";
|
||||
|
||||
function getMediaPathURL(previewFile) {
|
||||
if (previewFile['primary_path']) {
|
||||
|
|
@ -167,10 +167,22 @@ export function FilePreviewWrapper({children}) {
|
|||
}
|
||||
}
|
||||
|
||||
const localAddTag = async (name) => {
|
||||
await addTag(previewFile, name);
|
||||
await localFetchFile();
|
||||
}
|
||||
|
||||
const localRemoveTag = async (name) => {
|
||||
await removeTag(previewFile, name);
|
||||
await localFetchFile();
|
||||
}
|
||||
|
||||
function setModalContent(content, url, downloadURL) {
|
||||
const openButton = <SButton color='blue' as='a' href={url}>Open</SButton>;
|
||||
const closeButton = <SButton onClick={handleClose}>Close</SButton>;
|
||||
const tagsDisplay = <TagsDisplay fileGroup={previewFile} afterTag={localFetchFile}/>;
|
||||
const tagsDisplay = <TagsProvider>
|
||||
<TagsSelector selectedTagNames={previewFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
||||
</TagsProvider>;
|
||||
let downloadButton;
|
||||
if (downloadURL) {
|
||||
downloadButton = <SButton color='yellow' as='a' href={downloadURL} floated='left'>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, {useContext, useState} from 'react';
|
||||
import {deleteVideos} from "../api";
|
||||
import {addTag, deleteVideos, removeTag} from "../api";
|
||||
import {Link, useNavigate, useParams} from "react-router-dom";
|
||||
import _ from "lodash";
|
||||
import {
|
||||
|
|
@ -20,7 +20,7 @@ import {useChannel} from "../hooks/customHooks";
|
|||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {Button, darkTheme, Header, Icon, Segment, Tab, TabPane} from "./Theme";
|
||||
import {VideoCard} from "./Videos";
|
||||
import {TagsDisplay} from "../Tags";
|
||||
import {TagsProvider, TagsSelector} from "../Tags";
|
||||
|
||||
const MEDIA_PATH = '/media';
|
||||
|
||||
|
|
@ -83,8 +83,10 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
let downloadUrl = `/download/${encodeMediaPath(video.video_path)}`;
|
||||
|
||||
let posterUrl = video.poster_path ? `${MEDIA_PATH}/${encodeMediaPath(video.poster_path)}` : null;
|
||||
let captionsUrl = video.caption_path ? `${MEDIA_PATH}/${encodeMediaPath(video.caption_path)}` : null;
|
||||
let vttCaptions = video.caption_path && video.caption_path.endsWith('.vtt');
|
||||
const {caption_files} = video;
|
||||
const captionUrls = caption_files && caption_files.length > 0 ?
|
||||
caption_files.filter(i => i['mimetype'] === 'text/vtt').map(i => `${MEDIA_PATH}/${encodeMediaPath(i['path'])}`)
|
||||
: [];
|
||||
|
||||
let description = 'No description available.';
|
||||
if (video && video['description']) {
|
||||
|
|
@ -123,7 +125,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
</TabPane>
|
||||
};
|
||||
|
||||
const {poster_file, caption_files, info_json_file} = video;
|
||||
const {poster_file, info_json_file} = video;
|
||||
let filesPane = {
|
||||
menuItem: 'Files', render: () => <TabPane>
|
||||
<h3>Video File</h3>
|
||||
|
|
@ -156,6 +158,16 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
let tabPanes = [descriptionPane, aboutPane, filesPane, captionsPane];
|
||||
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
|
||||
|
||||
const localAddTag = async (name) => {
|
||||
await addTag(videoFile, name);
|
||||
await fetchVideo();
|
||||
}
|
||||
|
||||
const localRemoveTag = async (name) => {
|
||||
await removeTag(videoFile, name);
|
||||
await fetchVideo();
|
||||
}
|
||||
|
||||
return <>
|
||||
<Container style={{margin: '1em'}}>
|
||||
<BackButton/>
|
||||
|
|
@ -171,8 +183,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
>
|
||||
<source src={videoUrl} type="video/mp4"/>
|
||||
{/* Only WebVTT captions can be displayed. */}
|
||||
{vttCaptions &&
|
||||
<track kind="captions" label="English" src={captionsUrl} srcLang="en" default/>}
|
||||
{captionUrls.map(i => <track kind="captions" label="English" src={i} srcLang="en" default/>)}
|
||||
</video>
|
||||
|
||||
<Container style={{marginTop: '1em'}}>
|
||||
|
|
@ -210,7 +221,9 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<TagsDisplay fileGroup={videoFile} afterTag={fetchVideo}/>
|
||||
<TagsProvider>
|
||||
<TagsSelector selectedTagNames={videoFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
||||
</TagsProvider>
|
||||
</Segment>
|
||||
|
||||
<Tab menu={tabMenu} panes={tabPanes}/>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {useContext, useEffect, useRef, useState} from "react";
|
||||
import {
|
||||
addTag,
|
||||
fetchDomains,
|
||||
fetchFilesProgress,
|
||||
filesSearch,
|
||||
|
|
@ -17,7 +18,7 @@ import {
|
|||
getThrottleStatus,
|
||||
getVideo,
|
||||
getVideosStatistics,
|
||||
killDownloads,
|
||||
killDownloads, removeTag,
|
||||
searchArchives,
|
||||
searchVideos,
|
||||
setHotspot,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue