-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[READY] Search Page - Add new list view #1498
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
import { MsearchMultisearchBody } from '@elastic/elasticsearch/lib/api/types'; | ||
import { BasicSearch } from 'components/basic-search'; | ||
import { ContentList } from 'components/content-list'; | ||
import { PageSection } from 'components/section'; | ||
import { Sentiment } from 'components/sentiment'; | ||
import { ContentListActionBar } from 'components/tool-bar'; | ||
import { useElastic } from 'features/my-searches/hooks'; | ||
import { IContentSearchResult } from 'features/utils/interfaces'; | ||
import React from 'react'; | ||
import { FaPlay, FaStop } from 'react-icons/fa'; | ||
import { FaBookmark } from 'react-icons/fa6'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { useParams } from 'react-router-dom'; | ||
import { toast } from 'react-toastify'; | ||
import { useContent, useFilters, useLookup } from 'store/hooks'; | ||
import { useProfileStore } from 'store/slices'; | ||
import { | ||
Checkbox, | ||
Col, | ||
ContentTypeName, | ||
IContentModel, | ||
Loading, | ||
Row, | ||
Settings, | ||
Show, | ||
} from 'tno-core'; | ||
import { Col, IContentModel, Loading, Row, Show } from 'tno-core'; | ||
|
||
import { AdvancedSearch } from './components'; | ||
import { Player } from './player/Player'; | ||
import * as styled from './styled'; | ||
import { filterFormat, formatDate } from './utils'; | ||
import { filterFormat } from './utils'; | ||
|
||
export interface ISearchType { | ||
showAdvanced?: boolean; | ||
|
@@ -40,47 +30,18 @@ export const SearchPage: React.FC<ISearchType> = ({ showAdvanced }) => { | |
}, | ||
{ findContentWithElasticsearch, storeSearchFilter }, | ||
] = useContent(); | ||
const navigate = useNavigate(); | ||
const [{ frontPageImagesMediaTypeId, settings, isReady }] = useLookup(); | ||
const [{ frontPageImagesMediaTypeId }] = useLookup(); | ||
const genQuery = useElastic(); | ||
const [, { getFilter }] = useFilters(); | ||
const [{ filter: activeFilter }, { storeFilter }] = useProfileStore(); | ||
|
||
const [content, setContent] = React.useState<IContentModel[]>([]); | ||
const [activeContent, setActiveContent] = React.useState<IContentModel | null>(null); | ||
const [playerOpen, setPlayerOpen] = React.useState<boolean>(false); | ||
const [content, setContent] = React.useState<IContentSearchResult[]>([]); | ||
const [selected, setSelected] = React.useState<IContentModel[]>([]); | ||
const [isLoading, setIsLoading] = React.useState(false); | ||
const [showPage, setShowPage] = React.useState<string[]>([]); | ||
const [showNewWindow, setShowNewWindow] = React.useState<string[]>([]); | ||
const [hideSource, setHideSource] = React.useState<string[]>([]); | ||
const [init, setInit] = React.useState(true); // React hooks are horrible... | ||
|
||
const filterId = id ? parseInt(id) : 0; | ||
|
||
React.useEffect(() => { | ||
if (isReady) { | ||
const showPageIds = settings.find( | ||
(s) => s.name === Settings.SearchPageResultsShowPage, | ||
)?.value; | ||
if (showPageIds) { | ||
setShowPage(showPageIds.split(',')); | ||
} | ||
const showNewWindowIds = settings.find( | ||
(s) => s.name === Settings.SearchPageResultsNewWindow, | ||
)?.value; | ||
if (showNewWindowIds) { | ||
setShowNewWindow(showNewWindowIds.split(',')); | ||
} | ||
const hideSourceIds = settings.find( | ||
(s) => s.name === Settings.SearchPageResultsHideSource, | ||
)?.value; | ||
if (hideSourceIds) { | ||
setHideSource(hideSourceIds.split(',')); | ||
} | ||
} | ||
}, [isReady, settings]); | ||
|
||
React.useEffect(() => { | ||
// Fetch the active filter if required. | ||
if (filterId && init && activeFilter?.id !== filterId) { | ||
|
@@ -114,6 +75,10 @@ export const SearchPage: React.FC<ISearchType> = ({ showAdvanced }) => { | |
[findContentWithElasticsearch], | ||
); | ||
|
||
const handleContentSelected = React.useCallback((content: IContentModel[]) => { | ||
setSelected(content); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
// Need to wait until front page images are in redux store before making a request. | ||
if (frontPageImagesMediaTypeId) { | ||
|
@@ -158,117 +123,23 @@ export const SearchPage: React.FC<ISearchType> = ({ showAdvanced }) => { | |
className="search" | ||
/> | ||
<Show visible={!!activeFilter}> | ||
<div className="viewed-name padding-left"> | ||
<div className="viewed-name "> | ||
<FaBookmark /> | ||
<div className="filter-name">{activeFilter?.name}</div> | ||
</div> | ||
</Show> | ||
<Row className="search-contents"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All this covered in |
||
<div className={playerOpen ? 'scroll minimized' : 'scroll'}> | ||
<Col className={'search-items'}> | ||
<Show visible={!content.length}> | ||
<Row className="helper-text" justifyContent="center"> | ||
Please refine search criteria and click "search". | ||
</Row> | ||
</Show> | ||
|
||
{content.map((item) => { | ||
return ( | ||
<Row | ||
key={item.id} | ||
className="rows" | ||
onClick={() => navigate(`/view/${item.id}`)} | ||
> | ||
<Col className="cols"> | ||
<Row> | ||
<Col | ||
className="checkBoxColumn" | ||
alignItems="center" | ||
onClick={(e) => e.stopPropagation()} | ||
> | ||
<Checkbox | ||
onChange={(e) => { | ||
if (e.target.checked) { | ||
setSelected([...selected, item]); | ||
} else { | ||
setSelected(selected.filter((i) => i.id !== item.id)); | ||
} | ||
}} | ||
className="checkbox" | ||
checked={selected.some((i) => i.id === item.id)} | ||
/> | ||
</Col> | ||
<Col className="sentimentColumn"> | ||
<Sentiment | ||
value={item.tonePools?.length ? item.tonePools[0].value : 0} | ||
/> | ||
</Col> | ||
<Col className="dateColumn col-date"> | ||
<div className="date">{formatDate(item.publishedOn)}</div> | ||
</Col> | ||
<Col className="sourceColumn"> | ||
{item.contentType === ContentTypeName.AudioVideo && | ||
!hideSource.includes(`${item.mediaTypeId}`) | ||
? item.series?.name | ||
: item.source?.name} | ||
</Col> | ||
<Col className="headlineColumn"> | ||
<div className="headline">{item.headline}</div> | ||
</Col> | ||
{showPage.includes(`${item.mediaTypeId}`) && ( | ||
<Col className="linkColumn">{item.page}</Col> | ||
)} | ||
{showNewWindow.includes(`${item.mediaTypeId}`) && ( | ||
<Col className="linkColumn"> | ||
<div | ||
className="new-window" | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
window.open(`/view/${item.id}`, '_blank'); | ||
}} | ||
> | ||
new window | ||
</div> | ||
</Col> | ||
)} | ||
<Show visible={!!item.fileReferences?.length}> | ||
<Col className="mediaColumn"> | ||
<button | ||
onClick={() => { | ||
!playerOpen && setPlayerOpen(true); | ||
item.fileReferences && setActiveContent(item); | ||
}} | ||
className={ | ||
playerOpen && activeContent?.id === item.id | ||
? 'playing media-button' | ||
: 'show media-button' | ||
} | ||
> | ||
{playerOpen && activeContent?.id === item.id ? ( | ||
<Row> | ||
<div>NOW PLAYING</div> <FaStop /> | ||
</Row> | ||
) : ( | ||
<Row> | ||
<div>PLAY MEDIA</div> <FaPlay /> | ||
</Row> | ||
)} | ||
</button> | ||
</Col> | ||
</Show> | ||
</Row> | ||
</Col> | ||
</Row> | ||
); | ||
})} | ||
</Col> | ||
</div> | ||
<Show visible={playerOpen}> | ||
<Col className="player"> | ||
<Player setPlayerOpen={setPlayerOpen} content={activeContent} /> | ||
</Col> | ||
</Show> | ||
</Row> | ||
<Show visible={!content.length}> | ||
<Row className="helper-text" justifyContent="center"> | ||
Please refine search criteria and click "search". | ||
</Row> | ||
</Show> | ||
<ContentList | ||
onContentSelected={handleContentSelected} | ||
content={content} | ||
selected={selected} | ||
showDate | ||
styleOnSettings | ||
/> | ||
{isLoading && <Loading />} | ||
</PageSection> | ||
</Col> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented new window, need to re implement show page, currently just shows page number if one exists