From 932a954b7327c603d68c96bc45b931abc9ec080e Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 28 Nov 2018 19:38:47 +0800 Subject: [PATCH] also fetch reputation of visited hashtags --- src/redux/app-reducers.html | 8 ++++++++ src/redux/app-selectors.html | 1 + src/redux/sagas/hashtag-saga.html | 4 +++- src/redux/sagas/hashtagList-saga.html | 13 ++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/redux/app-reducers.html b/src/redux/app-reducers.html index 7cf58918..8cfad2eb 100644 --- a/src/redux/app-reducers.html +++ b/src/redux/app-reducers.html @@ -40,6 +40,7 @@ }, balance: {}, hashtagList: [], + visitedHashtags: {}, fetching: {}, hashtags: {}, current: {}, @@ -313,6 +314,13 @@ } } } + case 'ADD_VISITED_HASHTAG': { + return deepmerge(state, { + visitedHashtags: { + [action.hashtag.hashtagAddress]: action.hashtag + } + }) + } default: { return state } diff --git a/src/redux/app-selectors.html b/src/redux/app-selectors.html index f2a40896..adf300ae 100644 --- a/src/redux/app-selectors.html +++ b/src/redux/app-selectors.html @@ -55,6 +55,7 @@ }, confirmedTx: (state) => state.confirmedTx, hashtagList: (state) => state.hashtagList, + visitedHashtags: (state) => state.visitedHashtags, address: (state) => state.publicKey, username: (state) => state.username, language: (state) => state.language, diff --git a/src/redux/sagas/hashtag-saga.html b/src/redux/sagas/hashtag-saga.html index aa8457bc..a7bce255 100644 --- a/src/redux/sagas/hashtag-saga.html +++ b/src/redux/sagas/hashtag-saga.html @@ -78,7 +78,8 @@ hashtagMetadataHash: await hashtagContract.methods.hashtagMetadataHash().call(), hashtagFee: parseInt(await hashtagContract.methods.hashtagFee().call()), deployBlock: deployBlock || 8149489, - address: hashtagContract._address + address: hashtagContract._address, + hashtagAddress: hashtagContract._address } } @@ -157,6 +158,7 @@ // - deployBlock() -> deployBlock const hashtagContractData = yield call(getHashtagContractData, hashtagContract) yield put({ type: 'UPDATE_NEWHASHTAG', hashtagAddress, data: hashtagContractData }); + yield put({ type: 'ADD_VISITED_HASHTAG', hashtag: hashtagContractData }) // Step 2A. Resolve hashtagMetadata with IPFS // - ipfs.cat(hashtagMetadata) -> description diff --git a/src/redux/sagas/hashtagList-saga.html b/src/redux/sagas/hashtagList-saga.html index 2d61742b..3596b7f5 100644 --- a/src/redux/sagas/hashtagList-saga.html +++ b/src/redux/sagas/hashtagList-saga.html @@ -56,7 +56,18 @@ if (!hashtagList.length) { hashtagList = yield call(getHashtagList) } - const reputationsObj = yield call(getReputationFromHashtags, hashtagList, address) + + // Append the visited hashtags and remove duplicates + // visitedHashtags is an object + const visitedHashtags = yield select(selectors.visitedHashtags) + const uniqueHashtags = visitedHashtags + hashtagList.forEach(hashtag => { + uniqueHashtags[hashtag.hashtagAddress] = hashtag + }) + const uniqueHashtagList = Object.values(uniqueHashtags) + + // Get reputation for all hashtags in the list + const reputationsObj = yield call(getReputationFromHashtags, uniqueHashtagList, address) yield put({ type: 'UPDATE_REPUTATION', address, reputationsObj }); } catch (e) { console.error(`Error fetching user's reputation`, e)