Skip to content

Commit

Permalink
Adds a settings item to choose the start time for week based views
Browse files Browse the repository at this point in the history
This commit adds the options to select a default value for three days
and week views to scroll to.
  • Loading branch information
mup committed Jan 21, 2025
1 parent 52a6327 commit e4b2166
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/calendar-app/calendar/view/CalendarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
getStartOfTheWeekOffset,
getStartOfTheWeekOffsetForUser,
getTimeZone,
getWeekNumber,
hasSourceUrl,
isBirthdayEvent,
isClientOnlyCalendar,
Expand Down Expand Up @@ -1139,6 +1138,9 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
onNewUrl(args: Record<string, any>) {
if (!args.view) {
this.setUrl(this.currentViewType, this.viewModel.selectedDate(), true)
if (this.currentViewType === CalendarViewType.WEEK || this.currentViewType === CalendarViewType.THREE_DAY) {
this.viewModel.setSelectedTime(Time.fromDateTime(DateTime.fromObject({ hour: deviceConfig.getScrollTime(), minute: 0 })))
}
} else {
this.currentViewType = CalendarViewTypeByValue[args.view as CalendarViewType] ? args.view : CalendarViewType.MONTH
const urlDateParam = args.date
Expand All @@ -1160,7 +1162,9 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
}

const today = new Date()
if (isSameDayOfDate(today, date) || (args.view === "week" && getWeekNumber(date) === getWeekNumber(today))) {
if (args.view === "week" || args.view === "three") {
this.viewModel.setSelectedTime(Time.fromDateTime(DateTime.fromObject({ hour: deviceConfig.getScrollTime(), minute: 0 })))
} else if (isSameDayOfDate(today, date)) {
const time = Time.fromDate(today)
this.viewModel.setSelectedTime(time)
} else {
Expand Down
15 changes: 15 additions & 0 deletions src/common/misc/DeviceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ interface ConfigObject {
* This is only for the case the user does not want to rate right now or completely opts out of the in-app ratings.
*/
retryRatingPromptAfter?: number

/**
* Which time the three days or week view will scroll to when opened
*/
scrollTime: number
}

/**
Expand Down Expand Up @@ -144,6 +149,7 @@ export class DeviceConfig implements UsageTestStorage, NewsItemStorage {
events: loadedConfig.events ?? [],
lastRatingPromptedDate: loadedConfig.lastRatingPromptedDate ?? null,
retryRatingPromptAfter: loadedConfig.retryRatingPromptAfter ?? null,
scrollTime: loadedConfig.scrollTime ?? 8,
}

this.lastSyncStream(new Map(Object.entries(this.config.lastExternalCalendarSync)))
Expand Down Expand Up @@ -173,6 +179,15 @@ export class DeviceConfig implements UsageTestStorage, NewsItemStorage {
}
}

getScrollTime(): number {
return this.config.scrollTime
}

setScrollTime(time: number) {
this.config.scrollTime = time
this.writeToStorage()
}

storeCredentials(credentials: DeviceConfigCredentials) {
this.config._credentials.set(credentials.credentialInfo.userId, credentials)

Expand Down
2 changes: 2 additions & 0 deletions src/common/misc/TranslationKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,8 @@ export type TranslationKeyType =
| "threeDays_label"
| "prevThreeDays_label"
| "nextThreeDays_label"
| "weekScrollTime_label"
| "weekScrollTime_msg"
// Put in temporarily
| "localAdminGroup_label"
| "assignAdminRightsToLocallyAdministratedUserError_msg"
Expand Down
25 changes: 25 additions & 0 deletions src/common/settings/AppearanceSettingsViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ import { isDesktop } from "../../common/api/common/Env"
import { locator } from "../../common/api/main/CommonLocator"
import { EntityUpdateData, isUpdateForTypeRef } from "../../common/api/common/utils/EntityUpdateUtils.js"
import { client } from "../misc/ClientDetector.js"
import { DateTime } from "../../../libs/luxon.js"

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

oncreate() {
locator.themeController.getCustomThemes().then((themes) => {
this._customThemes = themes
m.redraw()
})

const userSettingsGroupRoot = locator.logins.getUserController().userSettingsGroupRoot
const timeFormat = userSettingsGroupRoot.timeFormat

for (let hour = 0; hour < 24; hour++) {
this.timeOptions.push({
name: DateTime.fromFormat(hour.toString(), "h").toFormat(timeFormat === TimeFormat.TWENTY_FOUR_HOURS ? "HH:mm" : "hh:mm a"),
value: hour,
})
}
}

view(): Children {
Expand Down Expand Up @@ -117,6 +129,7 @@ export class AppearanceSettingsViewer implements UpdatableSettingsViewer {
m(".h4.mt-l", lang.get("settingsForDevice_label")),
m(DropDownSelector, languageDropDownAttrs),
this._renderThemeSelector(),
this.renderScrollTimeSelector(),
m(".h4.mt-l", lang.get("userSettings_label")),
m(DropDownSelector, hourFormatDropDownAttrs),
m(DropDownSelector, weekStartDropDownAttrs),
Expand Down Expand Up @@ -145,6 +158,18 @@ export class AppearanceSettingsViewer implements UpdatableSettingsViewer {
return m(DropDownSelector, themeDropDownAttrs)
}

renderScrollTimeSelector(): Children {
const themeDropDownAttrs: DropDownSelectorAttrs<number> = {
label: "weekScrollTime_label",
helpLabel: () => lang.get("weekScrollTime_msg"),
items: this.timeOptions as SelectorItemList<number>,
selectedValue: deviceConfig.getScrollTime(),
selectionChangedHandler: (value) => deviceConfig.setScrollTime(value),
dropdownWidth: 300,
}
return m(DropDownSelector, themeDropDownAttrs)
}

entityEventsReceived(updates: ReadonlyArray<EntityUpdateData>): Promise<void> {
return promiseMap(updates, (update) => {
if (isUpdateForTypeRef(UserSettingsGroupRootTypeRef, update)) {
Expand Down
2 changes: 2 additions & 0 deletions src/mail-app/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,8 @@ export default {
"threeDays_label": "Drei Tage",
"prevThreeDays_label": "Vorherige drei Tage",
"nextThreeDays_label": "Nächsten drei Tage",
"weekScrollTime_label": "Standardzeit",
"weekScrollTime_msg": "Standardzeit für Drei-Tage- und Wochen-Ansichten zum Blättern zu",
// Put in temporarily
"localAdminGroup_label": "Local admin group",
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
Expand Down
2 changes: 2 additions & 0 deletions src/mail-app/translations/de_sie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,8 @@ export default {
"threeDays_label": "Drei Tage",
"prevThreeDays_label": "Vorherige drei Tage",
"nextThreeDays_label": "Nächsten drei Tage",
"weekScrollTime_label": "Standardzeit",
"weekScrollTime_msg": "Standardzeit für Drei-Tage- und Wochen-Ansichten zum Blättern zu",
// Put in temporarily
"localAdminGroup_label": "Local admin group",
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
Expand Down
10 changes: 6 additions & 4 deletions src/mail-app/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1875,12 +1875,14 @@ export default {
"yourFolders_action": "YOUR FOLDERS",
"yourMessage_label": "Your message",
"you_label": "You",
"threeDays_label": "Three Days",
"prevThreeDays_label": "Previous three days",
"nextThreeDays_label": "Next three days",
"weekScrollTime_label": "Default time",
"weekScrollTime_msg": "Default time for Three Days and Week views to scroll to",
// Put in temporarily
"localAdminGroup_label": "Local admin group",
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
"localAdminGroups_label": "Local admin groups",
"threeDays_label": "Three Days",
"prevThreeDays_label": "Previous three days",
"nextThreeDays_label": "Next three days"
"localAdminGroups_label": "Local admin groups"
}
}

0 comments on commit e4b2166

Please sign in to comment.