Api call from component itself and linting.

This commit is contained in:
2021-02-18 21:17:22 +01:00
parent 72c1896747
commit 2cf4095b97

View File

@@ -2,10 +2,9 @@
<div class="container"> <div class="container">
<h1 class="">Alle viner</h1> <h1 class="">Alle viner</h1>
<div id="wines-container"> <div class="wines-container">
<Wine :wine="wine" v-for="(wine, _, index) in wines" :key="wine._id"> <Wine :wine="wine" v-for="(wine, _, index) in wines" :key="wine._id">
<div class="winners-container"> <div class="winners-container">
<span class="label">Vinnende lodd:</span> <span class="label">Vinnende lodd:</span>
<div class="flex row"> <div class="flex row">
<span class="raffle-element blue-raffle">{{ wine.blue == null ? 0 : wine.blue }}</span> <span class="raffle-element blue-raffle">{{ wine.blue == null ? 0 : wine.blue }}</span>
@@ -20,42 +19,43 @@
<li v-for="(winner, index) in wine.winners"> <li v-for="(winner, index) in wine.winners">
<router-link class="vin-link" :to="`/highscore/` + winner">{{ winner }}</router-link> <router-link class="vin-link" :to="`/highscore/` + winner">{{ winner }}</router-link>
-&nbsp; -&nbsp;
<router-link class="vin-link" :to="winDateUrl(wine.dates[index])">{{ dateString(wine.dates[index]) }}</router-link> <router-link class="vin-link" :to="winDateUrl(wine.dates[index])">{{
dateString(wine.dates[index])
}}</router-link>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
</Wine> </Wine>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Banner from "@/ui/Banner";
import Wine from "@/ui/Wine"; import Wine from "@/ui/Wine";
import { overallWineStatistics } from "@/api";
import { dateString } from "@/utils"; import { dateString } from "@/utils";
export default { export default {
components: { components: { Wine },
Banner,
Wine
},
data() { data() {
return { return {
wines: [] wines: []
}; };
}, },
mounted() {
this.overallWineStatistics();
},
methods: { methods: {
winDateUrl(date) { winDateUrl(date) {
const timestamp = new Date(date).getTime(); const timestamp = new Date(date).getTime();
return `/history/${timestamp}` return `/history/${timestamp}`;
},
overallWineStatistics() {
return fetch("/api/wines")
.then(resp => resp.json())
.then(response => (this.wines = response.wines));
}, },
dateString: dateString dateString: dateString
},
async mounted() {
this.wines = await overallWineStatistics();
} }
}; };
</script> </script>
@@ -84,18 +84,6 @@ h1 {
font-weight: 600; font-weight: 600;
} }
#wines-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
grid-gap: 2rem;
> div {
justify-content: flex-start;
margin-bottom: 2rem;
}
}
.name-wins { .name-wins {
display: flex; display: flex;
flex-direction: column; flex-direction: column;