|
1 | 1 | import {hexToRGB, ValueObject} from "@/models/utils"; |
2 | | -import {EventTheme, ListableEvent} from "@shared/event-list.firestore"; |
| 2 | +import {EventTheme, ListableEvent, ThemeColors} from "@shared/event-list.firestore"; |
3 | 3 | import {DayId, VoxxrinDay} from "@/models/VoxxrinDay"; |
4 | 4 | import {Temporal} from "temporal-polyfill"; |
5 | 5 | import {useCurrentClock} from "@/state/useCurrentClock"; |
@@ -40,16 +40,21 @@ export type ListableVoxxrinEvent = Replace<ListableEvent, { |
40 | 40 | theming: VoxxrinEventTheme, |
41 | 41 | } & ListableVoxxrinEventVisibility> |
42 | 42 |
|
43 | | -export type VoxxrinEventTheme = Replace<EventTheme, { |
44 | | - colors: EventTheme['colors'] & { |
45 | | - primaryRGB: string, |
46 | | - primaryContrastRGB: string, |
47 | | - secondaryRGB: string, |
48 | | - secondaryContrastRGB: string, |
49 | | - tertiaryRGB: string, |
50 | | - tertiaryContrastRGB: string |
| 43 | +export type VoxxringThemeColors = ThemeColors & { |
| 44 | + primaryRGB: string, |
| 45 | + primaryContrastRGB: string, |
| 46 | + secondaryRGB: string, |
| 47 | + secondaryContrastRGB: string, |
| 48 | + tertiaryRGB: string, |
| 49 | + tertiaryContrastRGB: string |
| 50 | +} |
| 51 | + |
| 52 | +export type VoxxrinEventTheme = Omit<EventTheme, "colors"> & { |
| 53 | + colors: { |
| 54 | + light: VoxxringThemeColors, |
| 55 | + dark: VoxxringThemeColors, |
51 | 56 | } |
52 | | -}> |
| 57 | +} |
53 | 58 |
|
54 | 59 | export function searchEvents(events: ListableVoxxrinEvent[], searchCriteria: { terms: string|undefined, includePastEvents: boolean}, pinnededIds: EventId[]) { |
55 | 60 | const filteredEvents = events.filter(event => { |
@@ -107,16 +112,49 @@ export function firestoreListableEventToVoxxrinListableEvent(firestoreListableEv |
107 | 112 | } |
108 | 113 |
|
109 | 114 | export function toVoxxrinEventTheme(firestoreTheme: EventTheme): VoxxrinEventTheme { |
110 | | - return { |
111 | | - colors: { |
112 | | - ...firestoreTheme.colors, |
113 | | - primaryRGB: hexToRGB(firestoreTheme.colors.primaryHex), |
114 | | - primaryContrastRGB: hexToRGB(firestoreTheme.colors.primaryContrastHex), |
115 | | - secondaryRGB: hexToRGB(firestoreTheme.colors.secondaryHex), |
116 | | - secondaryContrastRGB: hexToRGB(firestoreTheme.colors.secondaryContrastHex), |
117 | | - tertiaryRGB: hexToRGB(firestoreTheme.colors.tertiaryHex), |
118 | | - tertiaryContrastRGB: hexToRGB(firestoreTheme.colors.tertiaryContrastHex), |
| 115 | + const colors: VoxxrinEventTheme['colors'] = match(firestoreTheme.colors) |
| 116 | + .with({ light: P.any, dark: P.any }, ({light, dark}) => ({ |
| 117 | + light: { |
| 118 | + ...light, |
| 119 | + primaryRGB: hexToRGB(light.primaryHex), |
| 120 | + primaryContrastRGB: hexToRGB(light.primaryContrastHex), |
| 121 | + secondaryRGB: hexToRGB(light.secondaryHex), |
| 122 | + secondaryContrastRGB: hexToRGB(light.secondaryContrastHex), |
| 123 | + tertiaryRGB: hexToRGB(light.tertiaryHex), |
| 124 | + tertiaryContrastRGB: hexToRGB(light.tertiaryContrastHex), |
119 | 125 | }, |
| 126 | + dark: { |
| 127 | + ...dark, |
| 128 | + primaryRGB: hexToRGB(dark.primaryHex), |
| 129 | + primaryContrastRGB: hexToRGB(dark.primaryContrastHex), |
| 130 | + secondaryRGB: hexToRGB(dark.secondaryHex), |
| 131 | + secondaryContrastRGB: hexToRGB(dark.secondaryContrastHex), |
| 132 | + tertiaryRGB: hexToRGB(dark.tertiaryHex), |
| 133 | + tertiaryContrastRGB: hexToRGB(dark.tertiaryContrastHex), |
| 134 | + } |
| 135 | + })) |
| 136 | + .otherwise(colors => ({ |
| 137 | + light: { |
| 138 | + ...colors, |
| 139 | + primaryRGB: hexToRGB(colors.primaryHex), |
| 140 | + primaryContrastRGB: hexToRGB(colors.primaryContrastHex), |
| 141 | + secondaryRGB: hexToRGB(colors.secondaryHex), |
| 142 | + secondaryContrastRGB: hexToRGB(colors.secondaryContrastHex), |
| 143 | + tertiaryRGB: hexToRGB(colors.tertiaryHex), |
| 144 | + tertiaryContrastRGB: hexToRGB(colors.tertiaryContrastHex), |
| 145 | + }, |
| 146 | + dark: { |
| 147 | + ...colors, |
| 148 | + primaryRGB: hexToRGB(colors.primaryHex), |
| 149 | + primaryContrastRGB: hexToRGB(colors.primaryContrastHex), |
| 150 | + secondaryRGB: hexToRGB(colors.secondaryHex), |
| 151 | + secondaryContrastRGB: hexToRGB(colors.secondaryContrastHex), |
| 152 | + tertiaryRGB: hexToRGB(colors.tertiaryHex), |
| 153 | + tertiaryContrastRGB: hexToRGB(colors.tertiaryContrastHex), |
| 154 | + } |
| 155 | + })) |
| 156 | + return { |
| 157 | + colors, |
120 | 158 | headingCustomStyles: firestoreTheme.headingCustomStyles, |
121 | 159 | headingSrcSet: firestoreTheme.headingSrcSet, |
122 | 160 | customImportedFonts: firestoreTheme.customImportedFonts, |
|
0 commit comments