All files / app/containers Files.tsx

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                  2x   2x 2x 2x 2x 2x   2x 2x   2x                                                      
import React, { Component } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { debug } from 'app/utilities/logger';
 
import { selectPath, setOpenSidePanelGroup } from 'app/actions';
import { CollapsibleSidePanelGroups } from 'app/actions/ActionTypes';
import {
  getFilesContainerSort,
  getOpenSidePanelGroup,
} from 'app/selectors/stateVars';
import { getFilteredFilesForFilesContainer } from 'app/selectors/files';
 
import FilesActionMenu from './FilesActionMenu';
import { FileCard } from 'app/components/FileCard';
import { CollapsibleGroup } from 'app/components/CollapsibleGroup';
import { ExtendingList } from 'app/components/ExtendingList';
 
const COLLAPSIBLE_GROUP = CollapsibleSidePanelGroups.FILES;
 
export const Files: React.FC = (): React.ReactElement => {
  const filesContainerSort = useSelector(getFilesContainerSort);
  const files = useSelector(getFilteredFilesForFilesContainer);
  const openGroup = useSelector(getOpenSidePanelGroup);
  const dispatch = useDispatch();
 
  const title = `${files.length} Files`;
  const isOpen = openGroup === COLLAPSIBLE_GROUP;
 
  return (
    <CollapsibleGroup
      title={title}
      isOpen={isOpen}
      onOpenToggle={handleOpenGroupToggle}
    >
      <FilesActionMenu />
      <ExtendingList rowCount={files.length} rowRenderer={renderRow} />
    </CollapsibleGroup>
  );
 
  function handleOpenGroupToggle() {
    if (!isOpen) {
      dispatch(setOpenSidePanelGroup(COLLAPSIBLE_GROUP));
    }
  }
 
  function renderRow(index: number, key: string) {
    const file = files[index];
    return <FileCard key={key} file={file} onFileClick={onFileClick} />;
  }
 
  function onFileClick(event, fileName) {
    event.stopPropagation();
    dispatch(selectPath(fileName));
  }
};