Skip to content

Commit

Permalink
Merge branch 'master' into draw
Browse files Browse the repository at this point in the history
  • Loading branch information
VanshikaSabharwal authored May 17, 2024
2 parents d1526d2 + c685fc0 commit 1a42fac
Show file tree
Hide file tree
Showing 15 changed files with 979 additions and 1,097 deletions.
34 changes: 16 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ module.exports = {
"next",
"prettier",
],
overrides: [
{
plugins: ["react", "@typescript-eslint"],
files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
parser: "@typescript-eslint/parser",
overrides : [
{ plugins: ["react", "@typescript-eslint"],
files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
parser: "@typescript-eslint/parser",

rules: {
"react/no-direct-mutation-state": [
"error", // Keep the default as error
{
ignoreCallbacks: true, // Allow mutation within callbacks (optional)
mutators: ["this.setState"], // Allow mutation using this.setState (optional)
},
],
"react/no-unescaped-entities": "off",
"@next/next/no-page-custom-font": "off",

rules: {
"react/no-direct-mutation-state": [
"error", // Keep the default as error
{
ignoreCallbacks: true, // Allow mutation within callbacks (optional)
mutators: ["this.setState"], // Allow mutation using this.setState (optional)
},
},
],
],
"react/no-unescaped-entities": "off",
"@next/next/no-page-custom-font": "off",
},}],
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand All @@ -38,4 +36,4 @@ module.exports = {
sourceType: "module",
},
};
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
16 changes: 6 additions & 10 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
. "$(dirname -- "$0")/_/husky.sh"

# check jest standards
#uncomment when writting test cases in __test__ file
# npm run test ||
# (
# echo 'Jest test failed. '
# false;
# )



npm run test ||
(
echo 'Jest test failed. '
false;
)
# check prettier standards
npm run check-format ||
(
Expand All @@ -24,4 +20,4 @@ npm run check-lint ||
echo 'eslint check failed. '
false;
)
echo 'All Done I am committing this now'
echo 'All Done I am committing this now'
7 changes: 1 addition & 6 deletions app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Toaster } from "@/components/ui/toaster";
import { Inter } from "next/font/google";
import "./globals.css";
import { Analytics } from "@vercel/analytics/react";
import PropTypes from "prop-types";
import React from "react";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -22,7 +20,4 @@ export default function RootLayout({ children }) {
</body>
</html>
);
}
RootLayout.propTypes = {
children: PropTypes.node.isRequired, // This validates that children is of type node and is required
};
}
3 changes: 1 addition & 2 deletions app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Provider } from "react-redux";
import store from "./store";
import App from "@/components/app";
import React from "react";

export default function Home() {
return (
Expand All @@ -13,4 +12,4 @@ export default function Home() {
</Provider>
</main>
);
}
}
48 changes: 32 additions & 16 deletions components/Drawing/Drawing.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

import store from "@/app/store";
import { drawBounds } from "../ElementManipulation/Bounds";
import {
getElementObject,
updateElement,
} from "../ElementManipulation/Element";
import { getElementObject, updateElement } from "../ElementManipulation/Element";
import { ShapeCache } from "../Redux/ShapeCache";






export const draw = (event) => {
const histIndex = store.getState().elements.index;
const elements = store.getState().elements.value[histIndex][0];
Expand All @@ -16,74 +19,87 @@ export const draw = (event) => {

const { id, x1, y1, type } = elements[index];

updateElement(id, x1, y1, event.clientX, event.clientY, type);
updateElement(id, x1, y1, event.clientX, event.clientY, type)
}
};
}

// the main function that is responsilbe for rendering
export const drawElements = (ctx, element) => {

const roughCanvasRef = store.getState().canvas.value;




switch (element.type) {
case "line":
case "rectangle":
case "ellipse":
case "diamond":
if (ShapeCache.cache.has(element)) {


roughCanvasRef.draw(ShapeCache.cache.get(element));
} else {

roughCanvasRef.draw(getElementObject(element));
}
break;

case "pencil":
case 'pencil':
ctx.fillStyle = element.stroke;
if (ShapeCache.cache.has(element)) {

ctx.fill(ShapeCache.cache.get(element));
} else {
ctx.fill(getElementObject(element));
}

break;


case "text":

ctx.textBaseline = "top";
ctx.font = `${element.fontSize}px Virgil`;

var txt = element.text;

var lineheight = element.fontSize + 6;
var lines = txt.split("\n");
var lines = txt.split('\n');
ctx.fillStyle = element.stroke;
for (var i = 0; i < lines.length; i++)
ctx.fillText(lines[i], element.x1, element.y1 + 6 + i * lineheight);
ctx.fillText(lines[i], element.x1, element.y1 + 6 + (i * lineheight));
break;

default:
break;
}
};
}


export const renderer = (ctx, elements, selectedElement, action, scale) => {

let boundedElement = null;

elements.forEach((element) => {

if (element === null) {
return;
}
if (selectedElement != null && selectedElement.id === element.id) {
boundedElement = element;
}
if (
action === "writing" &&
selectedElement != null &&
selectedElement.id === element.id
) {
if (action === 'writing' && selectedElement != null && selectedElement.id === element.id) {
return;
}

drawElements(ctx, element, selectedElement);

});



drawBounds(ctx, boundedElement, action, scale);
};

}
Loading

0 comments on commit 1a42fac

Please sign in to comment.