From 1b0a8d4043cfb6cb3c39168338fab87f2784a5a1 Mon Sep 17 00:00:00 2001 From: jo-es Date: Mon, 3 Aug 2020 13:28:30 +0200 Subject: [PATCH] Add fallback to the graph, ipfs if publisher is not available and sort annotation by date --- src/Components/Reader.js | 27 +++++++++++++++++---------- src/Models/Annotation.js | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Components/Reader.js b/src/Components/Reader.js index f303207..82b80f7 100644 --- a/src/Components/Reader.js +++ b/src/Components/Reader.js @@ -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); })(); }, []) diff --git a/src/Models/Annotation.js b/src/Models/Annotation.js index 47c4d7a..df1c557 100644 --- a/src/Models/Annotation.js +++ b/src/Models/Annotation.js @@ -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()) } }