Skip to content

Commit 46ac5be

Browse files
committed
Prepare for sorting by
1 parent ace2b6e commit 46ac5be

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

src/assets/css/main.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ body {
3636
.mr-10 {
3737
margin-right: 10px;
3838
}
39+
.mr-5 {
40+
margin-right: 5px;
41+
}
42+
.pr-5{
43+
padding-right: 5px;
44+
}
45+
.p-5{
46+
padding: 5px;
47+
}
3948
.text-right {
4049
text-align: right;
4150
}

src/components/TabItemHeader.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<template>
22
<div class="header-block">
3-
<p>{{ title }} ({{ countOfSites }} sites)</p>
4-
<p class="time">{{ summaryTimeString }}</p>
3+
<div class="time-block">
4+
<p>{{ title }} ({{ countOfSites }} sites)</p>
5+
<p class="time">{{ summaryTimeString }}</p>
6+
</div>
7+
<div class="sorted-block">
8+
<span class="mr-5">Sorting by</span>
9+
<select class="p-5" @change="sortingBy()">
10+
<option>Usage Time</option>
11+
<option>Sessions</option>
12+
</select>
13+
</div>
514
</div>
615
</template>
716

@@ -14,7 +23,7 @@ export default {
1423
<script lang="ts" setup>
1524
import { computed } from 'vue';
1625
import { convertSummaryTimeToString } from '../utils/converter';
17-
import { TypeOfList } from '../utils/enums';
26+
import { SortingBy, TypeOfList } from '../utils/enums';
1827
1928
const props = defineProps<{
2029
listType: TypeOfList;
@@ -23,19 +32,32 @@ const props = defineProps<{
2332
firstDay: Date;
2433
}>();
2534
35+
const emit = defineEmits<{
36+
(event: 'sortingBy', sortingBy: SortingBy): void;
37+
}>();
38+
2639
const title = computed(() => {
2740
if (props.listType == TypeOfList.Today) return 'Today';
2841
if (props.listType == TypeOfList.All) return `Aggregate data since ${props.firstDay} `;
2942
});
3043
3144
const summaryTimeString = computed(() => convertSummaryTimeToString(props.summaryTime));
45+
46+
function sortingBy(value) {
47+
emit('sortingBy', value);
48+
}
3249
</script>
3350

3451
<style scoped>
3552
.header-block {
3653
background-color: var(--popup-header);
3754
padding: 1px 0;
3855
text-align: center;
56+
display: flex;
57+
flex-direction: row;
58+
}
59+
.time-block {
60+
flex: auto;
3961
}
4062
p {
4163
font-size: 14px;
@@ -45,4 +67,8 @@ p {
4567
font-size: 16px;
4668
font-weight: 600;
4769
}
70+
.sorted-block {
71+
margin: auto;
72+
margin-right: 15px;
73+
}
4874
</style>

src/components/TabList.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:summaryTime="summaryTime"
88
:countOfSites="countOfSites"
99
:firstDay="firstDay"
10+
@sortingBy="sorting"
1011
/>
1112
<TabItem v-for="(tab, i) of tabs" :key="i" :tab="tab" :summaryTime="summaryTime" />
1213
</div>
@@ -25,10 +26,8 @@ import TabItemHeader from '../components/TabItemHeader.vue';
2526
import DonutChart from '../components/DonutChart.vue';
2627
import { injectTabsRepository } from '../repository/inject-tabs-repository';
2728
import { Tab } from '../entity/tab';
28-
import { todayLocalDate } from '../utils/today';
2929
import { SortingBy, TypeOfList } from '../utils/enums';
3030
import { useTodayTabListSummary } from '../compositions/today-tab-list-summary';
31-
import { TabListSummary } from '../utils/tabListSummary';
3231
import { useAllTabListSummary } from '../compositions/all-tab-list-summary';
3332
3433
const props = defineProps<{
@@ -51,8 +50,8 @@ const firstDay = computed(() => {
5150
async function loadList(sortingBy: SortingBy) {
5251
const repo = await injectTabsRepository();
5352
let tabSummary = null;
54-
if (props.type == TypeOfList.Today) tabSummary = await useTodayTabListSummary();
55-
if (props.type == TypeOfList.Today) tabSummary = await useAllTabListSummary();
53+
if (props.type == TypeOfList.Today) tabSummary = await useTodayTabListSummary(sortingBy);
54+
if (props.type == TypeOfList.Today) tabSummary = await useAllTabListSummary(sortingBy);
5655
5756
if (tabSummary != null) {
5857
tabs.value = tabSummary.tabs;
@@ -62,11 +61,7 @@ async function loadList(sortingBy: SortingBy) {
6261
}
6362
}
6463
65-
onMounted(async () => {
66-
loadList(SortingBy.WebUsage);
67-
});
68-
69-
function sortingBy(sortingBy: SortingBy) {
64+
function sorting(sortingBy: SortingBy) {
7065
switch (sortingBy) {
7166
case SortingBy.WebUsage:
7267
loadList(SortingBy.WebUsage);
@@ -76,4 +71,8 @@ function sortingBy(sortingBy: SortingBy) {
7671
break;
7772
}
7873
}
74+
75+
onMounted(async () => {
76+
loadList(SortingBy.WebUsage);
77+
});
7978
</script>

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { Tab } from '../entity/tab';
22
import { injectTabsRepository } from '../repository/inject-tabs-repository';
3+
import { SortingBy } from '../utils/enums';
34
import { TabListSummary } from '../utils/tabListSummary';
45
import { todayLocalDate } from '../utils/today';
56

6-
export async function useTodayTabListSummary(): Promise<TabListSummary> {
7+
export async function useTodayTabListSummary(sortingBy: SortingBy): Promise<TabListSummary> {
78
const repo = await injectTabsRepository();
89
const unSortedTabs = repo.getTodayTabs();
910
let tabs: Tab[] = [];
1011

1112
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-
);
13+
return sortingBy == SortingBy.UsageTime
14+
? b.days.find(s => s.date === todayLocalDate())!.summary -
15+
a.days.find(s => s.date === todayLocalDate())!.summary
16+
: b.days.find(s => s.date === todayLocalDate())!.counter -
17+
a.days.find(s => s.date === todayLocalDate())!.counter;
1618
});
1719

1820
const summaryTimeList = tabs?.map(function (tab) {
19-
return tab.days.find(day => day.date === todayLocalDate())!.summary;
21+
return sortingBy == SortingBy.UsageTime
22+
? tab.days.find(day => day.date === todayLocalDate())!.summary
23+
: tab.days.find(day => day.date === todayLocalDate())!.counter;
2024
});
2125
const siteList = tabs?.map(function (tab) {
2226
return tab.url;

src/utils/enums.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ export enum TypeOfList {
33
All,
44
ByDays,
55
}
6+
7+
export enum SortingBy {
8+
UsageTime,
9+
Sessions,
10+
}

0 commit comments

Comments
 (0)