Skip to content

Commit

Permalink
#15 Auto refresh page when user authorized with pocket or resynced #15
Browse files Browse the repository at this point in the history
… (#18)

- Changed how tags stats look like, small fixes
 - Autorefresh stats components when sync was made
  • Loading branch information
michmzr committed Jun 8, 2023
1 parent 40780f9 commit 059652b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
18 changes: 11 additions & 7 deletions src/frontend/src/components/DailyStatsChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<script lang="ts">
import {Options, Vue} from "vue-class-component";
import {useSessionStore} from "@/store";
import {useSessionStore, useSyncStore} from "@/store";
import {StatsService} from "@/services/stats-service";
import {DayStatsType, IDayStat} from "@/models/stats-models";
import Datepicker from 'vue3-datepicker'
Expand Down Expand Up @@ -62,6 +62,7 @@ export default class DailyStatsChart extends Vue {
authorized: Boolean = false
sessionStore = useSessionStore()
syncStore = useSyncStore()
statsService = new StatsService()
formDayStart: Date = subDays(new Date(), 7)
Expand All @@ -72,15 +73,15 @@ export default class DailyStatsChart extends Vue {
datasets: [
{
label: 'Read items in day',
backgroundColor: '#f87979',
borderColor: '#f87979',
backgroundColor: '#0a4687',
borderColor: '#0a4687',
data: [] as number[],
yAxisID: 'y',
},
{
label: 'Added items in day',
backgroundColor: '#0a4687',
borderColor: '#0a4687',
backgroundColor: '#f87979',
borderColor: '#f87979',
data: [] as number[],
yAxisID: 'y1',
}
Expand Down Expand Up @@ -116,12 +117,15 @@ export default class DailyStatsChart extends Vue {
}
mounted() {
this.onChangedDatePeriod();
this.isAuthorized()
this.sessionStore.$subscribe((mutation, state) => {
this.authorized = state.authorized
});
this.syncStore.$subscribe(() => {
console.debug(`Got sync store change - reloading component data`)
this.onChangedDatePeriod()
})
}
clearChart() {
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/components/LangStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<script lang="ts">
import {Options, Vue} from "vue-class-component";
import {useSessionStore} from "@/store";
import {useSessionStore, useSyncStore} from "@/store";
import {Pie} from "vue-chartjs";
import {ILangStats} from "@/models/stats-models";
import {StatsService} from "@/services/stats-service";
Expand All @@ -26,6 +26,7 @@ ChartJS.register(ArcElement, Tooltip, Legend)
export default class LangStats extends Vue {
authorized: Boolean = false;
sessionStore = useSessionStore();
syncStore = useSyncStore()
loadedData: boolean = false;
Expand Down Expand Up @@ -60,7 +61,10 @@ export default class LangStats extends Vue {
this.authorized = state.authorized;
});
this.loadData();
this.syncStore.$subscribe(() => {
console.debug(`Got sync store change - reloading component data`)
this.loadData()
})
}
loadData() {
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/components/StatsPerPeriod.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<script lang="ts">
import {Vue} from "vue-class-component";
import {useSessionStore} from "@/store";
import {useSessionStore, useSyncStore} from "@/store";
import {StatsService} from "@/services/stats-service";
import {ItemsStatsAggregated, ItemsStatsPerPeriod, TimePeriod} from "@/models/stats-models";
import {format, parseISO} from "date-fns";
Expand All @@ -42,6 +42,7 @@ export default class StatsPerPeriod extends Vue {
sessionStore = useSessionStore()
statsService = new StatsService()
syncStore = useSyncStore()
itemsStats: ItemsStatsPerPeriod[] = [];
Expand All @@ -58,7 +59,10 @@ export default class StatsPerPeriod extends Vue {
this.authorized = state.authorized
})
this.loadStats()
this.syncStore.$subscribe(() => {
console.debug(`Got sync store change - reloading component data`)
this.loadStats()
})
}
displayPeriod(period: TimePeriod): String {
Expand Down
31 changes: 12 additions & 19 deletions src/frontend/src/components/TopTags.vue
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
<template>
<div class="card" v-if="authorized">
<div class="card-body" v-if="loadedData">
<div v-if="authorized" class="card">
<div v-if="loadedData" class="card-body">
<h5 class="card-title">Top {{ limitTags }} the most popular tags.</h5>
<table class="table">
<thead>
<tr>
<th scope="col">Tag name</th>
<th scope="col">Occurs</th>
</tr>
</thead>
<tbody>
<tr v-for="item in topTags" v-bind:key="item.name">
<td>{{ item.name }}</td>
<td>{{ item.count }}</td>
</tr>
</tbody>
</table>
<span v-for="item in topTags" v-bind:key="item.name" class="badge ">
<b-badge variant="dark">{{ item.name }} <b-badge variant="light">{{ item.count }}</b-badge></b-badge>
</span>
</div>
</div>
</template>

<script lang="ts">
import {Vue} from "vue-class-component";
import {useSessionStore} from "@/store";
import {useSessionStore, useSyncStore} from "@/store";
import {StatsService} from "@/services/stats-service";
import {ITopTag, ITopTags} from "@/models/stats-models";
export default class TopTags extends Vue {
limitTags: number = 10
limitTags: number = 30
authorized: Boolean = false
loadedData: boolean = false
sessionStore = useSessionStore()
statsService = new StatsService()
syncStore = useSyncStore()
topTags: ITopTag[] = [] as ITopTag[]
Expand All @@ -50,7 +40,10 @@ export default class TopTags extends Vue {
this.authorized = state.authorized;
});
this.loadTopTags();
this.syncStore.$subscribe(() => {
console.debug(`Got sync store change - reloading component data`)
this.loadTopTags()
})
}
loadTopTags() {
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import router from "@/router";
import {createPinia} from "pinia";
import {BootstrapVue3, BToastPlugin} from "bootstrap-vue-3";

// Import Bootstrap and BootstrapVue CSS files (order is important)
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'

import {FontAwesomeIcon} from "@fortawesome/vue-fontawesome";
import {library} from "@fortawesome/fontawesome-svg-core";
import {faSpinner, faUser} from "@fortawesome/free-solid-svg-icons";

//font awesome
library.add(faSpinner, faUser);

const app = createApp(App)
const pinia = createPinia()

// @ts-ignore
app
.use(pinia)
.use(VueAxios, axios)
Expand All @@ -27,3 +28,4 @@ app
.use(BToastPlugin)
.component("font-awesome-icon", FontAwesomeIcon)
.mount('#app')

6 changes: 1 addition & 5 deletions src/main/docker/mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ services:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
volumes:
# # seeding scripts
- ./mongo-entrypoint:/docker-entrypoint-initdb.d
# named volumes
# - mongodb:/data/db
# - mongoconfig:/data/configdb
- ./mongo-entrypoint:/docker-entrypoint-initdb.d

0 comments on commit 059652b

Please sign in to comment.