Skip to content

Commit 22060e7

Browse files
committed
fetch similar posts and not only the score
1 parent 0cedd8f commit 22060e7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/Similar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<span class="title">Similar: </span>
55
<ul class="list" v-if="story.similar && story.similar.length !== 0">
66
<li v-for="sim in story.similar" :key="sim.id">
7-
<span class="box" v-bind:style="{ background: getColor(sim.score)}" v-bind:title="sim.score"></span>
8-
<router-link :to="'/item/' + sim.id">{{ sim.text }}</router-link>
7+
<span class="box" v-bind:style="{ background: getColor(sim.similarity_score)}" v-bind:title="sim.similarity_score"></span>
8+
<router-link :to="'/item/' + sim.id">{{ sim.title }} | <b>{{ new Date(sim.time * 1000).getFullYear() }}</b> | {{ sim.descendants }} comments</router-link>
99
</li>
1010
</ul>
1111
<div v-else class="no-posts">

src/store/actions.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ export default {
4545
item.similar = similar[idx];
4646
return item;
4747
}))
48+
// Start fetching similar posts (potential performance issue...)
49+
.then((items) => {
50+
return fetchItems(items.map(i => i.similar).flat().map(sim => sim.id))
51+
.then(similarItems => {
52+
items.forEach(item => {
53+
item.similar = item.similar.map(sim => {
54+
const simItem = similarItems.find(si => si.id === sim.id);
55+
return Object.assign({ similarity_score: sim.score }, simItem);
56+
});
57+
});
58+
return items;
59+
});
60+
});
61+
// Stop fetching similar posts (potential performance issue...)
4862
}
4963
return items;
5064
})

0 commit comments

Comments
 (0)