Skip to content

Commit

Permalink
Add fallback to the graph, ipfs if publisher is not available and sor…
Browse files Browse the repository at this point in the history
…t annotation by date
  • Loading branch information
jo-es committed Aug 3, 2020
1 parent e0a9622 commit 1b0a8d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/Components/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ const Reader = ({ setPage }) => {
useEffect(() => {
(async () => {
const { tweetId, tweetAuthor } = getTweetData()
// const annotationCIDs = await getAnnotationCIDsByReference({ reference: tweetId });
// const annotations = [];
// for (const annotationCID of annotationCIDs) {
// annotations.push(new Annotation({ payload: await getAnnotationData(annotationCID) }));
// }
const annotations = [];
const annotationsFromPublisher = await getAnnotationsByReference({ reference: tweetId });
for (const annotation of annotationsFromPublisher) {
annotations.push(new Annotation({ payload: annotation }));
try {
const annotations = [];
const annotationsFromPublisher = await getAnnotationsByReference({ reference: tweetId });
for (const annotation of annotationsFromPublisher) {
annotations.push(new Annotation({ payload: annotation }));
}
annotations.sort((a, b) => (new Date(a.getDate()) - new Date(b.getDate())));
setTweetAnnotations(annotations);
} catch (error) {
// fallback to the graph and ipfs
const annotationCIDs = await getAnnotationCIDsByReference({ reference: tweetId });
const annotations = [];
for (const annotationCID of annotationCIDs) {
annotations.push(new Annotation({ payload: await getAnnotationData(annotationCID) }));
}
annotations.sort((a, b) => (new Date(a.getDate()) - new Date(b.getDate())));
setTweetAnnotations(annotations);
}
setTweetAnnotations(annotations);
})();
}, [])

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Annotation {
}

getShortDate() {
return new Date(this.payload.issuanceDate).toLocaleDateString()
return (new Date(this.payload.issuanceDate).toLocaleTimeString() + ', ' + new Date(this.payload.issuanceDate).toLocaleDateString())
}
}

Expand Down

0 comments on commit 1b0a8d4

Please sign in to comment.