Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Added photos sorting logic (#54)
Browse files Browse the repository at this point in the history
* Added photos sorting logic

* quick fix
  • Loading branch information
akshaypithadiya authored Oct 31, 2021
1 parent 80673e4 commit 0f7d4f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/src/pages/Photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
import { gql, useQuery } from '@apollo/client';
import { Grid, GridCell } from '@rmwc/grid';
import { Loading, Error } from '../components';
import { reducePhotos } from '../utils';
import { reducePhotos, sortPhotos } from '../utils';
import '@rmwc/grid/styles';

const GET_MEDIA_ITEMS = gql`
Expand Down Expand Up @@ -56,7 +56,7 @@ const Photos = () => {
</>
) : (
<>
{reducePhotos(data.mediaItems.nodes).map((image) => {
{sortPhotos(reducePhotos(data.mediaItems.nodes)).map((image) => {
return (
<div key={image.createdAt}>
<Grid>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import reducePhotos from './reducePhotos';
import capThings from './capThings';
import sortPhotos from './sortPhotos';

export { reducePhotos, capThings };
export { reducePhotos, capThings, sortPhotos };
12 changes: 12 additions & 0 deletions frontend/src/utils/sortPhotos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import moment from 'moment';

const sortPhotos = (obj) => {
var sortedObj = obj.sort((a, b) => {
if (moment(a.createdAt) > moment(b.createdAt)) return -1;
if (moment(a.createdAt) < moment(b.createdAt)) return 1;
return 0;
});
return sortedObj;
};

export default sortPhotos;

0 comments on commit 0f7d4f4

Please sign in to comment.