Skip to content

Commit

Permalink
canvas completed, some bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
elmurodvokhidov committed Feb 29, 2024
1 parent 520aa37 commit f7353db
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 17 deletions.
32 changes: 31 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
"use client"

import { fabric } from "fabric";
import LeftSidebar from "@/components/LeftSidebar";
import Live from "@/components/Live";
import Navbar from "@/components/Navbar";
import RightSidebar from "@/components/RightSidebar";
import { useEffect, useRef } from "react";
import { handleCanvasMouseDown, handleResize, initializeFabric } from "@/lib/canvas";

export default function Page() {
const canvasRef = useRef<HTMLCanvasElement>(null);
const fabricRef = useRef<fabric.Canvas | null>(null);
const isDrawing = useRef(false);
const shapeRef = useRef<fabric.Object | null>(null);
const selectedShapeRef = useRef<string | null>("rectangle");

useEffect(() => {
const canvas = initializeFabric({
canvasRef,
fabricRef,
});

canvas.on("mouse:down", (options) => {
handleCanvasMouseDown({
options,
canvas,
selectedShapeRef,
isDrawing,
shapeRef,
});
});

window.addEventListener("resize", () => {
handleResize({ fabricRef })
});
}, []);

return (
<main className="h-screen overflow-hidden">
<Navbar />

<section className="h-full flex flex-row">
<LeftSidebar />
<Live />
<Live canvasRef={canvasRef} />
<RightSidebar />
</section>
</main>
Expand Down
9 changes: 8 additions & 1 deletion components/Live.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import ReactionSelector from "./reaction/ReactionButton";
import FlyingReaction from "./reaction/FlyingReaction";
import useInterval from "@/hooks/useInterval";

const Live = () => {
type Props = {
canvasRef: React.MutableRefObject<HTMLCanvasElement | null>
}

const Live = ({ canvasRef }: Props) => {
const others = useOthers();
const [{ cursor }, updateMyPresence] = useMyPresence() as any;

Expand Down Expand Up @@ -118,12 +122,15 @@ const Live = () => {

return (
<div
id="canvas"
onPointerMove={handlePointerMove}
onPointerLeave={handlePointerLeave}
onPointerDown={handlePointerDown}
onPointerUp={handlePointerUp}
className="w-full h-screen flex justify-center items-center text-center"
>
<canvas ref={canvasRef} />

{reactions.map((reaction) => (
<FlyingReaction
key={reaction.timestamp.toString()}
Expand Down
2 changes: 1 addition & 1 deletion lib/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,4 @@ export const handleCanvasZoom = ({

options.e.preventDefault();
options.e.stopPropagation();
};
};
34 changes: 23 additions & 11 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.externals.push({
"utf-8-validate": "commonjs utf-8-validate",
bufferutil: "commonjs bufferutil",
canvas: "commonjs canvas",
});
// config.infrastructureLogging = { debug: /PackFileCache/ };
return config;
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "liveblocks.io",
port: ""
}
]
}
};

export default nextConfig;
remotePatterns: [
{
protocol: "https",
hostname: "liveblocks.io",
port: "",
},
],
},
typescript: {
ignoreBuildErrors: true,
},
};

export default nextConfig;
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/fabric": "^5.3.7",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/uuid": "^9.0.8",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.0",
Expand Down
16 changes: 13 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"forceConsistentCasingInFileNames": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"target": "es2018",
"typeRoots": ["./types"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/types/**/*.tsx",
"./types/**/*.d.ts"
],
"exclude": ["node_modules"]
}
}

0 comments on commit f7353db

Please sign in to comment.