Skip to content

Commit 2e55e0f

Browse files
author
mup
committed
Adds a settings item to choose the start time for week based views
This commit adds the options to select a default value for three days and week views to scroll to.
1 parent ab4b073 commit 2e55e0f

File tree

8 files changed

+59
-6
lines changed

8 files changed

+59
-6
lines changed

src/calendar-app/calendar/view/CalendarView.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
getStartOfTheWeekOffset,
3737
getStartOfTheWeekOffsetForUser,
3838
getTimeZone,
39-
getWeekNumber,
4039
hasSourceUrl,
4140
isBirthdayEvent,
4241
isClientOnlyCalendar,
@@ -1141,6 +1140,9 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
11411140
onNewUrl(args: Record<string, any>) {
11421141
if (!args.view) {
11431142
this.setUrl(this.currentViewType, this.viewModel.selectedDate(), true)
1143+
if (this.currentViewType === CalendarViewType.WEEK || this.currentViewType === CalendarViewType.THREE_DAY) {
1144+
this.viewModel.setSelectedTime(Time.fromDateTime(DateTime.fromObject({ hour: deviceConfig.getScrollTime(), minute: 0 })))
1145+
}
11441146
} else {
11451147
this.currentViewType = CalendarViewTypeByValue[args.view as CalendarViewType] ? args.view : CalendarViewType.MONTH
11461148
const urlDateParam = args.date
@@ -1162,7 +1164,9 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
11621164
}
11631165

11641166
const today = new Date()
1165-
if (isSameDayOfDate(today, date) || (args.view === "week" && getWeekNumber(date) === getWeekNumber(today))) {
1167+
if (args.view === "week" || args.view === "three") {
1168+
this.viewModel.setSelectedTime(Time.fromDateTime(DateTime.fromObject({ hour: deviceConfig.getScrollTime(), minute: 0 })))
1169+
} else if (isSameDayOfDate(today, date)) {
11661170
const time = Time.fromDate(today)
11671171
this.viewModel.setSelectedTime(time)
11681172
} else {

src/common/misc/DeviceConfig.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ interface ConfigObject {
8181
* This is only for the case the user does not want to rate right now or completely opts out of the in-app ratings.
8282
*/
8383
retryRatingPromptAfter?: number
84+
85+
/**
86+
* Which time the three days or week view will scroll to when opened
87+
*/
88+
scrollTime: number
8489
}
8590

8691
/**
@@ -144,6 +149,7 @@ export class DeviceConfig implements UsageTestStorage, NewsItemStorage {
144149
events: loadedConfig.events ?? [],
145150
lastRatingPromptedDate: loadedConfig.lastRatingPromptedDate ?? null,
146151
retryRatingPromptAfter: loadedConfig.retryRatingPromptAfter ?? null,
152+
scrollTime: loadedConfig.scrollTime ?? 8,
147153
}
148154

149155
this.lastSyncStream(new Map(Object.entries(this.config.lastExternalCalendarSync)))
@@ -173,6 +179,15 @@ export class DeviceConfig implements UsageTestStorage, NewsItemStorage {
173179
}
174180
}
175181

182+
getScrollTime(): number {
183+
return this.config.scrollTime
184+
}
185+
186+
setScrollTime(time: number) {
187+
this.config.scrollTime = time
188+
this.writeToStorage()
189+
}
190+
176191
storeCredentials(credentials: DeviceConfigCredentials) {
177192
this.config._credentials.set(credentials.credentialInfo.userId, credentials)
178193

src/common/misc/TranslationKey.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,8 @@ export type TranslationKeyType =
18921892
| "threeDays_label"
18931893
| "prevThreeDays_label"
18941894
| "nextThreeDays_label"
1895+
| "weekScrollTime_label"
1896+
| "weekScrollTime_msg"
18951897
// Put in temporarily, will be removed soon
18961898
| "localAdminGroup_label"
18971899
| "assignAdminRightsToLocallyAdministratedUserError_msg"

src/common/settings/AppearanceSettingsViewer.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,27 @@ import { isDesktop } from "../../common/api/common/Env"
1414
import { locator } from "../../common/api/main/CommonLocator"
1515
import { EntityUpdateData, isUpdateForTypeRef } from "../../common/api/common/utils/EntityUpdateUtils.js"
1616
import { client } from "../misc/ClientDetector.js"
17+
import { DateTime } from "../../../libs/luxon.js"
1718

1819
export class AppearanceSettingsViewer implements UpdatableSettingsViewer {
1920
private _customThemes: Array<ThemeId> | null = null
21+
private timeOptions: Array<{ name: string; value: number }> = []
2022

2123
oncreate() {
2224
locator.themeController.getCustomThemes().then((themes) => {
2325
this._customThemes = themes
2426
m.redraw()
2527
})
28+
29+
const userSettingsGroupRoot = locator.logins.getUserController().userSettingsGroupRoot
30+
const timeFormat = userSettingsGroupRoot.timeFormat
31+
32+
for (let hour = 0; hour < 24; hour++) {
33+
this.timeOptions.push({
34+
name: DateTime.fromFormat(hour.toString(), "h").toFormat(timeFormat === TimeFormat.TWENTY_FOUR_HOURS ? "HH:mm" : "hh:mm a"),
35+
value: hour,
36+
})
37+
}
2638
}
2739

2840
view(): Children {
@@ -117,6 +129,7 @@ export class AppearanceSettingsViewer implements UpdatableSettingsViewer {
117129
m(".h4.mt-l", lang.get("settingsForDevice_label")),
118130
m(DropDownSelector, languageDropDownAttrs),
119131
this._renderThemeSelector(),
132+
this.renderScrollTimeSelector(),
120133
m(".h4.mt-l", lang.get("userSettings_label")),
121134
m(DropDownSelector, hourFormatDropDownAttrs),
122135
m(DropDownSelector, weekStartDropDownAttrs),
@@ -145,6 +158,18 @@ export class AppearanceSettingsViewer implements UpdatableSettingsViewer {
145158
return m(DropDownSelector, themeDropDownAttrs)
146159
}
147160

161+
renderScrollTimeSelector(): Children {
162+
const themeDropDownAttrs: DropDownSelectorAttrs<number> = {
163+
label: "weekScrollTime_label",
164+
helpLabel: () => lang.get("weekScrollTime_msg"),
165+
items: this.timeOptions as SelectorItemList<number>,
166+
selectedValue: deviceConfig.getScrollTime(),
167+
selectionChangedHandler: (value) => deviceConfig.setScrollTime(value),
168+
dropdownWidth: 300,
169+
}
170+
return m(DropDownSelector, themeDropDownAttrs)
171+
}
172+
148173
entityEventsReceived(updates: ReadonlyArray<EntityUpdateData>): Promise<void> {
149174
return promiseMap(updates, (update) => {
150175
if (isUpdateForTypeRef(UserSettingsGroupRootTypeRef, update)) {

src/mail-app/translations/de.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,8 @@ export default {
19121912
"threeDays_label": "Drei Tage",
19131913
"prevThreeDays_label": "Vorherige drei Tage",
19141914
"nextThreeDays_label": "Nächsten drei Tage",
1915+
"weekScrollTime_label": "Standardzeit",
1916+
"weekScrollTime_msg": "Standardzeit für Drei-Tage- und Wochen-Ansichten zum Blättern zu",
19151917
// Put in temporarily, will be removed soon
19161918
"localAdminGroup_label": "Local admin group",
19171919
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",

src/mail-app/translations/de_sie.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,8 @@ export default {
19121912
"threeDays_label": "Drei Tage",
19131913
"prevThreeDays_label": "Vorherige drei Tage",
19141914
"nextThreeDays_label": "Nächsten drei Tage",
1915+
"weekScrollTime_label": "Standardzeit",
1916+
"weekScrollTime_msg": "Standardzeit für Drei-Tage- und Wochen-Ansichten zum Blättern zu",
19151917
// Put in temporarily, will be removed soon
19161918
"localAdminGroup_label": "Local admin group",
19171919
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",

src/mail-app/translations/en.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,12 +1906,14 @@ export default {
19061906
"yourMessage_label": "Your message",
19071907
"you_label": "You",
19081908
// Put in temporarily, will be removed soon
1909-
"localAdminGroup_label": "Local admin group",
1910-
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
1911-
"localAdminGroups_label": "Local admin groups",
19121909
"threeDays_label": "Three Days",
19131910
"prevThreeDays_label": "Previous three days",
1914-
"nextThreeDays_label": "Next three days"
1911+
"nextThreeDays_label": "Next three days",
1912+
"weekScrollTime_label": "Default time",
1913+
"weekScrollTime_msg": "Default time for Three Days and Week views to scroll to",
1914+
// Put in temporarily
1915+
"localAdminGroup_label": "Local admin group",
1916+
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
19151917
"localAdminGroups_label": "Local admin groups"
19161918
}
19171919
}

test/tests/misc/DeviceConfigTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ o.spec("DeviceConfig", function () {
109109
events: [],
110110
lastRatingPromptedDate: null,
111111
retryRatingPromptAfter: null,
112+
scrollTime: 8
112113
}
113114

114115
when(localStorageMock.getItem(DeviceConfig.LocalStorageKey)).thenReturn(JSON.stringify(storedInLocalStorage))

0 commit comments

Comments
 (0)