Headlines can be displayed for file search results.

This commit is contained in:
Roland 2023-04-12 18:09:10 -06:00
parent f33dc31111
commit 29e562c520
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
7 changed files with 145 additions and 10 deletions

View file

@ -438,6 +438,7 @@ function Archives() {
selectedArchives,
onSelect,
setPage,
!!searchStr,
);
const searchInput = <SearchInput clearable

View file

@ -54,6 +54,7 @@ import {FileBrowser} from "./FileBrowser";
import {refreshDirectoryFiles, refreshFiles} from "../api";
import {useSubscribeEventName} from "../Events";
import {TagsSelector} from "../Tags";
import {Headlines} from "./Headline";
function EbookCard({file}) {
const {s} = useContext(ThemeContext);
@ -264,9 +265,20 @@ export function FileRowTagIcon({file}) {
}
}
export function SearchViewButton() {
export function SearchViewButton({headlines}) {
const {view, setView} = useSearchView();
if (headlines) {
// Cycle: cards -> headline -> list
if (view === 'headline') {
return <Button icon='list' onClick={() => setView('list')}/>;
} else if (view === 'list') {
return <Button icon='th' onClick={() => setView('cards')}/>;
}
return <Button icon='searchengin' onClick={() => setView('headline')}/>;
}
// Cycle: cards -> list
if (view === 'list') {
return <Button icon='th' onClick={() => setView('cards')}/>;
}
@ -295,6 +307,7 @@ export function FilesView(
selectedKeys,
onSelect,
setPage,
headlines = false,
limitOptions = [12, 24, 48, 96],
) {
const {view} = useSearchView();
@ -328,11 +341,13 @@ export function FilesView(
footer={footer}
selectedKeys={selectedKeys || []}
/>;
} else if (view === 'headline') {
body = <Headlines results={files}/>;
} else {
body = <FileCards files={files}/>;
}
const viewButton = <SearchViewButton/>
const viewButton = <SearchViewButton headlines={headlines}/>
const limitDropdown = <SearchLimitDropdown limits={limitOptions}/>;
const tagQuerySelector = <TagsQuerySelector/>;
@ -446,6 +461,10 @@ export function FilesSearchView({
activePage,
totalPages,
setPage,
null,
null,
null,
true,
);
return <>

View file

@ -0,0 +1,92 @@
import {CardIcon, Header, Placeholder, Segment} from "./Theme";
import {PlaceholderLine, Item, Image} from "semantic-ui-react";
import React from "react";
import {ThemeContext} from "../contexts/contexts";
import {encodeMediaPath, FileIcon, findPosterPath, isoDatetimeToString, PreviewLink} from "./Common";
import {Link} from "react-router-dom";
import _ from "lodash";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
const HeadlineParagraph = ({headline}) => {
const {s} = React.useContext(ThemeContext);
if (headline) {
headline = headline.replaceAll('<b>', '<b><u>');
headline = headline.replaceAll('</b>', '</b></u>');
headline = headline.replaceAll('\n', '<br/>');
return <p {...s} dangerouslySetInnerHTML={{__html: headline}}></p>
}
}
const FileHeadline = ({file, to}) => {
const {title_headline, b_headline, c_headline, d_headline} = file;
let poster;
const posterPath = findPosterPath(file);
if (posterPath) {
const posterUrl = posterPath ? `/media/${encodeMediaPath(posterPath)}` : null;
poster = <Image src={posterUrl} size='tiny'/>;
} else {
poster = <FileIcon file={file}/>;
}
let header = <PreviewLink file={file}><HeadlineParagraph headline={title_headline}/></PreviewLink>;
if (to) {
header = <Link to={to}><HeadlineParagraph headline={title_headline}/></Link>
}
let body = <p>No highlights</p>
if (b_headline || c_headline || d_headline) {
body = <>
<HeadlineParagraph headline={b_headline}/>
<HeadlineParagraph headline={c_headline}/>
<HeadlineParagraph headline={d_headline}/>
</>;
}
return <Segment>
<Grid>
<Grid.Row>
<Grid.Column mobile={4} computer={2}>{poster}</Grid.Column>
<Grid.Column mobile={12} computer={12}>
<span style={{fontSize: '1.25em'}}>{header}</span>
</Grid.Column>
</Grid.Row>
</Grid>
<br/>
{body}
</Segment>
}
export const Headlines = ({results}) => {
if (results === null || results === undefined) {
return <Placeholder>
<PlaceholderLine/>
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>
} else if (results && results.length === 0) {
return <Segment>No results!</Segment>
}
let items = [];
for (let i = 0; i < results.length; i++) {
const result = results[i];
const {model, data, video} = result;
if (model === 'video' && !_.isEmpty(video)) {
let video_url = `/videos/video/${video.id}`;
const channel = video.channel ? video.channel : null;
if (channel) {
video_url = `/videos/channel/${channel.id}/video/${video.id}`;
}
items = [...items, <FileHeadline key={result['key']} file={result} to={video_url}/>];
} else if (model === 'archive' && !_.isEmpty(data)) {
items = [...items, <FileHeadline key={result['key']} file={result} to={`/archive/${data.id}`}/>];
} else {
items = [...items, <FileHeadline key={result['key']} file={result}/>];
}
}
return <>
{items}
</>
}

View file

@ -176,6 +176,7 @@ function VideosPage() {
selectedVideos,
onSelect,
setPage,
!!searchStr,
);
const searchInput = <SearchInput clearable