Skip to content

Commit a6cb22e

Browse files
šŸ› Fix: Disable newly created event from being editing during optimistic render cycle (#206)
* fix: disable newly created event from being editing during optimistic render cycle Prevents the event from being modified when we initially insert the event as an optimistic event * refactor: replace disabledColorByPriority map with simple darken() the previous solution worked fine, but it came with the overhead of another color map in theme.util. We're going to get away from these as we support more priorities, so this method lets us scale with more ease --------- Co-authored-by: Tyler Dane <tyler@switchback.tech>
1 parent 9cde6be commit a6cb22e

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

ā€Žpackages/web/src/views/Calendar/components/Event/Grid/GridEvent/GridEvent.tsxā€Ž

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
import { getPosition } from "@web/views/Calendar/hooks/event/getPosition";
1919
import { getLineClamp } from "@web/common/utils/grid.util";
2020
import { getTimesLabel } from "@web/common/utils/web.date.util";
21-
import { ZIndex } from "@web/common/constants/web.constants";
21+
import {
22+
ID_OPTIMISTIC_PREFIX,
23+
ZIndex,
24+
} from "@web/common/constants/web.constants";
2225
import { Text } from "@web/components/Text";
2326

2427
import { StyledEvent, StyledEventScaler, StyledEventTitle } from "../../styled";
@@ -56,6 +59,7 @@ const _GridEvent = (
5659
const { component } = weekProps;
5760

5861
const isInPast = dayjs().isAfter(dayjs(_event.endDate));
62+
const isOptimistic = _event._id?.startsWith(ID_OPTIMISTIC_PREFIX);
5963
const event = _event;
6064

6165
const position = getPosition(
@@ -79,10 +83,13 @@ const _GridEvent = (
7983
isDragging={isDragging}
8084
isInPast={isInPast}
8185
isPlaceholder={isPlaceholder}
86+
isOptimistic={isOptimistic}
8287
isResizing={isResizing}
8388
left={position.left}
8489
lineClamp={lineClamp}
8590
onMouseDown={(e) => {
91+
if (isOptimistic) return;
92+
8693
onEventMouseDown(event, e);
8794
}}
8895
priority={event.priority}

ā€Žpackages/web/src/views/Calendar/components/Event/styled.tsā€Ž

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from "styled-components";
22
import { Priority } from "@core/constants/core.constants";
3-
import { brighten } from "@core/util/color.utils";
3+
import { brighten, darken } from "@core/util/color.utils";
44
import { Text } from "@web/components/Text";
55
import { ZIndex } from "@web/common/constants/web.constants";
66
import {
@@ -17,6 +17,7 @@ interface StyledEventProps {
1717
isInPast: boolean;
1818
isResizing: boolean;
1919
isPlaceholder: boolean;
20+
isOptimistic: boolean;
2021
left: number;
2122
lineClamp: number;
2223
opacity?: number;
@@ -71,13 +72,21 @@ export const StyledEvent = styled.div.attrs<StyledEventProps>((props) => {
7172
&:hover {
7273
transition: background-color 0.35s linear;
7374
74-
${({ isPlaceholder, isResizing, hoverColor, theme }) =>
75+
${({
76+
backgroundColor,
77+
isOptimistic,
78+
isPlaceholder,
79+
isResizing,
80+
hoverColor,
81+
theme,
82+
}) =>
7583
!isPlaceholder &&
7684
!isResizing &&
7785
`
78-
background-color: ${hoverColor};
86+
background-color: ${isOptimistic ? darken(backgroundColor) : hoverColor};
87+
cursor: ${isOptimistic ? "wait" : "pointer"};
7988
drop-shadow(2px 4px 4px ${theme.color.shadow.default});
80-
`};
89+
`};
8190
}
8291
8392
&.active {

0 commit comments

Comments
Ā (0)