Skip to content

Commit c74eb02

Browse files
committed
Fix initial for empty data
1 parent 02d5f27 commit c74eb02

File tree

7 files changed

+64
-18
lines changed

7 files changed

+64
-18
lines changed

src/components/ByDays.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<img height="55" src="../assets/icons/preloader.gif" />
44
</div>
55
<div v-else>
6-
<div class="no-data" v-if="countOfDays == undefined || countOfDays == 0">No data</div>
6+
<div class="no-data" v-if="countOfDays == undefined || (countOfDays == 0 && !noData)">
7+
No data
8+
</div>
9+
<div v-else-if="noData">
10+
<div class="no-data">No data for selected period</div>
11+
</div>
712
<div v-else>
813
<div class="stats-block block">
914
<div class="header">Average time on selected days</div>
@@ -46,13 +51,18 @@ import { convertSummaryTimeToString } from '../utils/converter';
4651
4752
const tabsByDays = ref<TabListByDays>();
4853
const isLoading = ref<boolean>();
54+
const noData = ref<boolean>();
4955
5056
const countOfDays = computed(() =>
5157
tabsByDays.value != undefined ? tabsByDays.value.days.length : 0,
5258
);
5359
5460
async function loadList() {
55-
tabsByDays.value = await useTabListByDays(new Date('06/03/2023'), new Date('06/14/2023'));
61+
const tabList = await useTabListByDays(new Date('06/03/2023'), new Date('06/14/2023'));
62+
if (tabList != null) {
63+
tabsByDays.value = tabList;
64+
if (tabList.days.length == 0 && tabList.summaryTime == 0) noData.value = true;
65+
}
5666
isLoading.value = false;
5767
}
5868

