Skip to content

Commit 41278c0

Browse files
committed
Add components for today and all days data summary
1 parent edf4e39 commit 41278c0

File tree

5 files changed

+119
-24
lines changed

5 files changed

+119
-24
lines changed

src/components/TabList.vue

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import DonutChart from '../components/DonutChart.vue';
2626
import { injectTabsRepository } from '../repository/inject-tabs-repository';
2727
import { Tab } from '../entity/tab';
2828
import { todayLocalDate } from '../utils/today';
29-
import { TypeOfList } from '../utils/enums';
29+
import { SortingBy, TypeOfList } from '../utils/enums';
30+
import { useTodayTabListSummary } from '../compositions/today-tab-list-summary';
31+
import { TabListSummary } from '../utils/tabListSummary';
32+
import { useAllTabListSummary } from '../compositions/all-tab-list-summary';
3033
3134
const props = defineProps<{
3235
type: TypeOfList;
@@ -45,30 +48,32 @@ const firstDay = computed(() => {
4548
if (props.type == TypeOfList.All) return;
4649
});
4750
48-
onMounted(async () => {
51+
async function loadList(sortingBy: SortingBy) {
4952
const repo = await injectTabsRepository();
50-
let unSortedTabs = repo.getTodayTabs();
51-
tabs.value = unSortedTabs.sort(function (a: Tab, b: Tab) {
52-
return (
53-
b.days.find(s => s.date === todayLocalDate())!.summary -
54-
a.days.find(s => s.date === todayLocalDate())!.summary
55-
);
56-
});
53+
let tabSummary = null;
54+
if (props.type == TypeOfList.Today) tabSummary = await useTodayTabListSummary();
55+
if (props.type == TypeOfList.Today) tabSummary = await useAllTabListSummary();
5756
58-
const summaryTimeList = tabs.value?.map(function (tab) {
59-
return tab.days.find(day => day.date === todayLocalDate())!.summary;
60-
});
61-
const siteList = tabs.value?.map(function (tab) {
62-
return tab.url;
63-
});
64-
timeForChart.value = summaryTimeList?.slice(0, 10);
65-
sitesForChart.value = siteList?.slice(0, 10);
57+
if (tabSummary != null) {
58+
tabs.value = tabSummary.tabs;
59+
summaryTime.value = tabSummary.summaryTime;
60+
timeForChart.value = tabSummary.chart.timeForChart;
61+
sitesForChart.value = tabSummary.chart.sitesForChart;
62+
}
63+
}
6664
67-
summaryTime.value =
68-
summaryTimeList != undefined && summaryTimeList.length > 0
69-
? summaryTimeList.reduce(function (a, b) {
70-
return a + b;
71-
})
72-
: 0;
65+
onMounted(async () => {
66+
loadList(SortingBy.WebUsage);
7367
});
68+
69+
function sortingBy(sortingBy: SortingBy) {
70+
switch (sortingBy) {
71+
case SortingBy.WebUsage:
72+
loadList(SortingBy.WebUsage);
73+
break;
74+
case SortingBy.Sessions:
75+
loadList(SortingBy.Sessions);
76+
break;
77+
}
78+
}
7479
</script>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Tab } from '../entity/tab';
2+
import { injectTabsRepository } from '../repository/inject-tabs-repository';
3+
import { TabListSummary } from '../utils/tabListSummary';
4+
5+
export async function useAllTabListSummary(): Promise<TabListSummary> {
6+
const repo = await injectTabsRepository();
7+
const unSortedTabs = repo.getTodayTabs();
8+
let tabs: Tab[] = [];
9+
10+
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
11+
return b.summaryTime - a.summaryTime;
12+
});
13+
14+
const summaryTimeList = tabs?.map(function (tab) {
15+
return tab.summaryTime;
16+
});
17+
const siteList = tabs?.map(function (tab) {
18+
return tab.url;
19+
});
20+
const timeForChart = summaryTimeList?.slice(0, 10);
21+
const sitesForChart = siteList?.slice(0, 10);
22+
23+
const summaryTime =
24+
summaryTimeList != undefined && summaryTimeList.length > 0
25+
? summaryTimeList.reduce(function (a, b) {
26+
return a + b;
27+
})
28+
: 0;
29+
return {
30+
tabs,
31+
summaryTime,
32+
chart: {
33+
timeForChart,
34+
sitesForChart,
35+
},
36+
};
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Tab } from '../entity/tab';
2+
import { injectTabsRepository } from '../repository/inject-tabs-repository';
3+
import { TabListSummary } from '../utils/tabListSummary';
4+
import { todayLocalDate } from '../utils/today';
5+
6+
export async function useTodayTabListSummary(): Promise<TabListSummary> {
7+
const repo = await injectTabsRepository();
8+
const unSortedTabs = repo.getTodayTabs();
9+
let tabs: Tab[] = [];
10+
11+
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
12+
return (
13+
b.days.find(s => s.date === todayLocalDate())!.summary -
14+
a.days.find(s => s.date === todayLocalDate())!.summary
15+
);
16+
});
17+
18+
const summaryTimeList = tabs?.map(function (tab) {
19+
return tab.days.find(day => day.date === todayLocalDate())!.summary;
20+
});
21+
const siteList = tabs?.map(function (tab) {
22+
return tab.url;
23+
});
24+
const timeForChart = summaryTimeList?.slice(0, 10);
25+
const sitesForChart = siteList?.slice(0, 10);
26+
27+
const summaryTime =
28+
summaryTimeList != undefined && summaryTimeList.length > 0
29+
? summaryTimeList.reduce(function (a, b) {
30+
return a + b;
31+
})
32+
: 0;
33+
return {
34+
tabs,
35+
summaryTime,
36+
chart: {
37+
timeForChart,
38+
sitesForChart,
39+
},
40+
};
41+
}

src/pages/Popup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<TabList :type="TypeOfList.Today" />
3535
</section>
3636
<section>
37-
<h2>Delivery Contents</h2>
37+
<TabList :type="TypeOfList.All" />
3838
</section>
3939
<section>
4040
<h2>Shipping</h2>

src/utils/tabListSummary.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Tab } from '../entity/tab';
2+
3+
export interface TabListSummary {
4+
tabs: Tab[];
5+
summaryTime: number;
6+
chart: DataForChart;
7+
}
8+
9+
export interface DataForChart {
10+
timeForChart: number[];
11+
sitesForChart: string[];
12+
}

0 commit comments

Comments
 (0)