diff --git a/src/components/Suggestions.vue b/src/components/Suggestions.vue index 3c45bc88001b4e2641323b947ccc2890bc1086f3..e682cfd3ef9d144cc245410e3c71959d1fb94abc 100644 --- a/src/components/Suggestions.vue +++ b/src/components/Suggestions.vue @@ -35,6 +35,23 @@ <img v-if="suggestion.avatar" :src="suggestion.avatar" alt="" class="circle"> <a target="_blank" rel="noopener noreferrer" :href="suggestion.url" class="title">{{ suggestion.name }}</a> <p>Score: {{ suggestion.weight }}</p> + <a v-if="retributeProfiles[suggestion.fullId] === undefined" @click="lookup(suggestion.fullId)" class="secondary-content"><i class="material-icons">search</i></a> + <div v-else-if="retributeProfiles[suggestion.fullId]"> + <h6>Donation platforms</h6> + <!-- {{ retributeProfiles[suggestion.fullId] }} --> + <template v-for="mean in retributeProfiles[suggestion.fullId].means"> + <a + :href="mean.url" + :key="mean.id" + target="_blank" + rel="noopener noreferrer" + :class="['waves-effect', 'waves-light', 'btn-small']"> + <span :title="mean.summary">{{ mean.provider }}</span> + </a> + + </template> + </div> + <div v-else>No retribute information found for this account</div> </li> </ul> </div> @@ -44,13 +61,16 @@ <script> import sources from '@/sources' import orderBy from 'lodash/orderBy' +import chunk from 'lodash/chunk' +import axios from 'axios' export default { data () { return { isLoading: false, results: {}, - aggregatedSuggestions: {} + aggregatedSuggestions: this.$store.state.cache.aggregatedSuggestions || {}, + retributeProfiles: this.$store.state.cache.retributeProfiles || {}, } }, computed: { @@ -103,15 +123,58 @@ export default { for(let i = 0; i < keys.length; i++){ await this.results[keys[i]].promise } + await this.lookupAll() this.isLoading = false + }, + async lookupAll () { + const toLookup = this.filteredSuggestions.filter((s) => { + return this.retributeProfiles[s.fullId] === undefined + }) + const chunkSize = 5 + const chunks = chunk(toLookup, chunkSize) + for (let i = 0; i < chunks.length; i++){ + let chunk = chunks[i] + let ids = chunk.map((s) => { + return s.fullId + }) + await this.lookups(ids) + } + + }, + async lookups(ids) { + const tasks = ids.map((i) => { + return this.lookup(i) + }) + for (let i = 0; i < tasks.length; i++){ + await tasks[i] + } + + }, + async lookup (id) { + const client = axios.create({timeout: 5000}) + let url = `http://localhost:8000/api/v1/search/${id}` + try { + const response = await client.get(url) + this.$set(this.retributeProfiles, id, response.data) + } catch { + this.$set(this.retributeProfiles, id, null) + return + } } }, watch: { results: { handler (v) { this.aggregatedSuggestions = this.aggregateSuggestions(v) + this.$store.commit('setRecursiveState', {key: 'cache.aggregatedSuggestions', value: this.aggregatedSuggestions}) }, deep: true, + }, + retributeProfiles: { + handler (v) { + this.$store.commit('setRecursiveState', {key: 'cache.retributeProfiles', value: this.retributeProfiles}) + }, + deep: true } } } diff --git a/src/sources/mastodon.js b/src/sources/mastodon.js index bb91f18b68fdedefeb25599832794833cb7ea6c0..ae128dc10c0c6b60208938b401e1ca8dce5ac21e 100644 --- a/src/sources/mastodon.js +++ b/src/sources/mastodon.js @@ -89,7 +89,7 @@ export default { baseURL: `https://${account.domain}`, headers: {'Authorization': `Bearer ${token}`}, }) - const maxFavorites = 500 + const maxFavorites = 100 let url = '/api/v1/favourites' let handledFavorites = 0 results.progress = 0 diff --git a/src/store.js b/src/store.js index 40d00a7c5d7f8300ab5c3a31d651c618f0f095a1..5f77ddd08c2ab9940a0f88da2ee5ea3f18ad81f3 100644 --- a/src/store.js +++ b/src/store.js @@ -13,7 +13,8 @@ export const storeConfig = { state: { accounts: {}, - sources: {} + sources: {}, + cache: {} }, mutations: { addAccount (state, payload) {