Skip to content

Commit f502408

Browse files
committed
Load data by days
- add datepicker
1 parent 0cca9cb commit f502408

File tree

14 files changed

+102
-21
lines changed

14 files changed

+102
-21
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@kyvg/vue3-notification": "^2.9.1",
14+
"@vuepic/vue-datepicker": "^5.3.0",
1415
"chart.js": "^4.3.0",
1516
"date-fns": "^2.30.0",
1617
"vue": "^3.2.47",

pnpm-lock.yaml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ByDays.vue

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
<div class="no-data">No data for the selected period</div>
1111
</div>
1212
<div v-else>
13+
<div class="date-block">
14+
<VueDatePicker
15+
range
16+
:enable-time-picker="false"
17+
class="date-picker"
18+
v-model="selectedDate"
19+
:preset-ranges="presetRanges"
20+
@update:model-value="handleDate"
21+
>
22+
<template #yearly="{ label, range, presetDateRange }">
23+
<span @click="presetDateRange(range)">{{ label }}</span>
24+
</template></VueDatePicker
25+
>
26+
</div>
1327
<div class="stats-block block">
1428
<div class="header">Average time on selected days</div>
1529
<p>{{ convertSummaryTimeToString(tabsByDays.averageTime) }}</p>
@@ -48,27 +62,41 @@ import Expander from '../components/Expander.vue';
4862
import { TabListByDays } from '../dto/tabListSummary';
4963
import { useTabListByDays } from '../compositions/tab-list-by-days';
5064
import { convertSummaryTimeToString } from '../utils/converter';
65+
import { ranges, ThisWeekRange } from '../utils/date';
5166
5267
const tabsByDays = ref<TabListByDays>();
5368
const isLoading = ref<boolean>();
5469
const noData = ref<boolean>();
70+
const selectedDate = ref<Date[]>();
71+
72+
const presetRanges = ranges();
5573
5674
const countOfDays = computed(() =>
5775
tabsByDays.value != undefined ? tabsByDays.value.days.length : 0,
5876
);
5977
60-
async function loadList() {
61-
const tabList = await useTabListByDays(new Date('06/03/2023'), new Date('06/14/2023'));
78+
async function loadList(dateFrom: Date, dateTo: Date) {
79+
const tabList = await useTabListByDays(dateFrom, dateTo);
6280
if (tabList != null) {
6381
tabsByDays.value = tabList;
6482
if (tabList.days.length == 0 && tabList.summaryTime == 0) noData.value = true;
6583
}
6684
isLoading.value = false;
6785
}
6886
87+
async function handleDate(modelData: Date[]) {
88+
selectedDate.value = modelData;
89+
const dateFrom = selectedDate.value?.[0] as Date;
90+
const dateTo = selectedDate.value?.[1] as Date;
91+
await loadList(dateFrom, dateTo);
92+
}
93+
6994
onMounted(async () => {
7095
isLoading.value = true;
71-
await loadList();
96+
selectedDate.value = ThisWeekRange;
97+
const dateFrom = selectedDate.value?.[0] as Date;
98+
const dateTo = selectedDate.value?.[1] as Date;
99+
await loadList(dateFrom, dateTo);
72100
});
73101
</script>
74102

@@ -95,4 +123,10 @@ onMounted(async () => {
95123
font-size: 13px;
96124
color: rgb(59, 59, 59);
97125
}
126+
.date-block {
127+
margin: 0 20px 0 20px;
128+
}
129+
.date-picker {
130+
width: 250px;
131+
}
98132
</style>

src/components/TabList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { SortingBy, TypeOfList } from '../utils/enums';
4747
import { useTodayTabListSummary } from '../compositions/today-tab-list-summary';
4848
import { useAllTabListSummary } from '../compositions/all-tab-list-summary';
4949
import { CurrentTabItem } from '../dto/currentTabItem';
50-
import { todayLocalDate } from '../utils/today';
50+
import { todayLocalDate } from '../utils/date';
5151
import { OverallStats } from '../dto/tabListSummary';
5252
5353
const props = defineProps<{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Tab, TabDay } from '../entity/tab';
33
import { injectTabsRepository } from '../repository/inject-tabs-repository';
44
import { SortingBy } from '../utils/enums';
55
import { daysBetween } from '../utils/time';
6-
import { todayLocalDate } from '../utils/today';
6+
import { todayLocalDate } from '../utils/date';
77

88
export async function useAllTabListSummary(sortingBy: SortingBy): Promise<OverallStats | null> {
99
const repo = await injectTabsRepository();

src/compositions/daily-intervals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TimeInterval } from '../entity/time-interval';
22
import { injecStorage } from '../storage/inject-storage';
33
import { StorageDeserializeParam, StorageParams } from '../storage/storage-params';
4-
import { todayLocalDate } from '../utils/today';
4+
import { todayLocalDate } from '../utils/date';
55

66
export async function closeInterval(domain: string | null): Promise<void> {
77
if (domain == null) return;

src/compositions/limit-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Restriction } from '../entity/restriction';
22
import { Tab } from '../entity/tab';
33
import { StorageParams } from '../storage/storage-params';
4-
import { todayLocalDate } from '../utils/today';
4+
import { todayLocalDate } from '../utils/date';
55
import { Settings } from './settings';
66

77
export async function isLimitExceeded(url: string, tab: Tab): Promise<boolean> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TabListSummary } from '../dto/tabListSummary';
22
import { Tab } from '../entity/tab';
33
import { injectTabsRepository } from '../repository/inject-tabs-repository';
44
import { SortingBy } from '../utils/enums';
5-
import { todayLocalDate } from '../utils/today';
5+
import { todayLocalDate } from '../utils/date';
66

77
export async function useTodayTabListSummary(sortingBy: SortingBy): Promise<TabListSummary | null> {
88
const repo = await injectTabsRepository();

src/entity/tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { todayLocalDate } from '../utils/today';
1+
import { todayLocalDate } from '../utils/date';
22
import { logger } from '../compositions/logger';
33

44
export class Tab implements ISerializable<Tab> {

src/popup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import Popup from './pages/Popup.vue';
2+
import VueDatePicker from '@vuepic/vue-datepicker';
3+
import '@vuepic/vue-datepicker/dist/main.css';
24
import { createApp } from 'vue';
35

4-
createApp(Popup).mount('body');
6+
const app = createApp(Popup);
7+
app.component('VueDatePicker', VueDatePicker);
8+
app.mount('body');

0 commit comments

Comments
 (0)