src/components/TabList.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ async function loadList(sortingBy: SortingBy) {
8383
if (props.type == TypeOfList.Today) tabSummary = await useTodayTabListSummary(sortingBy);
8484
if (props.type == TypeOfList.All) {
8585
tabSummary = await useAllTabListSummary(sortingBy);
86-
firstDay.value = tabSummary.firstDay;
87-
countOfActiveDays.value = tabSummary.activeDaysTotal;
88-
dataForOvarallStats.value = tabSummary;
86+
87+
if (tabSummary != null) {
88+
firstDay.value = tabSummary.firstDay;
89+
countOfActiveDays.value = tabSummary.activeDaysTotal;
90+
dataForOvarallStats.value = tabSummary;
91+
}
8992
}
9093
9194
if (tabSummary != null) {

src/compositions/all-tab-list-summary.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { SortingBy } from '../utils/enums';
55
import { daysBetween } from '../utils/time';
66
import { todayLocalDate } from '../utils/today';
77

8-
export async function useAllTabListSummary(sortingBy: SortingBy): Promise<OverallStats> {
8+
export async function useAllTabListSummary(sortingBy: SortingBy): Promise<OverallStats | null> {
99
const repo = await injectTabsRepository();
1010
const unSortedTabs = repo.getTabs();
1111
let tabs: Tab[] = [];
1212

13-
const todayTabs = unSortedTabs.filter(x => x.days.find(s => s.date === todayLocalDate()));
13+
if (unSortedTabs.length == 0) return null;
14+
const todayTabs = unSortedTabs?.filter(x => x.days.find(s => s.date === todayLocalDate()));
1415

1516
const summaryTimeListForToday = todayTabs.map(function (tab) {
1617
return tab.days.find(day => day.date === todayLocalDate())!.summary;
@@ -82,8 +83,10 @@ export async function useAllTabListSummary(sortingBy: SortingBy): Promise<Overal
8283
averageTimeByActiveDays: averageTimeByActiveDays,
8384
mostActiveDay: mostDay.mostActiveDayObj,
8485
mostInactiveDay: mostDay.mostInactiveDayObj,
85-
mostActiveDayExceptToday: mostDayExceptToday.mostActiveDayObjExceptToday,
86-
mostInactiveDayExceptToday: mostDayExceptToday.mostInactiveDayObjExceptToday,
86+
mostActiveDayExceptToday:
87+
mostDayExceptToday != null ? mostDayExceptToday.mostActiveDayObjExceptToday : null,
88+
mostInactiveDayExceptToday:
89+
mostDayExceptToday != null ? mostDayExceptToday.mostInactiveDayObjExceptToday : null,
8790
tabs: tabs,
8891
summaryTime: summaryTime,
8992
chart: {
@@ -111,6 +114,7 @@ function fillMostListWithoutToday(days: TabDay[]) {
111114
return a.summary - b.summary;
112115
});
113116

117+
if (sortedByTimeDaysWithoutToday.length == 0) return null;
114118
const mostActiveDayExceptToday = sortedByTimeDaysWithoutToday[0];
115119
const mostActiveDayObjExceptToday = fillMostDay(mostActiveDayExceptToday);
116120

src/compositions/tab-list-by-days.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ import { CurrentTabItem } from '../dto/currentTabItem';
22
import { DayTabs, TabListByDays } from '../dto/tabListSummary';
33
import { injectTabsRepository } from '../repository/inject-tabs-repository';
44

5-
export async function useTabListByDays(dateFrom: Date, dateTo: Date): Promise<TabListByDays> {
5+
export async function useTabListByDays(
6+
dateFrom: Date,
7+
dateTo: Date,
8+
): Promise<TabListByDays | null> {
69
const repo = await injectTabsRepository();
710
const unSortedTabs = repo.getTabs();
811
let daysTabs: DayTabs[] = [];
912

13+
if (unSortedTabs.length == 0) return null;
14+
1015
const unSortedTabsByDays = unSortedTabs.filter(
1116
x => x.days.find(s => new Date(s.date) >= dateFrom && new Date(s.date) <= dateTo) != undefined,
1217
);
1318

19+
if (unSortedTabsByDays.length == 0)
20+
return {
21+
days: [],
22+
averageTime: 0,
23+
summaryTime: 0,
24+
};
25+
1426
unSortedTabsByDays.forEach(tab => {
1527
tab.days.forEach(day => {
1628
if (new Date(day.date) >= dateFrom && new Date(day.date) <= dateTo) {

src/compositions/today-tab-list-summary.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { injectTabsRepository } from '../repository/inject-tabs-repository';
44
import { SortingBy } from '../utils/enums';
55
import { todayLocalDate } from '../utils/today';
66

7-
export async function useTodayTabListSummary(sortingBy: SortingBy): Promise<TabListSummary> {
7+
export async function useTodayTabListSummary(sortingBy: SortingBy): Promise<TabListSummary | null> {
88
const repo = await injectTabsRepository();
99
const unSortedTabs = repo.getTodayTabs();
1010
let tabs: Tab[] = [];
1111

12+
if (unSortedTabs.length == 0) return null;
13+
1214
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
1315
return sortingBy == SortingBy.UsageTime
1416
? b.days.find(s => s.date === todayLocalDate())!.summary -

src/dto/tabListSummary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export interface OverallStats extends TabListSummary {
99
averageTimeByActiveDays: number;
1010
mostActiveDay: ActiveDay;
1111
mostInactiveDay: ActiveDay;
12-
mostActiveDayExceptToday: ActiveDay;
13-
mostInactiveDayExceptToday: ActiveDay;
12+
mostActiveDayExceptToday: ActiveDay | null;
13+
mostInactiveDayExceptToday: ActiveDay | null;
1414
}
1515

1616
export interface ActiveDay {

src/pages/Settings.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@
173173

174174
<script lang="ts" setup>
175175
import { watchEffect, onMounted, ref } from 'vue';
176-
import { StorageParams } from '../storage/storage-params';
176+
import {
177+
BLOCK_DEFERRAL_DEFAULT,
178+
DARK_MODE_DEFAULT,
179+
INTERVAL_INACTIVITY_DEFAULT,
180+
StorageParams,
181+
VIEW_TIME_IN_BADGE_DEFAULT,
182+
} from '../storage/storage-params';
177183
import { injecStorage } from '../storage/inject-storage';
178184
import { InactivityInterval } from '../storage/storage-params';
179185
@@ -185,10 +191,19 @@ const allowDeferringBlock = ref<boolean>();
185191
const darkMode = ref<boolean>();
186192
187193
onMounted(async () => {
188-
viewTimeInBadge.value = await settingsStorage.getValue(StorageParams.VIEW_TIME_IN_BADGE);
189-
intervalInactivity.value = await settingsStorage.getValue(StorageParams.INTERVAL_INACTIVITY);
190-
darkMode.value = await settingsStorage.getValue(StorageParams.DARK_MODE);
191-
allowDeferringBlock.value = await settingsStorage.getValue(StorageParams.BLOCK_DEFERRAL);
194+
viewTimeInBadge.value = await settingsStorage.getValue(
195+
StorageParams.VIEW_TIME_IN_BADGE,
196+
VIEW_TIME_IN_BADGE_DEFAULT,
197+
);
198+
intervalInactivity.value = await settingsStorage.getValue(
199+
StorageParams.INTERVAL_INACTIVITY,
200+
INTERVAL_INACTIVITY_DEFAULT,
201+
);
202+
darkMode.value = await settingsStorage.getValue(StorageParams.DARK_MODE, DARK_MODE_DEFAULT);
203+
allowDeferringBlock.value = await settingsStorage.getValue(
204+
StorageParams.BLOCK_DEFERRAL,
205+
BLOCK_DEFERRAL_DEFAULT,
206+
);
192207
});
193208
194209
watchEffect(() => save(StorageParams.VIEW_TIME_IN_BADGE, viewTimeInBadge.value));

0 commit comments

Comments
 (0)