Skip to content

Commit

Permalink
Fix missing color for external calendars
Browse files Browse the repository at this point in the history
This commit re-implements the generateRandomColor function and adds
a random default color for new external calendars.

fix #8121
  • Loading branch information
mup authored and wrdhub committed Dec 12, 2024
1 parent b480144 commit ce59682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/calendar-app/calendar/gui/CalendarGuiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { CalendarEventTimes, CalendarViewType, cleanMailAddress, isAllDayEvent }
import { CalendarEvent, UserSettingsGroupRoot } from "../../../common/api/entities/tutanota/TypeRefs.js"
import { ProgrammingError } from "../../../common/api/common/error/ProgrammingError.js"
import { size } from "../../../common/gui/size.js"
import { isValidColorCode } from "../../../common/gui/base/Color.js"
import { hslToHex, isColorLight, isValidColorCode, MAX_HUE_ANGLE } from "../../../common/gui/base/Color.js"
import { GroupColors } from "../view/CalendarView.js"
import { CalendarInfo } from "../model/CalendarModel.js"
import { EventType } from "./eventeditor-model/CalendarEventModel.js"
Expand All @@ -82,6 +82,8 @@ import { UserController } from "../../../common/api/main/UserController.js"
import { ClientOnlyCalendarsInfo } from "../../../common/misc/DeviceConfig.js"
import { SelectOption } from "../../../common/gui/base/Select.js"
import { RadioGroupOption } from "../../../common/gui/base/RadioGroup.js"
import { ColorPickerModel } from "../../../common/gui/base/colorPicker/ColorPickerModel.js"
import { theme } from "../../../common/gui/theme.js"

export interface IntervalOption {
value: number
Expand Down Expand Up @@ -972,8 +974,9 @@ export function getDisplayEventTitle(title: string): string {

export type ColorString = string

export function generateRandomColor(withHashtag: boolean = false): ColorString {
return (withHashtag ? "#" : "") + Math.random().toString(16).slice(-6)
export function generateRandomColor(): ColorString {
const model = new ColorPickerModel(!isColorLight(theme.content_bg))
return hslToHex(model.getColor(Math.floor(Math.random() * MAX_HUE_ANGLE), 2))
}

export function renderCalendarColor(selectedCalendar: CalendarInfo | null, groupColors: Map<Id, string>) {
Expand Down
7 changes: 6 additions & 1 deletion src/calendar-app/calendar/gui/EditCalendarDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { CalendarModel } from "../model/CalendarModel.js"
import { DEFAULT_ERROR } from "../../../common/api/common/TutanotaConstants.js"
import { LoginButton } from "../../../common/gui/base/buttons/LoginButton.js"
import { ColorPickerView } from "../../../common/gui/base/colorPicker/ColorPickerView"
import { generateRandomColor } from "./CalendarGuiUtils.js"

export type CalendarProperties = {
name: string
Expand Down Expand Up @@ -125,7 +126,11 @@ export function showCreateEditCalendarDialog({
isNewCalendar = true,
calendarModel,
}: CreateEditDialogAttrs) {
if (color !== "") color = "#" + color
if (color !== "") {
color = "#" + color
} else if (isNewCalendar && isExternalCalendarType(calendarType)) {
color = generateRandomColor()
}

const nameStream = stream(name)
const colorStream = stream(color)
Expand Down
9 changes: 8 additions & 1 deletion src/calendar-app/calendar/view/CalendarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ import { GroupInvitationFolderRow } from "../../../common/sharing/view/GroupInvi
import { SidebarSection } from "../../../common/gui/SidebarSection"
import type { HtmlSanitizer } from "../../../common/misc/HtmlSanitizer"
import { ProgrammingError } from "../../../common/api/common/error/ProgrammingError"
import { calendarNavConfiguration, calendarWeek, daysHaveEvents, shouldDefaultToAmPmTimeFormat, showDeletePopup } from "../gui/CalendarGuiUtils.js"
import {
calendarNavConfiguration,
calendarWeek,
daysHaveEvents,
generateRandomColor,
shouldDefaultToAmPmTimeFormat,
showDeletePopup,
} from "../gui/CalendarGuiUtils.js"
import { CalendarEventBubbleKeyDownHandler, CalendarPreviewModels, CalendarViewModel, MouseOrPointerEvent } from "./CalendarViewModel"
import { CalendarEventPopup } from "../gui/eventpopup/CalendarEventPopup.js"
import { showProgressDialog } from "../../../common/gui/dialogs/ProgressDialog"
Expand Down

0 comments on commit ce59682

Please sign in to comment.