sort collection bar collection summaries

This commit is contained in:
Abhinav 2022-06-03 13:42:42 +05:30
parent ed54ede6d7
commit 594c9ad5df
2 changed files with 23 additions and 13 deletions

View file

@ -1,8 +1,8 @@
import ScrollButton from 'components/Collections/CollectionBar/ScrollButton'; import ScrollButton from 'components/Collections/CollectionBar/ScrollButton';
import React, { useEffect } from 'react'; import React, { useEffect, useMemo } from 'react';
import { Collection, CollectionSummaries } from 'types/collection'; import { Collection, CollectionSummaries } from 'types/collection';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { ALL_SECTION } from 'constants/collection'; import { ALL_SECTION, COLLECTION_SORT_BY } from 'constants/collection';
import { Typography } from '@mui/material'; import { Typography } from '@mui/material';
import { import {
Hider, Hider,
@ -15,6 +15,7 @@ import useComponentScroll, { SCROLL_DIRECTION } from 'hooks/useComponentScroll';
import useWindowSize from 'hooks/useWindowSize'; import useWindowSize from 'hooks/useWindowSize';
import LinkButton from 'components/pages/gallery/LinkButton'; import LinkButton from 'components/pages/gallery/LinkButton';
import { SpaceBetweenFlex } from 'components/Container'; import { SpaceBetweenFlex } from 'components/Container';
import { sortCollectionSummaries } from 'services/collectionService';
interface IProps { interface IProps {
collections: Collection[]; collections: Collection[];
@ -34,7 +35,17 @@ export default function CollectionBar(props: IProps) {
showAllCollections, showAllCollections,
} = props; } = props;
const sortedCollectionSummary = useMemo(
() =>
sortCollectionSummaries(
[...collectionSummaries.values()],
COLLECTION_SORT_BY.UPDATION_TIME_DESCENDING
),
[collectionSummaries]
);
const windowSize = useWindowSize(); const windowSize = useWindowSize();
const { const {
componentRef, componentRef,
scrollComponent, scrollComponent,
@ -90,15 +101,13 @@ export default function CollectionBar(props: IProps) {
onClick={clickHandler(ALL_SECTION)}> onClick={clickHandler(ALL_SECTION)}>
{constants.ALL_SECTION_NAME} {constants.ALL_SECTION_NAME}
</CollectionCardWithActiveIndicator> </CollectionCardWithActiveIndicator>
{collections.map((item) => ( {sortedCollectionSummary.map((item) => (
<CollectionCardWithActiveIndicator <CollectionCardWithActiveIndicator
key={item.id} key={item.attributes.id}
latestFile={ latestFile={item.latestFile}
collectionSummaries.get(item.id)?.latestFile ref={collectionChipsRef[item.attributes.id]}
} active={activeCollection === item.attributes.id}
ref={collectionChipsRef[item.id]} onClick={clickHandler(item.attributes.id)}>
active={activeCollection === item.id}
onClick={clickHandler(item.id)}>
{item.name} {item.name}
</CollectionCardWithActiveIndicator> </CollectionCardWithActiveIndicator>
))} ))}

View file

@ -28,7 +28,8 @@ export default function collectionInfoWithOptions({
<CollectionSectionWrapper> <CollectionSectionWrapper>
<SpaceBetweenFlex> <SpaceBetweenFlex>
<CollectionInfo name={name} fileCount={fileCount} /> <CollectionInfo name={name} fileCount={fileCount} />
{type !== CollectionType.system && ( {type !== CollectionType.system &&
type !== CollectionType.favorites && (
<CollectionOptions {...props} /> <CollectionOptions {...props} />
)} )}
</SpaceBetweenFlex> </SpaceBetweenFlex>