diff --git a/app/src/Tags.js b/app/src/Tags.js
index 0c1e1d2c..6aab082f 100644
--- a/app/src/Tags.js
+++ b/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}
;
@@ -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 = ;
- if (unusedTags && unusedTags.length) {
- availableTagsGroup = ;
}
- let usedTagsGroup = 'Add tags by clicking them below';
- if (usedTags && usedTags.length) {
- // TODO sort these labels.
- usedTagsGroup = ;
- }
-
- const modal = setOpen(true)}
- onClose={() => setOpen(false)}>
-
- {loading && }
-
-
- {usedTagsGroup}
-
-
-
- {availableTagsGroup}
-
-
-
-
-
+ const selectedTagsGroup = ;
+ const unusedTags = _.difference(tagNames, localTags);
+ const unusedTagsGroup = ;
return <>
setOpen(true)}/>
- {modal}
+ setOpen(true)}
+ onClose={() => setOpen(false)}>
+
+ {loading && }
+
+
+ {localTags && localTags.length > 0 ? selectedTagsGroup : 'Add tags below'}
+
+
+
+ {unusedTags && unusedTags.length > 0 ? unusedTagsGroup : 'You have no tags'}
+
+
+
+
+
>
}
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
-
+
-
- {_.isEmpty(fileGroup['tags']) &&
-
- }
+
}
-export const TagsDisplay = ({fileGroup, afterTag, ...props}) => {
- return
-
-
-}
-
const Dashboard = () => {
const {tagNames, TagsLinkGroup} = React.useContext(TagsContext);
diff --git a/app/src/components/Archive.js b/app/src/components/Archive.js
index ba7b858c..f4b67960 100644
--- a/app/src/components/Archive.js
+++ b/app/src/components/Archive.js
@@ -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() {
;
}
+ const localAddTag = async (name) => {
+ await addTag(archiveFile, name);
+ await fetchArchive();
+ }
+
+ const localRemoveTag = async (name) => {
+ await removeTag(archiveFile, name);
+ await fetchArchive();
+ }
+
return <>
@@ -163,7 +173,9 @@ function ArchivePage() {
-
+
+
+
diff --git a/app/src/components/Download.js b/app/src/components/Download.js
index d399a534..be7cc7ec 100644
--- a/app/src/components/Download.js
+++ b/app/src/components/Download.js
@@ -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 =
@@ -99,6 +106,10 @@ class Downloader extends React.Component {
/>
+
+
+
+
;
diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js
index dc124c4d..8c0ab781 100644
--- a/app/src/components/FilePreview.js
+++ b/app/src/components/FilePreview.js
@@ -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 = Open;
const closeButton = Close;
- const tagsDisplay = ;
+ const tagsDisplay =
+
+ ;
let downloadButton;
if (downloadURL) {
downloadButton =
diff --git a/app/src/components/VideoPlayer.js b/app/src/components/VideoPlayer.js
index e3eec993..55c63280 100644
--- a/app/src/components/VideoPlayer.js
+++ b/app/src/components/VideoPlayer.js
@@ -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}) {
};
- const {poster_file, caption_files, info_json_file} = video;
+ const {poster_file, info_json_file} = video;
let filesPane = {
menuItem: 'Files', render: () =>
Video File
@@ -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 <>
@@ -171,8 +183,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
>
{/* Only WebVTT captions can be displayed. */}
- {vttCaptions &&
- }
+ {captionUrls.map(i => )}
@@ -210,7 +221,9 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
-
+
+
+
diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js
index ffe571f1..409ec5cd 100644
--- a/app/src/hooks/customHooks.js
+++ b/app/src/hooks/customHooks.js
@@ -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,