forked from vuejs/vue-hackernews-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add star ranking to similar items (#2)
- Loading branch information
1 parent
35f210b
commit 8e6935a
Showing
4 changed files
with
108 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist/ | ||
.vscode/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,105 @@ | ||
|
||
<template> | ||
<div class="similar-posts"> | ||
<span class="title">Similar: </span> | ||
<span class="title">Similar:</span> | ||
<ul class="list" v-if="story.similar && story.similar.length !== 0"> | ||
<li v-for="sim in story.similar" :key="sim.id"> | ||
<span class="box" v-bind:style="{ background: getColor(sim.similarity_score)}" v-bind:title="sim.similarity_score"></span> | ||
<router-link :to="'/item/' + sim.id">{{ sim.title }} | <b>{{ new Date(sim.time * 1000).getFullYear() }}</b> | {{ sim.descendants }} comments</router-link> | ||
<li v-for="sim in story.similar" :key="sim.id"> | ||
<span | ||
class="box" | ||
v-bind:style="{ background: getColor(sim.similarity_score)}" | ||
v-bind:title="sim.similarity_score" | ||
></span> | ||
<router-link :to="'/item/' + sim.id"> | ||
{{ sim.title }} | | ||
<b>{{ new Date(sim.time * 1000).getFullYear() }}</b> | ||
| {{ sim.descendants }} comments | | ||
</router-link> | ||
<client-only> | ||
<div> | ||
<star-rating | ||
v-bind:star-size="15" | ||
active-color="#000000" | ||
v-bind:show-rating="false" | ||
@rating-selected="setRating($event, sim.title, story.title)" | ||
v-bind:inline="true" | ||
></star-rating> | ||
</div> | ||
</client-only> | ||
</li> | ||
</ul> | ||
<div v-else class="no-posts"> | ||
<span class="title">No similar posts found.</span> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
import StarRating from "vue-star-rating"; | ||
import ClientOnly from "vue-client-only"; | ||
import sendFeedBack from "../api"; | ||
export default { | ||
name: 'similar-posts', | ||
props: ['story'], | ||
name: "similar-posts", | ||
props: ["story"], | ||
components: { | ||
StarRating, | ||
ClientOnly | ||
}, | ||
data: () => { | ||
return { | ||
colorStops: [ | ||
{ start: 0, stop: 0.7, color: 'rgba(250, 157, 18, 0.5)' }, | ||
{ start: 0.7, stop: 0.8, color: 'rgba(250, 157, 18, 0.75)' }, | ||
{ start: 0.8, stop: 2, color: 'rgba(250, 157, 18, 1)' } | ||
{ start: 0, stop: 0.7, color: "rgba(250, 157, 18, 0.5)" }, | ||
{ start: 0.7, stop: 0.8, color: "rgba(250, 157, 18, 0.75)" }, | ||
{ start: 0.8, stop: 2, color: "rgba(250, 157, 18, 1)" } | ||
] | ||
}; | ||
}, | ||
methods: { | ||
getColor: function(score) { | ||
const found = this.colorStops.find(cs => score.toFixed(2) >= cs.start && score.toFixed(2) < cs.stop); | ||
const found = this.colorStops.find( | ||
cs => score.toFixed(2) >= cs.start && score.toFixed(2) < cs.stop | ||
); | ||
return found.color; | ||
}, | ||
setRating: function(rating, similar, story) { | ||
sendFeedBack(story, similar, rating); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="stylus"> | ||
.similar-posts | ||
line-height 1.2 | ||
.similar-posts { | ||
line-height: 1.2; | ||
.box { | ||
width: 12px; | ||
height: 0.85em; | ||
display: inline-block; | ||
margin-right: 8px; | ||
} | ||
.box | ||
width: 12px | ||
height: .85em | ||
display: inline-block | ||
margin-right: 8px | ||
.title { | ||
font-size: 0.85em; | ||
} | ||
ul.list, .no-posts { | ||
background-color: #f3f3f3; | ||
font-size: 0.85em; | ||
margin: 4px 0; | ||
padding: 8px 12px; | ||
border-radius: 4px; | ||
.title | ||
font-size .85em | ||
ul.list, .no-posts | ||
background-color #f3f3f3 | ||
font-size .85em | ||
margin 4px 0 | ||
padding 8px 12px | ||
border-radius 4px | ||
li | ||
padding: 4px | ||
display: flex | ||
align-items: center | ||
a | ||
color: #828282; | ||
li { | ||
padding: 4px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
} | ||
a { | ||
color: #828282; | ||
} | ||
} | ||
</style> |