Skip to content

Commit e86f641

Browse files
committed
Fix total time missing (sheepzh#352)
1 parent d7ace05 commit e86f641

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

src/i18n/message/popup/content-resource.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"saveAsImageTitle": "保存",
1313
"averageTime": "平均每天 {value}",
1414
"averageCount": "平均每天 {value} 次",
15+
"totalTime": "共 {totalTime}",
16+
"totalCount": "共 {totalCount} 次",
1517
"otherLabel": "其他{count}个网站"
1618
},
1719
"ranking": {
@@ -31,6 +33,8 @@
3133
"saveAsImageTitle": "保存",
3234
"averageCount": "平均每天 {value} 次",
3335
"averageTime": "平均每天 {value}",
36+
"totalTime": "共 {totalTime}",
37+
"totalCount": "共 {totalCount} 次",
3438
"otherLabel": "其他 {count} 個站點"
3539
},
3640
"ranking": {
@@ -50,6 +54,8 @@
5054
"saveAsImageTitle": "Snapshot",
5155
"averageCount": "{value} times per day on average",
5256
"averageTime": "{value} per day on average",
57+
"totalTime": "Total {totalTime}",
58+
"totalCount": "Total {totalCount} times",
5359
"otherLabel": "Other {count} sites"
5460
},
5561
"ranking": {
@@ -69,6 +75,8 @@
6975
"saveAsImageTitle": "ダウンロード",
7076
"averageCount": "1日平均 {value} 回",
7177
"averageTime": "1日平均 {value}",
78+
"totalTime": "合計 {totalTime}",
79+
"totalCount": "合計 {totalCount} 回",
7280
"otherLabel": "他 {count} サイト"
7381
},
7482
"ranking": {
@@ -88,6 +96,8 @@
8896
"saveAsImageTitle": "Capturas",
8997
"averageCount": "{value} vezes por dia em média",
9098
"averageTime": "{value} por dia em média",
99+
"totalTime": "Total {totalTime}",
100+
"totalCount": "Total {totalCount} vezes",
91101
"otherLabel": "Outros sites do {count}"
92102
},
93103
"ranking": {
@@ -107,6 +117,8 @@
107117
"saveAsImageTitle": "Знімок",
108118
"averageCount": "{value} разів на день у середньому",
109119
"averageTime": "{value} на день у середньому",
120+
"totalTime": "Всього {totalTime}",
121+
"totalCount": "Всього {totalCount} разів",
110122
"otherLabel": "Інші {count} сайтів"
111123
},
112124
"ranking": {
@@ -126,6 +138,8 @@
126138
"saveAsImageTitle": "Captura de pantalla",
127139
"averageCount": "{value} veces al día en promedio",
128140
"averageTime": "{value} al día en promedio",
141+
"totalTime": "Total {totalTime}",
142+
"totalCount": "Total {totalCount} veces",
129143
"otherLabel": "Otros {count} sitios"
130144
},
131145
"ranking": {
@@ -145,6 +159,8 @@
145159
"saveAsImageTitle": "Bildschirmfoto",
146160
"averageCount": "{value} mal pro Tag",
147161
"averageTime": "{value} pro Tag im Durchschnitt",
162+
"totalTime": "Gesamt {totalTime}",
163+
"totalCount": "Gesamt {totalCount} mal",
148164
"otherLabel": "{count} andere Websites"
149165
},
150166
"ranking": {
@@ -164,6 +180,8 @@
164180
"saveAsImageTitle": "Capture d'écran",
165181
"averageCount": "{value} fois par jour en moyenne",
166182
"averageTime": "{value} fois par jour en moyenne",
183+
"totalTime": "{totalTime} au total",
184+
"totalCount": "{totalCount} fois au total",
167185
"otherLabel": "{count} autres sites"
168186
},
169187
"ranking": {
@@ -183,6 +201,8 @@
183201
"saveAsImageTitle": "Снимок",
184202
"averageCount": "{value} раз в день в среднем",
185203
"averageTime": "{value} в день в среднем",
204+
"totalTime": "Всего {totalTime}",
205+
"totalCount": "Всего {totalCount} раз",
186206
"otherLabel": "Другие {count} сайты"
187207
},
188208
"ranking": {
@@ -202,6 +222,8 @@
202222
"saveAsImageTitle": "تحميل",
203223
"averageCount": "متوسط {value} زيارة يومياً",
204224
"averageTime": "متوسط {value} يومياً",
225+
"totalTime": "الإجمالي {totalTime}",
226+
"totalCount": "الإجمالي {totalCount} زيارة",
205227
"otherLabel": "{count} مواقع أخرى"
206228
},
207229
"ranking": {

src/i18n/message/popup/content.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type ContentMessage = {
1313
saveAsImageTitle: string
1414
averageTime: string
1515
averageCount: string
16+
totalTime: string
17+
totalCount: string
1618
otherLabel: string
1719
}
1820
ranking: {

src/pages/popup/components/Header/LangSelect.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { createTab } from "@api/chrome/tab"
12
import { useManualRequest, useRequest } from "@hooks/useRequest"
23
import { ALL_LOCALES, localeSameAsBrowser, t } from "@i18n"
34
import optionMessages from "@i18n/message/app/option"
45
import localeMessages from "@i18n/message/common/locale"
56
import Flex from "@pages/components/Flex"
67
import { usePopupContext } from "@popup/context"
8+
import { t as tPopup } from "@popup/locale"
79
import optionService from "@service/option-service"
10+
import { CROWDIN_HOMEPAGE } from "@util/constant/url"
811
import { ElDropdown, ElDropdownItem, ElDropdownMenu, ElIcon, ElText } from "element-plus"
912
import { defineComponent, type StyleValue } from "vue"
1013

@@ -64,10 +67,15 @@ const LangSelect = defineComponent(() => {
6467
<ElDropdownItem
6568
onClick={() => saveLocale('default')}
6669
style={current.value === 'default' ? SELECTED_STYLES : null}
67-
divided
6870
>
6971
{t(optionMessages, { key: m => m.appearance.locale.default })}
7072
</ElDropdownItem>
73+
<ElDropdownItem
74+
onClick={() => createTab(CROWDIN_HOMEPAGE)}
75+
divided
76+
>
77+
{tPopup(msg => msg.menu.helpUs)}
78+
</ElDropdownItem>
7179
</ElDropdownMenu>
7280
)
7381
}}

src/pages/popup/components/Percentage/chart.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { jump2Report } from "@popup/common"
22
import { t } from "@popup/locale"
3+
import { sum } from "@util/array"
34
import { IS_SAFARI } from "@util/constant/environment"
5+
import { isRtl } from "@util/document"
46
import { generateSiteLabel } from "@util/site"
57
import { getPrimaryTextColor, getSecondaryTextColor } from "@util/style"
68
import { formatPeriodCommon, formatTime, parseTime } from "@util/time"
@@ -39,7 +41,7 @@ function combineDate(start: Date, end: Date, format: string): string {
3941
.replace('{ed}', ed.toString().padStart(2, '0'))
4042
}
4143

42-
function calculateSubTitleText(date: Date | [Date, Date?], dataDate: [string, string]): string {
44+
function formatDateStr(date: Date | [Date, Date?], dataDate: [string, string]): string {
4345
const format = t(msg => msg.calendar.dateFormat)
4446

4547
if (!date) {
@@ -57,11 +59,32 @@ function calculateSubTitleText(date: Date | [Date, Date?], dataDate: [string, st
5759
return combineDate(start, end, format)
5860
}
5961

62+
function formatTotalStr(rows: timer.stat.Row[], type: timer.core.Dimension): string {
63+
if (type === 'focus') {
64+
const total = sum(rows.map(r => r?.focus ?? 0))
65+
const totalTime = formatPeriodCommon(total)
66+
return t(msg => msg.content.percentage.totalTime, { totalTime })
67+
} else if (type === 'time') {
68+
const totalCount = sum(rows.map(r => r.time ?? 0))
69+
return t(msg => msg.content.percentage.totalCount, { totalCount })
70+
} else {
71+
return ''
72+
}
73+
}
74+
75+
function calculateSubTitleText(result: PercentageResult): string {
76+
let { date, dataDate, rows, query: { type } = {} } = result
77+
const dateStr = formatDateStr(date, dataDate)
78+
const totalStr = formatTotalStr(rows, type)
79+
let parts = [totalStr, dateStr].filter(str => !!str)
80+
isRtl() && (parts = parts.reverse())
81+
return parts.join(' @ ')
82+
}
83+
6084
export function generateTitleOption(result: PercentageResult): TitleComponentOption {
61-
const { chartTitle, date, dataDate } = result || {}
6285
return {
63-
text: chartTitle,
64-
subtext: calculateSubTitleText(date, dataDate),
86+
text: result?.chartTitle,
87+
subtext: calculateSubTitleText(result),
6588
left: 'center',
6689
textStyle: { color: getPrimaryTextColor() },
6790
subtextStyle: { color: getSecondaryTextColor() },

0 commit comments

Comments
 (0)