import React from 'react';
import PropTypes from 'prop-types';
import RepoListView from './repo-list-view';
import RecentlyUsedListView from './recently-used-list-view';
import { gettext } from '../../utils/constants';
import SearchedListView from './searched-list-view';
import { SearchStatus } from './searcher';
import Loading from '../loading';
export const MODE_TYPE_MAP = {
CURRENT_AND_OTHER_REPOS: 'current_repo_and_other_repos',
ONLY_CURRENT_LIBRARY: 'only_current_library',
ONLY_ALL_REPOS: 'only_all_repos',
ONLY_OTHER_LIBRARIES: 'only_other_libraries',
RECENTLY_USED: 'recently_used',
SEARCH_RESULTS: 'search_results',
};
const RepoListWrapper = (props) => {
const {
mode, isShowFile, fileSuffixes, currentPath, isCurrentRepoShow, currentRepoInfo, selectedRepo,
selectedPath, isOtherRepoShow, selectedItemInfo, repoList,
searchStatus, searchResults, onSearchedItemClick, onSearchedItemDoubleClick, selectedSearchedRepo, newFolderName
} = props;
const renderRecentlyUsed = () => {
const recentlyUsedList = JSON.parse(localStorage.getItem('recently-used-list')) || [];
return (
);
};
const onScroll = (event) => {
event.stopPropagation();
};
const renderSearchResults = () => {
switch (searchStatus) {
case SearchStatus.LOADING:
return ;
case SearchStatus.RESULTS:
return (
<>
{searchResults.length === 0 ? (
{gettext('No results matching')}
) : (
)}
>
);
default:
return null;
}
};
return (
{mode === MODE_TYPE_MAP.CURRENT_AND_OTHER_REPOS && (
<>
{gettext('Current Library')}
{(isCurrentRepoShow && currentRepoInfo) &&
}
{gettext('Other Libraries')}
{isOtherRepoShow &&
}
>
)}
{mode === MODE_TYPE_MAP.ONLY_CURRENT_LIBRARY && (
)}
{mode === MODE_TYPE_MAP.ONLY_ALL_REPOS && (
)}
{mode === MODE_TYPE_MAP.ONLY_OTHER_LIBRARIES && (
)}
{mode === MODE_TYPE_MAP.RECENTLY_USED && renderRecentlyUsed()}
{mode === MODE_TYPE_MAP.SEARCH_RESULTS && (
{renderSearchResults()}
)}
);
};
RepoListWrapper.propTypes = {
mode: PropTypes.string,
currentPath: PropTypes.string,
isShowFile: PropTypes.bool,
fileSuffixes: PropTypes.array,
selectedItemInfo: PropTypes.object,
currentRepoInfo: PropTypes.object,
selectedRepo: PropTypes.object,
isCurrentRepoShow: PropTypes.bool,
isOtherRepoShow: PropTypes.bool,
selectedPath: PropTypes.string,
repoList: PropTypes.array,
onCurrentRepoToggle: PropTypes.func,
onOtherRepoToggle: PropTypes.func,
handleClickRepo: PropTypes.func,
handleClickDirent: PropTypes.func,
searchStatus: PropTypes.string,
searchResults: PropTypes.array,
onSearchedItemClick: PropTypes.func,
onSearchedItemDoubleClick: PropTypes.func,
selectedSearchedRepo: PropTypes.object,
newFolderName: PropTypes.string,
};
RepoListWrapper.defaultProps = {
isShowFile: false,
fileSuffixes: [],
};
export default RepoListWrapper;