mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 04:46:18 -05:00
Only files that have been tagged will be returned when new 'Any' tag button is used to filter file search results.
This commit is contained in:
parent
f3439c2bd5
commit
53d2402d32
31 changed files with 303 additions and 146 deletions
|
|
@ -161,7 +161,7 @@ export function DashboardPage() {
|
|||
const navigate = useNavigate();
|
||||
|
||||
// The search the user submitted.
|
||||
const {searchStr, setSearchStr, activeTags, isEmpty} = useSearch();
|
||||
const {searchStr, setSearchStr, activeTags, isEmpty, anyTag} = useSearch();
|
||||
// The search that the user is typing.
|
||||
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr);
|
||||
const {
|
||||
|
|
@ -174,7 +174,7 @@ export function DashboardPage() {
|
|||
setSearchStr: setSuggestionSearchStr,
|
||||
setSearchTags,
|
||||
months, dateRange, setDates, clearDate,
|
||||
} = useSearchSuggestions(searchStr, activeTags);
|
||||
} = useSearchSuggestions(searchStr, activeTags, anyTag);
|
||||
|
||||
React.useEffect(() => {
|
||||
setSuggestionSearchStr(localSearchStr);
|
||||
|
|
|
|||
|
|
@ -310,11 +310,12 @@ function EditTagsModal() {
|
|||
|
||||
export function AddTagsButton({
|
||||
hideEdit,
|
||||
active,
|
||||
showAny = false,
|
||||
selectedTagNames = [],
|
||||
onToggle = _.noop,
|
||||
anyTag = false,
|
||||
onAdd = _.noop,
|
||||
onRemove = _.noop,
|
||||
onChange = _.noop, // Expects to send: (tagNames, anyTag)
|
||||
limit = null,
|
||||
}) {
|
||||
// A button which displays a modal in which the user can add or remove tags.
|
||||
|
|
@ -324,6 +325,8 @@ export function AddTagsButton({
|
|||
const [loading, setLoading] = React.useState(false);
|
||||
const [localTags, setLocalTags] = React.useState(selectedTagNames);
|
||||
|
||||
const active = anyTag || (selectedTagNames && selectedTagNames.length > 0);
|
||||
|
||||
const handleOpen = (e) => {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
|
|
@ -339,8 +342,8 @@ export function AddTagsButton({
|
|||
return;
|
||||
}
|
||||
setLocalTags(newTags);
|
||||
onToggle(newTags);
|
||||
onAdd(name);
|
||||
onChange(newTags, null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
|
@ -350,30 +353,30 @@ export function AddTagsButton({
|
|||
setLoading(true);
|
||||
try {
|
||||
const newTags = localTags.filter(i => i !== name);
|
||||
setLocalTags(newTags);
|
||||
onToggle(newTags);
|
||||
setLocalTags(newTags)
|
||||
onRemove(name);
|
||||
onChange(newTags, null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
const clearLocalTags = () => {
|
||||
if (!localTags || (localTags && localTags.length === 0)) {
|
||||
if (!anyTag && (!localTags || (localTags && localTags.length === 0))) {
|
||||
console.debug('No tags to clear');
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
for (let i = 0; i < localTags.length; i++) {
|
||||
onRemove(localTags[i]);
|
||||
}
|
||||
setLocalTags([]);
|
||||
onToggle([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
console.debug('Clearing selected tags');
|
||||
onChange([], null);
|
||||
setLocalTags([]);
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
const localOnAnyTag = () => {
|
||||
console.debug('Setting any tag');
|
||||
onChange([], true);
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
const selectedTagsGroup = <TagsGroup tagNames={localTags} onClick={removeTag}/>;
|
||||
|
|
@ -382,7 +385,11 @@ export function AddTagsButton({
|
|||
const emptySelectedTags = limit === 1 ? 'Add only one tag below' : 'Add one or more tags below';
|
||||
|
||||
return <>
|
||||
<Button icon={active ? 'tags' : 'tag'} onClick={handleOpen} primary={!!active}/>
|
||||
<Button
|
||||
icon={active ? 'tags' : 'tag'}
|
||||
color={active ? 'violet' : undefined}
|
||||
onClick={handleOpen}
|
||||
/>
|
||||
<Modal closeIcon
|
||||
open={open}
|
||||
onOpen={(e) => handleOpen(e)}
|
||||
|
|
@ -405,6 +412,7 @@ export function AddTagsButton({
|
|||
</Grid.Column>
|
||||
<Grid.Column width={8}>
|
||||
<Button onClick={() => setOpen(false)} floated='right'>Close</Button>
|
||||
{showAny && <Button color='violet' onClick={localOnAnyTag} floated='right'>Any</Button>}
|
||||
<Button floated='right' secondary onClick={() => clearLocalTags()}>Clear</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
|
|
@ -418,12 +426,13 @@ export const taggedImageLabel = {corner: 'left', icon: 'tag', color: 'green'};
|
|||
|
||||
export const TagsSelector = ({
|
||||
hideEdit = false,
|
||||
active,
|
||||
showAny = false,
|
||||
hideGroup = false,
|
||||
selectedTagNames = [],
|
||||
onToggle = _.noop,
|
||||
anyTag = false,
|
||||
onAdd = _.noop,
|
||||
onRemove = _.noop,
|
||||
onChange = _.noop,
|
||||
limit = null,
|
||||
}) => {
|
||||
// Provides a button to add tags to a list. Displays the tags of that list.
|
||||
|
|
@ -436,11 +445,12 @@ export const TagsSelector = ({
|
|||
|
||||
const button = <AddTagsButton
|
||||
hideEdit={hideEdit}
|
||||
active={active}
|
||||
showAny={showAny}
|
||||
selectedTagNames={selectedTagNames}
|
||||
onToggle={onToggle}
|
||||
onAdd={onAdd}
|
||||
onRemove={onRemove}
|
||||
onChange={onChange}
|
||||
anyTag={anyTag}
|
||||
limit={limit}
|
||||
/>;
|
||||
|
||||
|
|
|
|||
|
|
@ -627,8 +627,8 @@ export async function deleteDownload(downloadId) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline, months, fromYear, toYear) {
|
||||
const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit)};
|
||||
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline, months, fromYear, toYear, anyTag) {
|
||||
const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit), any_tag: anyTag};
|
||||
if (mimetypes) {
|
||||
body['mimetypes'] = mimetypes;
|
||||
}
|
||||
|
|
@ -1183,10 +1183,10 @@ export async function searchSuggestions(search_str) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function searchEstimateFiles(search_str, tagNames, mimetypes, months, dateRange) {
|
||||
export async function searchEstimateFiles(search_str, tagNames, mimetypes, months, dateRange, anyTag) {
|
||||
months = months ? months.map(i => parseInt(i)) : [];
|
||||
|
||||
const body = {search_str, tag_names: tagNames, mimetypes, months};
|
||||
const body = {search_str, tag_names: tagNames, mimetypes, months, any_tag: anyTag};
|
||||
if (dateRange) {
|
||||
body['from_year'] = dateRange[0];
|
||||
body['to_year'] = dateRange[1];
|
||||
|
|
@ -1198,6 +1198,8 @@ export async function searchEstimateFiles(search_str, tagNames, mimetypes, month
|
|||
return {
|
||||
fileGroups: content.file_groups,
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to get file search estimates!');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -263,7 +263,11 @@ function ArchivePage() {
|
|||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<TagsSelector selectedTagNames={archiveFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
||||
<TagsSelector
|
||||
selectedTagNames={archiveFile['tags']}
|
||||
onAdd={localAddTag}
|
||||
onRemove={localRemoveTag}
|
||||
/>
|
||||
</Segment>
|
||||
|
||||
<Tab menu={tabMenu} panes={tabPanes}/>
|
||||
|
|
@ -497,14 +501,16 @@ function ArchivesPage() {
|
|||
</div>;
|
||||
|
||||
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
|
||||
archives,
|
||||
activePage,
|
||||
totalPages,
|
||||
selectElm,
|
||||
selectedArchives,
|
||||
onSelect,
|
||||
setPage,
|
||||
!!searchStr,
|
||||
{
|
||||
files: archives,
|
||||
activePage: activePage,
|
||||
totalPages: totalPages,
|
||||
selectElem: selectElm,
|
||||
selectedKeys: selectedArchives,
|
||||
onSelect: onSelect,
|
||||
setPage: setPage,
|
||||
headlines: !!searchStr
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -488,14 +488,6 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download
|
|||
}
|
||||
};
|
||||
|
||||
const handleAddTag = (tagName) => {
|
||||
setTagNames([...tagNames, tagName]);
|
||||
}
|
||||
|
||||
const handleUntag = (tagName) => {
|
||||
setTagNames(tagNames.filter(i => i !== tagName));
|
||||
}
|
||||
|
||||
const deleteDownloadButton = <APIButton
|
||||
color='red'
|
||||
floated='left'
|
||||
|
|
@ -571,7 +563,7 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download
|
|||
</Grid.Row>
|
||||
<Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<TagsSelector selectedTagNames={tagNames} onAdd={handleAddTag} onRemove={handleUntag}/>
|
||||
<TagsSelector selectedTagNames={tagNames} onChange={(i, j) => setTagNames(i)}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row columns={1}>
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class Downloader extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleSelectedTags = (tagNames) => {
|
||||
handleTagsChange = (tagNames, newAnyTag) => {
|
||||
this.setState({tagNames});
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ class Downloader extends React.Component {
|
|||
|
||||
let tagsSelector;
|
||||
if (withTags) {
|
||||
tagsSelector = <TagsSelector selectedTagNames={tagNames} onToggle={this.handleSelectedTags}/>;
|
||||
tagsSelector = <TagsSelector selectedTagNames={tagNames} onChange={this.handleTagsChange}/>;
|
||||
}
|
||||
|
||||
const advancedAccordion = <Accordion>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import {
|
|||
useTitle
|
||||
} from "./Common";
|
||||
import {
|
||||
useAllQuery,
|
||||
useFilesProgressInterval,
|
||||
usePages,
|
||||
useSearchFiles,
|
||||
|
|
@ -66,6 +65,7 @@ import {refreshFiles} from "../api";
|
|||
import {useSubscribeEventName} from "../Events";
|
||||
import {TagsSelector} from "../Tags";
|
||||
import {Headlines} from "./Headline";
|
||||
import {useSearch} from "./Search";
|
||||
|
||||
function EbookCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
|
|
@ -311,15 +311,18 @@ export function SearchLimitDropdown({limits = []}) {
|
|||
}
|
||||
|
||||
export function FilesView(
|
||||
files,
|
||||
activePage,
|
||||
totalPages,
|
||||
selectElem,
|
||||
selectedKeys,
|
||||
onSelect,
|
||||
setPage,
|
||||
headlines = false,
|
||||
limitOptions = [12, 24, 48, 96],
|
||||
{
|
||||
files,
|
||||
activePage,
|
||||
totalPages,
|
||||
selectElem,
|
||||
selectedKeys,
|
||||
onSelect,
|
||||
setPage,
|
||||
headlines = false,
|
||||
limitOptions = [12, 24, 48, 96],
|
||||
showAnyTag = false,
|
||||
},
|
||||
) {
|
||||
const {view} = useSearchView();
|
||||
|
||||
|
|
@ -360,7 +363,7 @@ export function FilesView(
|
|||
|
||||
const viewButton = <SearchViewButton headlines={headlines}/>
|
||||
const limitDropdown = <SearchLimitDropdown limits={limitOptions}/>;
|
||||
const tagQuerySelector = <TagsQuerySelector/>;
|
||||
const tagQuerySelector = <TagsQuerySelector showAny={showAnyTag}/>;
|
||||
|
||||
return {
|
||||
body,
|
||||
|
|
@ -432,22 +435,28 @@ export function SearchFilter({filters = [], modalHeader, size = 'medium'}) {
|
|||
return <></>
|
||||
}
|
||||
|
||||
export function TagsQuerySelector({onChange}) {
|
||||
// Creates modal that the User can use to manipulate the tag query.
|
||||
const [activeTags, setActiveTags] = useAllQuery('tag');
|
||||
export function TagsQuerySelector({onChange, showAny = true}) {
|
||||
// Creates modal that the User can use to manipulate the tag query params.
|
||||
const {activeTags, anyTag, setTags, setAnyTag} = useSearch();
|
||||
|
||||
const localOnChange = (tagNames) => {
|
||||
setActiveTags(tagNames);
|
||||
const localOnChange = (tagNames, newAnyTag) => {
|
||||
if (newAnyTag) {
|
||||
setAnyTag(true);
|
||||
} else {
|
||||
setTags(tagNames);
|
||||
}
|
||||
if (onChange) {
|
||||
onChange(tagNames);
|
||||
onChange(tagNames, newAnyTag);
|
||||
}
|
||||
}
|
||||
|
||||
return <TagsSelector hideGroup={true}
|
||||
hideEdit={true}
|
||||
active={activeTags && activeTags.length > 0}
|
||||
showAny={showAny}
|
||||
active={anyTag || activeTags && activeTags.length > 0}
|
||||
selectedTagNames={activeTags}
|
||||
onToggle={localOnChange}
|
||||
anyTag={anyTag}
|
||||
onChange={localOnChange}
|
||||
style={{marginLeft: '0.3em', marginTop: '0.3em'}}
|
||||
/>
|
||||
}
|
||||
|
|
@ -479,14 +488,17 @@ export function FilesSearchView({
|
|||
const {searchFiles, pages} = useSearchFiles(24, emptySearch, model);
|
||||
|
||||
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
|
||||
searchFiles,
|
||||
pages.activePage,
|
||||
pages.totalPages,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
pages.setPage,
|
||||
true,
|
||||
{
|
||||
files: searchFiles,
|
||||
activePage: pages.activePage,
|
||||
totalPages: pages.totalPages,
|
||||
selectElem: null,
|
||||
selectedKeys: null,
|
||||
onSelect: null,
|
||||
setPage: pages.setPage,
|
||||
headlines: true,
|
||||
showAnyTag: true,
|
||||
},
|
||||
);
|
||||
|
||||
return <>
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
|
|||
}
|
||||
|
||||
const setTags = (tags) => {
|
||||
updateQuery({tag: tags});
|
||||
updateQuery({tag: tags, anyTag: null});
|
||||
}
|
||||
|
||||
const addTag = (name) => {
|
||||
|
|
@ -95,24 +95,26 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
|
|||
setTags(newTags);
|
||||
}
|
||||
|
||||
const anyTag = searchParams.get('anyTag') === 'true';
|
||||
const setAnyTag = (value) => {
|
||||
updateQuery({tag: [], anyTag: value ? 'true' : null});
|
||||
}
|
||||
|
||||
return {
|
||||
activeTags,
|
||||
addTag,
|
||||
activeTags, addTag, removeTag, anyTag, setAnyTag, setTags,
|
||||
filter,
|
||||
model: model_,
|
||||
pages,
|
||||
removeTag,
|
||||
searchParams,
|
||||
searchStr,
|
||||
setSearchStr,
|
||||
clearSearch,
|
||||
setTags,
|
||||
months, dateRange, setDateRange, setDates,
|
||||
anySearch, isEmpty,
|
||||
}
|
||||
}
|
||||
|
||||
export function useSuggestions(searchStr, tagNames, filter) {
|
||||
export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
||||
const defaultSuggestions = {
|
||||
fileGroups: [],
|
||||
channels: [],
|
||||
|
|
@ -135,7 +137,7 @@ export function useSuggestions(searchStr, tagNames, filter) {
|
|||
// We can't search Channels/Domains without some string to filter by.
|
||||
sendGeneralReqeust(async () => await searchSuggestions(searchStr));
|
||||
}
|
||||
sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange));
|
||||
sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange, anyTag));
|
||||
sendZimRequest(async () => await searchEstimateZims(searchStr, tagNames));
|
||||
}
|
||||
}, [
|
||||
|
|
@ -146,6 +148,7 @@ export function useSuggestions(searchStr, tagNames, filter) {
|
|||
JSON.stringify(months),
|
||||
JSON.stringify(dateRange),
|
||||
filter,
|
||||
anyTag,
|
||||
]);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
|
@ -180,14 +183,14 @@ export function useSuggestions(searchStr, tagNames, filter) {
|
|||
}
|
||||
|
||||
|
||||
export function useSearchSuggestions(defaultSearchStr, defaultTagNames) {
|
||||
export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) {
|
||||
const navigate = useNavigate();
|
||||
const {filter} = useSearchFilter();
|
||||
const [searchStr, setSearchStr] = React.useState(defaultSearchStr || '');
|
||||
const [searchTags, setSearchTags] = React.useState(defaultTagNames);
|
||||
const {SingleTag, fuzzyMatchTagsByName} = React.useContext(TagsContext);
|
||||
const {dateRange, months, setDates, clearDate} = useSearchDate();
|
||||
const {suggestions, loading} = useSuggestions(searchStr, searchTags, filter);
|
||||
const {suggestions, loading} = useSuggestions(searchStr, searchTags, filter, anyTag);
|
||||
const {getLocationStr} = React.useContext(QueryContext);
|
||||
|
||||
// The results that will be displayed by <Search>.
|
||||
|
|
@ -239,6 +242,8 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames) {
|
|||
return {type: 'channel', title: i['name'], id: i['id'], location: `/videos/channel/${i.id}/video`}
|
||||
})
|
||||
}
|
||||
} else if (newSuggestions.channels && newSuggestions.channels.length === 0) {
|
||||
results.channels = {name: 'Channels', results: noResults};
|
||||
}
|
||||
if (newSuggestions.domains && newSuggestions.domains.length > 0) {
|
||||
results.domains = {
|
||||
|
|
@ -339,7 +344,7 @@ export function SearchView({suggestions, suggestionsSums, loading}) {
|
|||
const zimsTabName = <span>Zims <Label>{normalizeEstimate(suggestionsSums?.zims)}</Label></span>;
|
||||
|
||||
const links = [
|
||||
{text: filesTabName, to: '/search', key: 'filesSearch', end: true},
|
||||
{text: filesTabName, to: '/search', key: 'filesSearch_', end: true},
|
||||
{text: zimsTabName, to: '/search/zim', key: 'zimsSearch'},
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import {
|
|||
CardDescription,
|
||||
CardHeader,
|
||||
Container,
|
||||
Dimmer,
|
||||
Image,
|
||||
PlaceholderHeader,
|
||||
PlaceholderLine,
|
||||
|
|
@ -74,7 +75,7 @@ function VideosPage() {
|
|||
searchOrder = defaultSearchOrder;
|
||||
}
|
||||
|
||||
const {searchStr, setSearchStr, videos, activePage, setPage, totalPages, fetchVideos} =
|
||||
const {searchStr, setSearchStr, videos, activePage, setPage, totalPages, fetchVideos, loading} =
|
||||
useSearchVideos(null, channelId, searchOrder);
|
||||
|
||||
const {channel} = useChannel(channelId);
|
||||
|
|
@ -165,14 +166,17 @@ function VideosPage() {
|
|||
</div>;
|
||||
|
||||
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
|
||||
videos,
|
||||
activePage,
|
||||
totalPages,
|
||||
selectElm,
|
||||
selectedVideos,
|
||||
onSelect,
|
||||
setPage,
|
||||
!!searchStr,
|
||||
{
|
||||
files: videos,
|
||||
activePage: activePage,
|
||||
totalPages: totalPages,
|
||||
selectElem: selectElm,
|
||||
selectedKeys: selectedVideos,
|
||||
onSelect: onSelect,
|
||||
setPage: setPage,
|
||||
headlines: !!searchStr,
|
||||
loading: loading,
|
||||
},
|
||||
);
|
||||
|
||||
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr || '');
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ export const ZimSearchView = ({suggestions, loading}) => {
|
|||
}
|
||||
|
||||
return <>
|
||||
<TagsQuerySelector onChange={setTags}/>
|
||||
<TagsQuerySelector onChange={(i, j) => setTags(i)}/>
|
||||
<Accordion>
|
||||
{body}
|
||||
</Accordion>
|
||||
|
|
@ -533,7 +533,7 @@ class ManageZim extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
function ZimViewer({src = ZIM_VIEWER_URI, style=null}) {
|
||||
function ZimViewer({src = ZIM_VIEWER_URI, style = null}) {
|
||||
const fallback = <Segment>
|
||||
<Header as='h3'>Failed to fetch Zim service.</Header>
|
||||
<p>You may need to give permission to access the page: <a href={src}>{src}</a></p>
|
||||
|
|
|
|||
|
|
@ -324,20 +324,25 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
|
|||
const activeTags = searchParams.getAll('tag');
|
||||
const {view} = useSearchView();
|
||||
const headline = view === 'headline';
|
||||
const anyTag = searchParams.get('anyTag') === 'true';
|
||||
|
||||
const [videos, setVideos] = useState(null);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const localSearchVideos = async () => {
|
||||
setVideos(null);
|
||||
setLoading(true);
|
||||
setTotalPages(0);
|
||||
try {
|
||||
let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline);
|
||||
let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline, anyTag);
|
||||
setVideos(videos_);
|
||||
setTotalPages(calculateTotalPages(total, limit));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setVideos(undefined);// Could not get Videos, display error.
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -368,6 +373,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
|
|||
setOrderBy,
|
||||
fetchVideos: localSearchVideos,
|
||||
activeTags,
|
||||
loading,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -481,7 +487,7 @@ export const useChannels = () => {
|
|||
|
||||
export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) => {
|
||||
const {
|
||||
activeTags,
|
||||
activeTags, anyTag,
|
||||
pages,
|
||||
searchStr,
|
||||
filter,
|
||||
|
|
@ -493,6 +499,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
const {view} = useSearchView();
|
||||
|
||||
const [searchFiles, setSearchFiles] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const headline = view === 'headline';
|
||||
|
||||
const localSearchFiles = async () => {
|
||||
|
|
@ -507,11 +514,12 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
fromDate = dateRange[0];
|
||||
toDate = dateRange[1];
|
||||
}
|
||||
setLoading(true);
|
||||
console.log('localSearchFiles', fromDate, toDate, months);
|
||||
try {
|
||||
let [file_groups, total] = await filesSearch(
|
||||
pages.offset, pages.limit, searchStr, mimetypes, model || model_, activeTags, headline,
|
||||
months, fromDate, toDate);
|
||||
months, fromDate, toDate, anyTag);
|
||||
setSearchFiles(file_groups);
|
||||
pages.setTotal(total);
|
||||
} catch (e) {
|
||||
|
|
@ -523,6 +531,8 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
description: 'Could not get files',
|
||||
time: 5000,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -533,6 +543,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
|
||||
useEffect(() => {
|
||||
if (searchStr || (activeTags && activeTags.length > 0)) {
|
||||
setLoading(true);
|
||||
debouncedLocalSearchFiles();
|
||||
}
|
||||
// Handle when this is unmounted.
|
||||
|
|
@ -547,6 +558,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
headline,
|
||||
JSON.stringify(months),
|
||||
JSON.stringify(dateRange),
|
||||
anyTag,
|
||||
]);
|
||||
|
||||
return {
|
||||
|
|
@ -555,7 +567,8 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
filter,
|
||||
setSearchStr,
|
||||
pages,
|
||||
activeTags
|
||||
activeTags,
|
||||
loading,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1106,15 +1119,7 @@ export const useUploadFile = () => {
|
|||
doUpload()
|
||||
}, [JSON.stringify(files)]);
|
||||
|
||||
const handleAddTag = (tagName) => {
|
||||
setTagNames([...tagNames, tagName]);
|
||||
}
|
||||
|
||||
const handleUntag = (tagName) => {
|
||||
setTagNames(tagNames.filter(i => i !== tagName));
|
||||
}
|
||||
|
||||
const tagsSelector = <TagsSelector selectedTagNames={tagNames} onAdd={handleAddTag} onRemove={handleUntag}/>;
|
||||
const tagsSelector = <TagsSelector selectedTagNames={tagNames} onChange={(i,) => setTagNames(i)}/>;
|
||||
|
||||
return {
|
||||
destination,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue