Call api within the component itself & linting.

This commit is contained in:
2021-02-18 23:59:39 +01:00
parent 9e25b374e0
commit 6b33e03aae

View File

@@ -2,18 +2,18 @@
<div v-if="wines.length > 0" class="wines-main-container"> <div v-if="wines.length > 0" class="wines-main-container">
<div class="info-and-link"> <div class="info-and-link">
<h3> <h3>
Topp 5 viner Topp viner
</h3> </h3>
<router-link to="viner"> <router-link to="viner">
<span class="vin-link">Se alle viner </span> <span class="vin-link">Se alle viner </span>
</router-link> </router-link>
</div> </div>
<div class="wine-container"> <div class="wines-container">
<Wine v-for="wine in wines" :key="wine" :wine="wine"> <Wine v-for="wine in wines" :key="wine" :wine="wine">
<template v-slot:top> <template v-slot:top>
<div class="flex justify-end"> <div class="flex justify-end">
<div class="requested-count cursor-pointer"> <div class="requested-count cursor-pointer">
<span> {{ wine.occurences }} </span> <span> {{ wine.occurences }} </span>
<i class="icon icon--heart" /> <i class="icon icon--heart" />
</div> </div>
</div> </div>
@@ -35,15 +35,20 @@ export default {
return { return {
wines: [], wines: [],
clickedWine: null, clickedWine: null,
limit: 18
}; };
}, },
async mounted() { async mounted() {
let response = await overallWineStatistics(); this.getAllWines();
},
methods: {
getAllWines() {
return fetch(`/api/wines?limit=${this.limit}`)
.then(resp => resp.json())
.then(response => {
let { wines, success } = response;
response.sort(); this.wines = wines.sort(
response = response
.filter(wine => wine.name != null && wine.name != "")
.sort(
this.predicate( this.predicate(
{ {
name: "occurences", name: "occurences",
@@ -55,9 +60,8 @@ export default {
} }
) )
); );
this.wines = response.slice(0, 5); });
}, },
methods: {
predicate: function() { predicate: function() {
var fields = [], var fields = [],
n_fields = arguments.length, n_fields = arguments.length,
@@ -125,7 +129,7 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
@import "@/styles/variables.scss"; @import "@/styles/variables.scss";
@import "@/styles/global.scss"; @import "@/styles/global.scss";
@import "../styles/media-queries.scss"; @import "@/styles/media-queries.scss";
.wines-main-container { .wines-main-container {
margin-bottom: 10em; margin-bottom: 10em;