Skip to content

Commit 890f906

Browse files
committed
fix: resolve TypeScript issues and
1 parent 01a9c56 commit 890f906

File tree

8 files changed

+41
-33
lines changed

8 files changed

+41
-33
lines changed

app/Room.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function Room({ children }: { children: ReactNode }) {
1414
cursor: null,
1515
cursorColor: null,
1616
editingText: null,
17+
message: null,
1718
}}
1819
initialStorage={{
1920
canvasObjects: new LiveMap(),

app/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export default function Home() {
7474

7575
if (!canvasObjects || canvasObjects.size === 0) return true;
7676

77-
for (const [key, value] of canvasObjects.entries()) {
77+
const entries = Array.from(canvasObjects.entries());
78+
79+
for (const [key, value] of entries) {
7880
canvasObjects.delete(key);
7981
}
8082

components/cursor/cursor-chat.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const CursorChat = ({
2424
if (e.key === "Enter") {
2525
setCursorState({
2626
mode: CursorMode.Chat,
27-
previousMessage: cursorState.message,
2827
message: "",
28+
// @ts-ignore
29+
previousMessage: cursorState.message,
2930
});
3031
} else if (e.key === "Escape") {
3132
setCursorState({ mode: CursorMode.Hidden });

components/cursor/live-cursors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const LiveCursors = ({ others }: LiveCursorProps) => {
1313
color={COLORS[Number(connectionId) % COLORS.length]}
1414
x={presence.cursor.x}
1515
y={presence.cursor.y}
16-
message={presence.message}
16+
message={presence.message || ""}
1717
/>
1818
);
1919
});

components/live.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Props = {
3333

3434
const Live = ({ canvasRef, undo, redo }: Props) => {
3535
const others = useOthers();
36-
const [{ cursor }, updateMyPresence] = useMyPresence() as any;
36+
const [{ cursor }, updateMyPresence] = useMyPresence();
3737

3838
const [cursorState, setCursorState] = useState<CursorState>({
3939
mode: CursorMode.Hidden,

constants/index.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@ import { ActiveElement } from "@/types";
22

33
export const COLORS = ["#DC2626", "#D97706", "#059669", "#7C3AED", "#DB2777"];
44

5-
type TElement =
6-
| {
7-
icon: string;
8-
name: string;
9-
value: string | TElement[];
10-
}
11-
| {
12-
icon: string;
13-
label: string;
14-
value: string;
15-
}
16-
| {
17-
label: string;
18-
value: string;
19-
};
5+
type TElement = {
6+
name: string;
7+
icon: string;
8+
value: string;
9+
label: string;
10+
};
11+
12+
type TBaseElement = Pick<TElement, "value" | "label">;
13+
type TOptionElement = TBaseElement & { icon: string };
14+
type TNavElement = Omit<TElement, "label" | "value"> & {
15+
value: string | ActiveElement[];
16+
};
2017

2118
type TShortcut = {
2219
key: string;
2320
name: string;
2421
shortcut: string;
2522
};
2623

27-
export const shapeElements: TElement[] = [
24+
export const shapeElements: ActiveElement[] = [
2825
{
2926
icon: "/assets/rectangle.svg",
3027
name: "Rectangle",
@@ -57,7 +54,7 @@ export const shapeElements: TElement[] = [
5754
},
5855
];
5956

60-
export const navElements: TElement[] = [
57+
export const navElements: TNavElement[] = [
6158
{
6259
icon: "/assets/select.svg",
6360
name: "Select",
@@ -96,19 +93,19 @@ export const defaultNavElement: ActiveElement = {
9693
value: "select",
9794
};
9895

99-
export const directionOptions: TElement[] = [
96+
export const directionOptions: TOptionElement[] = [
10097
{ label: "Bring to Front", value: "front", icon: "/assets/front.svg" },
10198
{ label: "Send to Back", value: "back", icon: "/assets/back.svg" },
10299
];
103100

104-
export const fontFamilyOptions: TElement[] = [
101+
export const fontFamilyOptions: TBaseElement[] = [
105102
{ value: "Helvetica", label: "Helvetica" },
106103
{ value: "Times New Roman", label: "Times New Roman" },
107104
{ value: "Comic Sans MS", label: "Comic Sans MS" },
108105
{ value: "Brush Script MT", label: "Brush Script MT" },
109106
];
110107

111-
export const fontSizeOptions: TElement[] = [
108+
export const fontSizeOptions: TBaseElement[] = [
112109
{
113110
value: "10",
114111
label: "10",
@@ -167,7 +164,7 @@ export const fontSizeOptions: TElement[] = [
167164
},
168165
];
169166

170-
export const fontWeightOptions: TElement[] = [
167+
export const fontWeightOptions: TBaseElement[] = [
171168
{
172169
value: "400",
173170
label: "Normal",
@@ -182,7 +179,7 @@ export const fontWeightOptions: TElement[] = [
182179
},
183180
];
184181

185-
export const alignmentOptions: TElement[] = [
182+
export const alignmentOptions: TOptionElement[] = [
186183
{ value: "left", label: "Align Left", icon: "/assets/align-left.svg" },
187184
{
188185
value: "horizontalCenter",

liveblocks.config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LiveMap, createClient } from "@liveblocks/client";
22
import { createRoomContext, createLiveblocksContext } from "@liveblocks/react";
3+
import { ReactionEvent } from "./types";
34

45
const client = createClient({
56
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY!,
@@ -50,9 +51,13 @@ const client = createClient({
5051
// Presence represents the properties that exist on every user in the Room
5152
// and that will automatically be kept in sync. Accessible through the
5253
// `user.presence` property. Must be JSON-serializable.
53-
type Presence = {
54+
export type Presence = {
5455
// cursor: { x: number, y: number } | null,
5556
// ...
57+
cursor: { x: number; y: number } | null;
58+
cursorColor: string | null;
59+
editingText: string | null;
60+
message: string | null;
5661
};
5762

5863
// Optionally, Storage represents the shared document that persists in the
@@ -75,10 +80,11 @@ type UserMeta = {
7580

7681
// Optionally, the type of custom events broadcast and listened to in this
7782
// room. Use a union for multiple events. Must be JSON-serializable.
78-
type RoomEvent = {
79-
// type: "NOTIFICATION",
80-
// ...
81-
};
83+
// type RoomEvent = {
84+
// // type: "NOTIFICATION",
85+
// // ...
86+
// };
87+
type RoomEvent = ReactionEvent;
8288

8389
// Optionally, when using Comments, ThreadMetadata represents metadata on
8490
// each thread. Can only contain booleans, strings, and numbers.

types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Presence } from "@/liveblocks.config";
12
import { BaseUserMeta, User } from "@liveblocks/client";
23
import { Gradient, Pattern } from "fabric/fabric-impl";
34

@@ -118,12 +119,12 @@ export type ShapesMenuProps = {
118119
imageInputRef: any;
119120
};
120121

121-
export type Presence = any;
122+
// export type Presence = any;
122123

123124
export type CursorProps = {
124125
color: string;
125126
x: number;
126-
y: string;
127+
y: number;
127128
message: string;
128129
};
129130

0 commit comments

Comments
 (0)