mirror of
https://github.com/davegallant/rfd-fyi.git
synced 2025-08-07 09:02:27 +00:00
Add scores
This commit is contained in:
@@ -91,12 +91,20 @@ func (a *App) listTopics(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (a *App) refreshTopics() {
|
||||
latestTopics := a.getDeals(9, 1, 4)
|
||||
// TODO: only drop deals if a timer has been met
|
||||
latestTopics = a.updateScores(latestTopics)
|
||||
log.Debug().Msg("Refreshing topics")
|
||||
a.CurrentTopics = latestTopics
|
||||
a.LastRefresh = time.Now()
|
||||
}
|
||||
|
||||
func (a *App) updateScores(t []Topic) []Topic {
|
||||
for i := range t {
|
||||
t[i].Score = t[i].Votes.Up - t[i].Votes.Down
|
||||
log.Debug().Msgf("Added score: %d", t[i].Score)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
|
||||
|
||||
var t []Topic
|
||||
|
@@ -14,7 +14,7 @@ type Topic struct {
|
||||
PostTime string `json:"post_time"`
|
||||
LastPostTime string `json:"last_post_time"`
|
||||
Votes Votes
|
||||
Score string `json:",omitempty"`
|
||||
Score int `json:"score"`
|
||||
} // @name Topic
|
||||
|
||||
type Votes struct {
|
||||
|
@@ -12,9 +12,8 @@
|
||||
<thead class="thead thead-light text-muted">
|
||||
<tr>
|
||||
<th scope="col">Deal</th>
|
||||
<th scope="col">Score</th>
|
||||
<th scope="col">Views</th>
|
||||
<!-- TODO:score -->
|
||||
<!-- <th scope="col">Score</th> -->
|
||||
<th scope="col">Last Post</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -39,9 +38,8 @@
|
||||
v-html="highlightMatches(topic.title)"
|
||||
></a>
|
||||
</td>
|
||||
<td scope="col">{{ topic.score }}</td>
|
||||
<td scope="col">{{ topic.total_views }}</td>
|
||||
<!-- <td scope="col">{{ topic.score }}</td> -->
|
||||
<!-- <td scope="col">{{ topic.votes.up - topic.votes.down }}</td> -->
|
||||
<td scope="col">{{ formatDate(topic.last_post_time) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@@ -13,3 +13,4 @@ createApp(App)
|
||||
config: { id: "G-YF11ZH9SYD" },
|
||||
})
|
||||
.mount("#app");
|
||||
|
||||
|
Reference in New Issue
Block a user