|
1 | 1 |
|
2 | 2 | <template>
|
3 | 3 | <div class="similar-posts">
|
4 |
| - <span class="title">Similar: </span> |
| 4 | + <span class="title">Similar:</span> |
5 | 5 | <ul class="list" v-if="story.similar && story.similar.length !== 0">
|
6 |
| - <li v-for="sim in story.similar" :key="sim.id"> |
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> |
| 6 | + <li v-for="sim in story.similar" :key="sim.id"> |
| 7 | + <span |
| 8 | + class="box" |
| 9 | + v-bind:style="{ background: getColor(sim.similarity_score)}" |
| 10 | + v-bind:title="sim.similarity_score" |
| 11 | + ></span> |
| 12 | + <router-link :to="'/item/' + sim.id"> |
| 13 | + {{ sim.title }} | |
| 14 | + <b>{{ new Date(sim.time * 1000).getFullYear() }}</b> |
| 15 | + | {{ sim.descendants }} comments | |
| 16 | + </router-link> |
| 17 | + <client-only> |
| 18 | + <div> |
| 19 | + <star-rating |
| 20 | + v-bind:star-size="15" |
| 21 | + active-color="#000000" |
| 22 | + v-bind:show-rating="false" |
| 23 | + @rating-selected="setRating($event, sim.title, story.title)" |
| 24 | + v-bind:inline="true" |
| 25 | + ></star-rating> |
| 26 | + </div> |
| 27 | + </client-only> |
9 | 28 | </li>
|
10 | 29 | </ul>
|
11 | 30 | <div v-else class="no-posts">
|
12 | 31 | <span class="title">No similar posts found.</span>
|
13 | 32 | </div>
|
14 |
| - |
15 | 33 | </div>
|
16 | 34 | </template>
|
17 | 35 |
|
18 | 36 | <script>
|
| 37 | +import StarRating from "vue-star-rating"; |
| 38 | +import ClientOnly from "vue-client-only"; |
| 39 | +import sendFeedBack from "../api"; |
19 | 40 |
|
20 | 41 | export default {
|
21 |
| - name: 'similar-posts', |
22 |
| - props: ['story'], |
| 42 | + name: "similar-posts", |
| 43 | + props: ["story"], |
| 44 | + components: { |
| 45 | + StarRating, |
| 46 | + ClientOnly |
| 47 | + }, |
23 | 48 | data: () => {
|
24 | 49 | return {
|
25 | 50 | colorStops: [
|
26 |
| - { start: 0, stop: 0.7, color: 'rgba(250, 157, 18, 0.5)' }, |
27 |
| - { start: 0.7, stop: 0.8, color: 'rgba(250, 157, 18, 0.75)' }, |
28 |
| - { start: 0.8, stop: 2, color: 'rgba(250, 157, 18, 1)' } |
| 51 | + { start: 0, stop: 0.7, color: "rgba(250, 157, 18, 0.5)" }, |
| 52 | + { start: 0.7, stop: 0.8, color: "rgba(250, 157, 18, 0.75)" }, |
| 53 | + { start: 0.8, stop: 2, color: "rgba(250, 157, 18, 1)" } |
29 | 54 | ]
|
30 | 55 | };
|
31 | 56 | },
|
32 | 57 | methods: {
|
33 | 58 | getColor: function(score) {
|
34 |
| - const found = this.colorStops.find(cs => score.toFixed(2) >= cs.start && score.toFixed(2) < cs.stop); |
| 59 | + const found = this.colorStops.find( |
| 60 | + cs => score.toFixed(2) >= cs.start && score.toFixed(2) < cs.stop |
| 61 | + ); |
35 | 62 | return found.color;
|
| 63 | + }, |
| 64 | +
|
| 65 | + setRating: function(rating, similar, story) { |
| 66 | + sendFeedBack(story, similar, rating); |
36 | 67 | }
|
37 | 68 | }
|
38 |
| -} |
| 69 | +}; |
39 | 70 | </script>
|
40 | 71 |
|
41 | 72 | <style lang="stylus">
|
42 |
| - .similar-posts |
43 |
| - line-height 1.2 |
| 73 | +.similar-posts { |
| 74 | + line-height: 1.2; |
| 75 | +
|
| 76 | + .box { |
| 77 | + width: 12px; |
| 78 | + height: 0.85em; |
| 79 | + display: inline-block; |
| 80 | + margin-right: 8px; |
| 81 | + } |
44 | 82 |
|
45 |
| - .box |
46 |
| - width: 12px |
47 |
| - height: .85em |
48 |
| - display: inline-block |
49 |
| - margin-right: 8px |
| 83 | + .title { |
| 84 | + font-size: 0.85em; |
| 85 | + } |
| 86 | +
|
| 87 | + ul.list, .no-posts { |
| 88 | + background-color: #f3f3f3; |
| 89 | + font-size: 0.85em; |
| 90 | + margin: 4px 0; |
| 91 | + padding: 8px 12px; |
| 92 | + border-radius: 4px; |
50 | 93 |
|
51 |
| - .title |
52 |
| - font-size .85em |
53 |
| - ul.list, .no-posts |
54 |
| - background-color #f3f3f3 |
55 |
| - font-size .85em |
56 |
| - margin 4px 0 |
57 |
| - padding 8px 12px |
58 |
| - border-radius 4px |
59 |
| - li |
60 |
| - padding: 4px |
61 |
| - display: flex |
62 |
| - align-items: center |
63 |
| - a |
64 |
| - color: #828282; |
| 94 | + li { |
| 95 | + padding: 4px; |
| 96 | + display: flex; |
| 97 | + align-items: center; |
| 98 | + } |
| 99 | + } |
65 | 100 |
|
| 101 | + a { |
| 102 | + color: #828282; |
| 103 | + } |
| 104 | +} |
66 | 105 | </style>
|
0 commit comments