Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/components/calendar-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function CalendarContent({ scrollContainerRef }: CalendarContentProps) {
return pastFiltered.filter((eventItem) => {
const preference = getCalendarPreference(
calendarPreferences,
eventItem.event.accountId,
eventItem.event.calendarId,
eventItem.event.calendar.provider.accountId,
eventItem.event.calendar.id,
);

return !(preference?.hidden === true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export function CalendarColorsProvider({
for (const calendar of calendars) {
const preference = getCalendarPreference(
calendarPreferences,
calendar.accountId,
calendar.provider.accountId,
calendar.id,
);

document.documentElement.style.setProperty(
calendarColorVariable(calendar.accountId, calendar.id),
calendarColorVariable(calendar.provider.accountId, calendar.id),
preference?.color ?? calendar.color ?? "var(--color-muted-foreground)",
);
}
Expand Down
18 changes: 12 additions & 6 deletions apps/web/src/components/calendar/event/event-context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ function EventContextMenuCalendarList({
const updateAction = usePartialUpdateAction();

const moveEvent = React.useCallback(
(accountId: string, calendarId: string) => {
(calendar: {
id: string;
provider: { id: "google" | "microsoft"; accountId: string };
}) => {
updateAction({
changes: {
id: event.id,
accountId,
calendarId,
calendar,
type: event.type,
},
notify: true,
Expand All @@ -98,14 +100,16 @@ function EventContextMenuCalendarList({
<Tooltip key={index}>
<TooltipTrigger asChild>
<CalendarRadioItem
value={`${calendar.accountId}-${calendar.id}`}
value={`${calendar.provider.accountId}-${calendar.id}`}
style={
{
"--calendar-color": calendar.color,
} as React.CSSProperties
}
disabled={!canMoveBetweenCalendars(event, calendar)}
onSelect={() => moveEvent(calendar.accountId, calendar.id)}
onSelect={() =>
moveEvent({ id: calendar.id, provider: calendar.provider })
}
/>
</TooltipTrigger>
<TooltipContent className="w-full max-w-48" sideOffset={8}>
Expand Down Expand Up @@ -158,7 +162,9 @@ export function EventContextMenu({ event, children }: EventContextMenuProps) {
<ContextMenu>
{children}
<ContextMenuContent className="w-64">
<ContextMenuRadioGroup value={`${event.accountId}-${event.calendarId}`}>
<ContextMenuRadioGroup
value={`${event.calendar.provider.accountId}-${event.calendar.id}`}
>
<EventContextMenuCalendarList event={event} />
</ContextMenuRadioGroup>

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/calendar/event/event-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function EventItem({

const color =
item.event.color ??
`var(${calendarColorVariable(item.event.accountId, item.event.calendarId)}, var(--color-muted-foreground))`;
`var(${calendarColorVariable(item.event.calendar.provider.accountId, item.event.calendar.id)}, var(--color-muted-foreground))`;

if (view === "month") {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export function DeleteQueueProvider({ children }: DeleteQueueProviderProps) {

deleteMutation.mutate(
{
accountId: item.event.accountId,
calendarId: item.event.calendarId,
calendar: item.event.calendar,
eventId,
sendUpdate: item.notify,
},
Expand Down
31 changes: 9 additions & 22 deletions apps/web/src/components/calendar/flows/update-event/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export function isMovedBetweenCalendars(
previous: CalendarEvent,
) {
return (
updated.accountId !== previous.accountId ||
updated.calendarId !== previous.calendarId
updated.calendar.provider.accountId !==
previous.calendar.provider.accountId ||
updated.calendar.id !== previous.calendar.id
);
}

Expand Down Expand Up @@ -76,8 +77,7 @@ export function buildUpdateEvent(
...event,
...(isCalendarChanged
? {
accountId: previous.accountId,
calendarId: previous.calendarId,
calendar: previous.calendar,
}
: {}),
...(options.sendUpdate
Expand All @@ -92,14 +92,8 @@ export function buildUpdateEvent(
...(isCalendarChanged
? {
move: {
source: {
accountId: previous.accountId,
calendarId: previous.calendarId,
},
destination: {
accountId: event.accountId,
calendarId: event.calendarId,
},
source: previous.calendar,
destination: event.calendar,
},
}
: {}),
Expand All @@ -122,8 +116,7 @@ export function buildUpdateSeries(
...event,
...(isCalendarChanged
? {
accountId: previous.accountId,
calendarId: previous.calendarId,
calendar: previous.calendar,
}
: {}),
...(options.sendUpdate
Expand All @@ -140,14 +133,8 @@ export function buildUpdateSeries(
...(isCalendarChanged
? {
move: {
source: {
accountId: previous.accountId,
calendarId: previous.calendarId,
},
destination: {
accountId: event.accountId,
calendarId: event.calendarId,
},
source: previous.calendar,
destination: event.calendar,
},
}
: {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function CalendarDeleteDialog() {

const onDelete = () => {
mutate({
accountId: calendar.accountId,
provider: calendar.provider,
calendarId: calendar.id,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function CalendarPickerItemToggle({
data-slot="checkbox"
style={
{
"--calendar-color": `var(${calendarColorVariable(calendar.accountId, calendar.id)}, var(--color-muted-foreground))`,
"--calendar-color": `var(${calendarColorVariable(calendar.provider.accountId, calendar.id)}, var(--color-muted-foreground))`,
} as React.CSSProperties
}
className={cn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ function CalendarColorPicker() {

const currentPreference = getCalendarPreference(
calendarPreferences,
calendar.accountId,
calendar.provider.accountId,
calendar.id,
);

const currentColor = currentPreference?.color ?? calendar.color;

const onColorChange = (newColor: string) => {
setCalendarPreferences((prev) =>
setCalendarPreference(prev, calendar.accountId, calendar.id, {
setCalendarPreference(prev, calendar.provider.accountId, calendar.id, {
color: newColor,
}),
);
Expand Down Expand Up @@ -126,7 +126,7 @@ function useCalendarVisibility() {

const preference = getCalendarPreference(
calendarPreferences,
calendar.accountId,
calendar.provider.accountId,
calendar.id,
);

Expand All @@ -135,12 +135,12 @@ function useCalendarVisibility() {
const setVisible = React.useCallback(
(visible: boolean) => {
setCalendarPreferences((prev) =>
setCalendarPreference(prev, calendar.accountId, calendar.id, {
setCalendarPreference(prev, calendar.provider.accountId, calendar.id, {
hidden: !visible,
}),
);
},
[setCalendarPreferences, calendar.accountId, calendar.id],
[setCalendarPreferences, calendar.provider.accountId, calendar.id],
);

return { visible, setVisible };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function VisibleCalendarItem({
)}
style={
{
"--calendar-color": `var(${calendarColorVariable(calendar.accountId, calendar.id)}, var(--color-muted-foreground))`,
"--calendar-color": `var(${calendarColorVariable(calendar.provider.accountId, calendar.id)}, var(--color-muted-foreground))`,
} as React.CSSProperties
}
/>
Expand All @@ -75,7 +75,7 @@ function VisibleCalendars({ className, calendars }: VisibleCalendarProps) {
<div className={cn("flex -space-x-1", className)}>
{calendars.slice(0, Math.min(calendars.length, 3)).map((calendar) => (
<VisibleCalendarItem
key={`${calendar.accountId}.${calendar.id}`}
key={`${calendar.provider.accountId}.${calendar.id}`}
calendar={calendar}
/>
))}
Expand All @@ -96,7 +96,7 @@ function CalendarPickerContent() {
.filter((calendar) => {
const preference = getCalendarPreference(
calendarPreferences,
calendar.accountId,
calendar.provider.accountId,
calendar.id,
);
return !preference?.hidden;
Expand Down Expand Up @@ -154,7 +154,7 @@ function CalendarPickerContent() {
{account.calendars.map((calendar) => (
<CalendarPickerItem
calendar={calendar}
key={`${calendar.accountId}-${calendar.id}`}
key={`${calendar.provider.accountId}-${calendar.id}`}
>
<CalendarPickerItemContent>
<CalendarPickerItemActionsMenu />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function CalendarRenameDialog() {
const onSubmit = () => {
mutate({
id: calendar.id,
accountId: calendar.accountId,
provider: calendar.provider,
name: name.trim(),
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useDefaultCalendar() {
return "var(--color-muted-foreground)";
}

return `var(${calendarColorVariable(data?.defaultCalendar?.accountId, data?.defaultCalendar?.id)}, var(--color-muted-foreground))`;
return `var(${calendarColorVariable(data?.defaultCalendar?.provider.accountId, data?.defaultCalendar?.id)}, var(--color-muted-foreground))`;
}, [data?.defaultCalendar]);

return React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export function useUpdateEventMutation() {
...data,
...(move?.destination
? {
accountId: move.destination.accountId,
calendarId: move.destination.calendarId,
calendar: move.destination,
}
: {}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export function useCreateDraftAction() {
...event,
type: "draft",
readOnly: false,
providerId: defaultCalendar.providerId,
accountId: defaultCalendar.accountId,
calendarId: defaultCalendar.id,
calendar: {
id: defaultCalendar.id,
provider: defaultCalendar.provider,
},
},
});

Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/calendar/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import type { RouterOutputs } from "@/lib/trpc";

export type CalendarView = "month" | "week" | "day" | "agenda";

export type CalendarEvent = RouterOutputs["events"]["list"]["events"][number];
4 changes: 2 additions & 2 deletions apps/web/src/components/calendar/utils/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export function canMoveBetweenCalendars(
destination: Calendar,
): boolean {
const isSameCalendar =
event.accountId === destination.accountId &&
event.calendarId === destination.id;
event.calendar.provider.accountId === destination.provider.accountId &&
event.calendar.id === destination.id;

if (isSameCalendar) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/command-bar/context-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { format, formatTime } from "@/lib/utils/format";

function eventColor(event: CalendarEvent) {
return {
"--calendar-color": `var(${calendarColorVariable(event.accountId, event.calendarId)}, var(--color-muted-foreground))`,
"--calendar-color": `var(${calendarColorVariable(event.calendar.provider.accountId, event.calendar.id)}, var(--color-muted-foreground))`,
} as React.CSSProperties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function EventSearchCommands() {

const color =
item.event.color ??
`var(${calendarColorVariable(item.event.accountId, item.event.calendarId)}, var(--color-muted-foreground))`;
`var(${calendarColorVariable(item.event.calendar.provider.accountId, item.event.calendar.id)}, var(--color-muted-foreground))`;

return {
...item,
Expand Down
Loading