Skip to content

Commit 2d585a7

Browse files
authored
refactor: remove tinycolor from core (#1993)
1 parent e24bf09 commit 2d585a7

22 files changed

Lines changed: 55 additions & 181 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
"main": "",
88
"devDependencies": {
99
"@faker-js/faker": "^9.6.0",
10-
"@types/tinycolor2": "^1.4.6",
1110
"typescript": "^6.0.3"
1211
},
1312
"dependencies": {
1413
"bson": "^7.2.0",
1514
"dayjs": "^1.11.19",
1615
"eventemitter2": "^6.4.9",
1716
"rxjs": "^7.8.2",
18-
"tinycolor2": "^1.6.0",
1917
"winston": "^3.8.1",
2018
"yaml": "^2.9.0",
2119
"zod": "^3.25.76"

packages/core/src/__tests__/helpers/gcal.factory.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { faker } from "@faker-js/faker";
22
import { type gSchema$CalendarListEntry } from "@core/types/gcal";
3-
import { generateCalendarColorScheme } from "@core/util/color.utils";
43

54
/**
65
* Generates a mock Google Calendar calendar list entry.
@@ -11,8 +10,6 @@ import { generateCalendarColorScheme } from "@core/util/color.utils";
1110
export const createMockCalendarListEntry = (
1211
overrides: Partial<gSchema$CalendarListEntry> = {},
1312
): gSchema$CalendarListEntry => {
14-
const { backgroundColor, color } = generateCalendarColorScheme();
15-
1613
return {
1714
kind: "calendar#calendarListEntry",
1815
id: "test-calendar",
@@ -22,8 +19,8 @@ export const createMockCalendarListEntry = (
2219
description: faker.lorem.paragraph({ min: 1, max: 3 }),
2320
timeZone: faker.location.timeZone(),
2421
colorId: faker.number.int({ min: 1, max: 24 }).toString(),
25-
backgroundColor,
26-
foregroundColor: color,
22+
backgroundColor: "#9e9e9e",
23+
foregroundColor: "#000000",
2724
selected: true,
2825
accessRole: faker.helpers.arrayElement(["reader", "writer", "owner"]),
2926
defaultReminders: [],

packages/core/src/mappers/map.calendar.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ describe("MapCalendar.gcalToCompass", () => {
3131
}),
3232
);
3333
});
34+
35+
it("uses stable colors when google omits them", () => {
36+
const googleCalendar = createMockCalendarListEntry({
37+
backgroundColor: undefined,
38+
foregroundColor: undefined,
39+
});
40+
41+
const result = MapCalendar.gcalToCompass(new ObjectId(), googleCalendar);
42+
43+
expect(result.backgroundColor).toBe("#9e9e9e");
44+
expect(result.color).toBe("#000000");
45+
});
3446
});

packages/core/src/mappers/map.calendar.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ import {
55
} from "@core/types/calendar.types";
66
import { CalendarProvider } from "@core/types/event.types";
77
import { type gSchema$CalendarListEntry } from "@core/types/gcal";
8-
import { generateCalendarColorScheme } from "@core/util/color.utils";
98
import dayjs from "@core/util/date/dayjs";
109

1110
export class MapCalendar {
1211
static gcalToCompass(
1312
user: ObjectId | string,
1413
googleCalendar: gSchema$CalendarListEntry,
1514
) {
16-
// generate fallback colors
17-
const { backgroundColor, color } = generateCalendarColorScheme();
18-
1915
const metadata = GoogleCalendarMetadataSchema.parse({
2016
...googleCalendar,
2117
provider: CalendarProvider.GOOGLE,
@@ -24,8 +20,8 @@ export class MapCalendar {
2420
return CompassCalendarSchema.parse({
2521
_id: new ObjectId(),
2622
user,
27-
backgroundColor: googleCalendar.backgroundColor ?? backgroundColor,
28-
color: googleCalendar.foregroundColor ?? color,
23+
backgroundColor: googleCalendar.backgroundColor ?? "#9e9e9e",
24+
color: googleCalendar.foregroundColor ?? "#000000",
2925
selected: googleCalendar.selected ?? true,
3026
primary: googleCalendar.primary ?? false,
3127
timezone: googleCalendar.timeZone ?? dayjs.tz.guess(),

packages/core/src/util/color.utils.test.ts

Lines changed: 0 additions & 110 deletions
This file was deleted.

packages/core/src/util/color.utils.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"react-textarea-autosize": "^8.3.3",
3030
"react-toastify": "^9.1.3",
3131
"supertokens-web-js": "^0.16.0",
32+
"tinycolor2": "^1.6.0",
3233
"zustand": "^5.0.14"
3334
},
3435
"devDependencies": {
@@ -42,6 +43,7 @@
4243
"@types/react": "^18.0.8",
4344
"@types/react-datepicker": "^4.1.7",
4445
"@types/react-dom": "^18.0.3",
46+
"@types/tinycolor2": "^1.4.6",
4547
"bun-types": "^1.2.18",
4648
"fake-indexeddb": "^6.2.5",
4749
"jsdom": "^26.1.0",

packages/web/src/common/calendar-grid/components/CalendarTimedEventCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
useMemo,
99
} from "react";
1010
import { Priorities } from "@core/constants/core.constants";
11-
import { brighten, darken } from "@core/util/color.utils";
1211
import dayjs from "@core/util/date/dayjs";
1312
import {
1413
CALENDAR_GRID_EVENT_TIME_LABEL_FONT_SIZE,
@@ -26,6 +25,7 @@ import {
2625
DATA_EVENT_ELEMENT_ID,
2726
ZIndex,
2827
} from "@web/common/constants/web.constants";
28+
import { brighten, darken } from "@web/common/styles/color.utils";
2929
import {
3030
gridColorByPriority,
3131
gridHoverColorByPriority,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { brighten, darken, isDark } from "./color.utils";
2+
import { describe, expect, it } from "bun:test";
3+
4+
describe("color.utils", () => {
5+
it("adjusts colors", () => {
6+
expect(brighten("#123456", 15)).toBe("#385a7c");
7+
expect(darken("#abcdef", 20)).toBe("#559adf");
8+
});
9+
10+
it("identifies dark colors", () => {
11+
expect(isDark("#000000")).toBe(true);
12+
expect(isDark("#ffffff")).toBe(false);
13+
});
14+
});

0 commit comments

Comments
 (0)