Skip to content

Commit

Permalink
#48 Chore/sorting cryptopunks (#52)
Browse files Browse the repository at this point in the history
* add timestamp sorting

* add timestamp sorting to cryptopunks

* remove timestamp, sortby tenancydates

* fix ordering to desc

* format code

* timestamp sorting fix & add date to be shown

Co-authored-by: nazariyv <[email protected]>
  • Loading branch information
eenagy and nazariyv authored May 3, 2021
1 parent f77f131 commit cc32083
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
18 changes: 14 additions & 4 deletions components/punk-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ export default function Punk({ punk, setModalOpen }) {
<p className="cols-1 pointer-events-none">
<span className="flex items-start justify-start flex-col">
<span className="font-semibold">
{monthNames[startDate.getMonth()]}
{startDate.getDate()} {monthNames[startDate.getMonth()]}
</span>
<span className="text-xl font-bold">
{startDate.getFullYear()}
</span>
<span className="font-medium text-left text-xs lg:text-base" style={{ minWidth: '4rem' }}>{formatAMPM(startDate)}</span>
<span
className="font-medium text-left text-xs lg:text-base"
style={{ minWidth: '4rem' }}
>
{formatAMPM(startDate)}
</span>
</span>
</p>
<p className="cols-1 flex justify-center items-center pointer-events-none">
Expand All @@ -95,12 +100,17 @@ export default function Punk({ punk, setModalOpen }) {
<p className="cols-1 pointer-events-none">
<span className="flex items-end justify-end flex-col">
<span className="font-semibold">
{monthNames[endDate.getMonth()]}
{endDate.getDate()} {monthNames[endDate.getMonth()]}
</span>
<span className="text-xl font-bold">
{endDate.getFullYear()}
</span>
<span className="font-medium text-xs lg:text-base text-right" style={{ minWidth: '4rem' }}>{formatAMPM(endDate)}</span>
<span
className="font-medium text-xs lg:text-base text-right"
style={{ minWidth: '4rem' }}
>
{formatAMPM(endDate)}
</span>
</span>
</p>
</div>
Expand Down
13 changes: 8 additions & 5 deletions contexts/punk.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import blockies from 'ethereum-blockies';
import { request } from 'graphql-request';
import { ethers } from 'ethers';

import { parsePackedRentData } from '../utils';
import { parsePackedRentData, sortByTimestamp } from '../utils';
import {
queryAllPunks,
queryProvenancyOfPunk,
Expand Down Expand Up @@ -133,7 +133,7 @@ export function PunkProvider({ children }) {
queryProvenancyOfPunk(punk.punkID),
'issue fetching punk"s provenance'
).then((result) => {
if (result) return result.map(mapToPunk);
if (result) return result.sort(sortByTimestamp).map(mapToPunk);
return [];
});
}, []);
Expand Down Expand Up @@ -171,10 +171,13 @@ export function PunkProvider({ children }) {
// TODO: only pulls this once. add a poller
getProvenances(queryAllPunks, 'issue fetching all punks').then((result) => {
if (result) {
setAllGiftedPunks(result.filter(filterNonZeroTenant).map(mapToPunk));
const sortedResult = result.sort(sortByTimestamp);
setAllGiftedPunks(
sortedResult.filter(filterNonZeroTenant).map(mapToPunk)
);
// todo: create punks and then filter. that way we will not perform
// todo: the end computation twice
setGiftedPunks(result.filter(filterCurrentPunk).map(mapToPunk));
setGiftedPunks(sortedResult.filter(filterCurrentPunk).map(mapToPunk));
}
});

Expand Down Expand Up @@ -221,7 +224,7 @@ export function PunkProvider({ children }) {
);
}

PunkContext.propTypes = {
PunkProvider.propTypes = {
children: PropTypes.node,
};

Expand Down
1 change: 1 addition & 0 deletions generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@ export class Provenance extends Entity {
set tenancyDates(value: string) {
this.set("tenancyDates", Value.fromString(value));
}

}
7 changes: 7 additions & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ export const formatAMPM = (date) => {
const strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
};

export function sortByTimestamp(a, b, asc = false) {
if (asc) {
return a.tenancyDates.start - b.tenancyDates.start;
}
return b.tenancyDates.start - a.tenancyDates.start;
}

1 comment on commit cc32083

@vercel
Copy link

@vercel vercel bot commented on cc32083 May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.