Skip to content

Commit

Permalink
Add infinite board (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmi authored Feb 14, 2022
1 parent 79cada9 commit 53e9c31
Show file tree
Hide file tree
Showing 33 changed files with 4,902 additions and 3,303 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const path = require("path");

const projectRootDir = path.resolve(__dirname);

module.exports = {
parser: "babel-eslint",
extends: [
"airbnb-base",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier",
"plugin:storybook/recommended",
],
root: true,
env: {
Expand All @@ -33,6 +33,12 @@ module.exports = {
],
"import/no-unresolved": "error",
"prettier/prettier": ["error"],
"react-hooks/exhaustive-deps": [
"warn",
{
additionalHooks: "(useRecoilCallback|useRecoilTransaction_UNSTABLE)",
},
],
},
settings: {
"import/resolver": {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ build
/coverage/
/lib/
/dist/
storybook-static/

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
6,182 changes: 3,751 additions & 2,431 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"@rollup/plugin-image": "^2.0.6",
"@rollup/plugin-node-resolve": "^13.0.0",
"@scripters/use-socket.io": "git+https://github.com/jrmi/use-socket.io.git#updated",
"@storybook/addon-actions": "^6.3.4",
"@storybook/addon-essentials": "^6.3.4",
"@storybook/addon-links": "^6.3.4",
"@storybook/react": "^6.3.4",
"@storybook/addon-actions": "^6.4.17",
"@storybook/addon-essentials": "^6.4.17",
"@storybook/addon-links": "^6.4.17",
"@storybook/react": "^6.4.17",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.3.0",
"babel-loader": "^8.1.0",
Expand All @@ -53,6 +53,7 @@
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-storybook": "^0.5.6",
"final-form": "^4.20.2",
"jest": "^27.0.5",
"postcss-preset-env": "^6.7.0",
Expand All @@ -78,12 +79,11 @@
"dependencies": {
"@emotion/react": "^11.4.0",
"@emotion/styled": "^11.3.0",
"@react-hookz/web": "^12.3.0",
"color2k": "^1.2.4",
"dayjs": "^1.10.5",
"fast-deep-equal": "^3.1.3",
"lodash.debounce": "^4.0.8",
"lodash.findlast": "^4.6.0",
"lodash.throttle": "^4.1.1",
"nanoid": "^3.1.23",
"randomcolor": "^0.6.2"
},
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import alias from "@rollup/plugin-alias";
import path from "path";
import css from "rollup-plugin-css-only";
import pkg from "./package.json";
// import analyze from "rollup-plugin-analyzer";
import analyze from "rollup-plugin-analyzer";

const projectRootDir = path.resolve(__dirname);

Expand Down Expand Up @@ -62,7 +62,7 @@ export default [
}),
css({ output: "bundle.css" }),
image(),
// analyze({ summaryOnly: true }),
analyze({ summaryOnly: true }),
],
output: [
{
Expand Down
38 changes: 29 additions & 9 deletions src/BoardWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import styled from "@emotion/styled";
import { RecoilRoot, useSetRecoilState, useRecoilState } from "recoil";
import { nanoid } from "nanoid";
import { useResizeObserver } from "@react-hookz/web/esm";

import useWire, { WireProvider } from "@/hooks/useWire";

Expand All @@ -16,18 +17,16 @@ import { insideClass } from "./utils";
const StyledBoardView = styled.div`
overflow: hidden;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
inset: 0;
`;

const SyncBoard = ({ children, style }) => {
const boardWrapperRef = React.useRef(null);
const setCurrentUserState = useSetRecoilState(userAtom);

const { room: session } = useWire("board");

const [{ uid }, setSettings] = useRecoilState(ConfigurationAtom);
const [{ uid }, setConfiguration] = useRecoilState(ConfigurationAtom);

React.useEffect(() => {
// Chrome-related issue.
Expand Down Expand Up @@ -60,14 +59,35 @@ const SyncBoard = ({ children, style }) => {
}, [session, setCurrentUserState]);

React.useEffect(() => {
setSettings((prev) => ({
if (!uid) {
setConfiguration((prev) => ({
...prev,
uid: nanoid(),
}));
}
}, [setConfiguration, uid]);

React.useEffect(() => {
setConfiguration((prev) => ({
...prev,
uid: nanoid(),
boardWrapper: boardWrapperRef.current,
}));
}, [setSettings]);
}, [setConfiguration, uid]);

useResizeObserver(boardWrapperRef, () =>
setConfiguration((prev) => ({
...prev,
boardWrapperRect: boardWrapperRef.current.getBoundingClientRect(),
}))
);

return (
<StyledBoardView id={uid} className="sync-board" style={style}>
<StyledBoardView
ref={boardWrapperRef}
id={uid}
className="sync-board"
style={style}
>
{children}
</StyledBoardView>
);
Expand Down
Loading

0 comments on commit 53e9c31

Please sign in to comment.