@@ -26,7 +26,10 @@ import DonutChart from '../components/DonutChart.vue';
2626import { injectTabsRepository } from ' ../repository/inject-tabs-repository' ;
2727import { Tab } from ' ../entity/tab' ;
2828import { 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
3134const 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 >
0 commit comments