// @flow import React from 'react'; import CollectionPreviewTile from 'component/collectionPreviewTile'; import ClaimList from 'component/claimList'; import Button from 'component/button'; import * as COLLECTIONS_CONSTS from 'constants/collections'; import Icon from 'component/common/icon'; import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import * as KEYCODES from 'constants/keycodes'; import Yrbl from 'component/yrbl'; import classnames from 'classnames'; import { FormField, Form } from 'component/common/form'; type Props = { builtinCollections: CollectionGroup, publishedCollections: CollectionGroup, unpublishedCollections: CollectionGroup, // savedCollections: CollectionGroup, fetchingCollections: boolean, }; const ALL = 'All'; const PRIVATE = 'Private'; const PUBLIC = 'Public'; const COLLECTION_FILTERS = [ALL, PRIVATE, PUBLIC]; export default function CollectionsListMine(props: Props) { const { builtinCollections, publishedCollections, unpublishedCollections, // savedCollections, these are resolved on startup from sync'd claimIds or urls fetchingCollections, } = props; const builtinCollectionsList = (Object.values(builtinCollections || {}): any); const unpublishedCollectionsList = (Object.keys(unpublishedCollections || {}): any); const publishedList = (Object.keys(publishedCollections || {}): any); const hasCollections = unpublishedCollectionsList.length || publishedList.length; const [filterType, setFilterType] = React.useState(ALL); const [searchText, setSearchText] = React.useState(''); let collectionsToShow = []; if (filterType === ALL) { collectionsToShow = unpublishedCollectionsList.concat(publishedList); } else if (filterType === PRIVATE) { collectionsToShow = unpublishedCollectionsList; } else if (filterType === PUBLIC) { collectionsToShow = publishedList; } let filteredCollections; if (searchText && collectionsToShow) { filteredCollections = collectionsToShow.filter((id) => { return ( (unpublishedCollections[id] && unpublishedCollections[id].name.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())) || (publishedCollections[id] && publishedCollections[id].name.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())) ); }); } else { filteredCollections = collectionsToShow || []; } const watchLater = builtinCollectionsList.find((list) => list.id === COLLECTIONS_CONSTS.WATCH_LATER_ID); const favorites = builtinCollectionsList.find((list) => list.id === COLLECTIONS_CONSTS.FAVORITES_ID); const builtin = [watchLater, favorites]; function escapeListener(e: SyntheticKeyboardEvent<*>) { if (e.keyCode === KEYCODES.ESCAPE) { e.preventDefault(); setSearchText(''); } } function onTextareaFocus() { window.addEventListener('keydown', escapeListener); } function onTextareaBlur() { window.removeEventListener('keydown', escapeListener); } return ( <> {builtin.map((list: Collection) => { const { items: itemUrls } = list; return (
<> {Boolean(itemUrls && itemUrls.length) && ( <>

)} {!(itemUrls && itemUrls.length) && (

{__(`${list.name}`)}
{__('(Empty) --[indicates empty playlist]--')}

)}
); })}

{__('Playlists')} {!hasCollections && !fetchingCollections && (
{__('(Empty) --[indicates empty playlist]--')}
)} {!hasCollections && fetchingCollections && (
{__('(Empty) --[indicates empty playlist]--')}
)}

{COLLECTION_FILTERS.map((value) => (
{}} className="wunderbar--inline"> setSearchText(e.target.value)} type="text" placeholder={__('Search')} />
{Boolean(hasCollections) && (
{/* TODO: fix above spacing hack */}
{filteredCollections && filteredCollections.length > 0 && filteredCollections.map((key) => )} {!filteredCollections.length &&
{__('No matching playlists')}
}
)} {!hasCollections && !fetchingCollections && (
)} {!hasCollections && fetchingCollections && (

{__('Loading...')}

)}
); }