Skip to content

Commit

Permalink
Add simple statistics view
Browse files Browse the repository at this point in the history
  • Loading branch information
pasikonik committed Nov 10, 2023
1 parent ad68773 commit 04a3171
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/stores/stat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import api from '@/lib/api'
import { defineStore } from 'pinia'

export const useStatStore = defineStore('stat', {
state: () => {
return {
allWords: 0,
knownWords: 0,
}
},
getters: {
getAllWords: (state) => state.allWords,
getKnownWords: (state) => state.knownWords,
},
actions: {
async fetchStats() {
const stats = await api.get('stats')
this.allWords = stats.all
this.knownWords = stats.known
}
}
})
29 changes: 28 additions & 1 deletion src/views/Stats.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
<script setup lang="ts">
import { useStatStore } from '@/stores/stat'
import { storeToRefs } from 'pinia';
const statStore = useStatStore()
statStore.fetchStats()
const { getAllWords, getKnownWords } = storeToRefs(statStore)
</script>

<template>
<h2>Stats</h2>
<div class="container mx-auto mt-16">

<div class="text-center">
<v-icon size="small" icon="mdi-poll"/>
<h2 class="text-h4 mb-5">
Statistics
</h2>
</div>


<div>You have <b>{{ getAllWords }}</b> words in your library</div>

<div>You have learned <b>{{ getKnownWords }}</b> words</div>
</div>
</template>

<style scoped lang="scss">
.container {
width: 450px;
padding: 3em;
border: $light-border;
}
</style>

0 comments on commit 04a3171

Please sign in to comment.