diff --git a/package-lock.json b/package-lock.json index 2b943ee..6017c96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "date-fns": "^3.6.0", "jwt-decode": "^4.0.0", "react": "^18.2.0", + "react-brackets": "^0.4.7", "react-dom": "^18.2.0", "react-image-picker-editor": "^1.3.3", "react-paginate": "^8.2.0", @@ -2598,6 +2599,11 @@ } } }, + "node_modules/@emotion/stylis": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/@emotion/stylis/-/stylis-0.8.5.tgz", + "integrity": "sha512-h6KtPihKFn3T9fuIrwvXXUOwlx3rfUvfZIcP5a6rh8Y7zjE3O06hT5Ss4S/YI1AYhuZ1kjaE/5EaOOI2NqSylQ==" + }, "node_modules/@emotion/unitless": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.8.1.tgz", @@ -4180,104 +4186,6 @@ "url": "https://github.com/sponsors/gregberge" } }, - "node_modules/@testing-library/dom": { - "version": "9.3.3", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.3.tgz", - "integrity": "sha512-fB0R+fa3AUqbLHWyxXa2kGVtf1Fe1ZZFr0Zp6AIbIAzXb2mKbEXl+PCQNUOaq5lbTab5tfctfXRNsWXxa2f7Aw==", - "peer": true, - "dependencies": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/@testing-library/dom/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "peer": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@testing-library/dom/node_modules/aria-query": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.1.3.tgz", - "integrity": "sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ==", - "peer": true, - "dependencies": { - "deep-equal": "^2.0.5" - } - }, - "node_modules/@testing-library/dom/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "peer": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@testing-library/dom/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "peer": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@testing-library/dom/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "peer": true - }, - "node_modules/@testing-library/dom/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "peer": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/@testing-library/dom/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "peer": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@testing-library/jest-dom": { "version": "5.17.0", "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", @@ -6773,6 +6681,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/camelize": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.1.tgz", + "integrity": "sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/caniuse-api": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz", @@ -7330,6 +7246,14 @@ "postcss": "^8.4" } }, + "node_modules/css-color-keywords": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz", + "integrity": "sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==", + "engines": { + "node": ">=4" + } + }, "node_modules/css-declaration-sorter": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.4.1.tgz", @@ -7520,6 +7444,16 @@ "resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz", "integrity": "sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w==" }, + "node_modules/css-to-react-native": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.2.0.tgz", + "integrity": "sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==", + "dependencies": { + "camelize": "^1.0.0", + "css-color-keywords": "^1.0.0", + "postcss-value-parser": "^4.0.2" + } + }, "node_modules/css-tree": { "version": "1.0.0-alpha.37", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.37.tgz", @@ -13919,6 +13853,11 @@ "node": ">=18" } }, + "node_modules/keycode": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/keycode/-/keycode-2.2.1.tgz", + "integrity": "sha512-Rdgz9Hl9Iv4QKi8b0OlCRQEzp4AgVxyCtz5S/+VIHezDmrDhkp2N2TqBWOLz0/gbeREXOOiI9/4b8BY9uw2vFg==" + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -16913,6 +16852,103 @@ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, + "node_modules/react-brackets": { + "version": "0.4.7", + "resolved": "https://registry.npmjs.org/react-brackets/-/react-brackets-0.4.7.tgz", + "integrity": "sha512-5NynHxC32gEe9vuLQJvD2JEtHXg2gI0R6MWVD+uSYhQCAlEdwlKbFWNdrP5MIt1buyxrs2F/tr1EIW6+eBCocw==", + "dependencies": { + "react-swipeable-views": "^0.13.9", + "styled-components": "^5.1.1" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": "^17.0.0", + "react-swipeable-views": "^0.13.9", + "styled-components": "^5.1.1" + } + }, + "node_modules/react-brackets/node_modules/@babel/runtime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0.tgz", + "integrity": "sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==", + "dependencies": { + "regenerator-runtime": "^0.12.0" + } + }, + "node_modules/react-brackets/node_modules/@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "node_modules/react-brackets/node_modules/react-swipeable-views": { + "version": "0.13.9", + "resolved": "https://registry.npmjs.org/react-swipeable-views/-/react-swipeable-views-0.13.9.tgz", + "integrity": "sha512-WXC2FKYvZ9QdJ31v9LjEJEl1bA7E4AcaloTkbW0uU0dYf5uvv4aOpiyxubvOkVl1a5L2UAHmKSif4TmJ9usrSg==", + "dependencies": { + "@babel/runtime": "7.0.0", + "prop-types": "^15.5.4", + "react-swipeable-views-core": "^0.13.7", + "react-swipeable-views-utils": "^0.13.9", + "warning": "^4.0.1" + }, + "engines": { + "node": ">=6.0.0" + }, + "peerDependencies": { + "react": "^15.3.0 || ^16.0.0" + } + }, + "node_modules/react-brackets/node_modules/regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + }, + "node_modules/react-brackets/node_modules/styled-components": { + "version": "5.3.11", + "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.11.tgz", + "integrity": "sha512-uuzIIfnVkagcVHv9nE0VPlHPSCmXIUGKfJ42LNjxCCTDTL5sgnJ8Z7GZBq0EnLYGln77tPpEpExt2+qa+cZqSw==", + "dependencies": { + "@babel/helper-module-imports": "^7.0.0", + "@babel/traverse": "^7.4.5", + "@emotion/is-prop-valid": "^1.1.0", + "@emotion/stylis": "^0.8.4", + "@emotion/unitless": "^0.7.4", + "babel-plugin-styled-components": ">= 1.12.0", + "css-to-react-native": "^3.0.0", + "hoist-non-react-statics": "^3.0.0", + "shallowequal": "^1.1.0", + "supports-color": "^5.5.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/styled-components" + }, + "peerDependencies": { + "react": ">= 16.8.0", + "react-dom": ">= 16.8.0", + "react-is": ">= 16.8.0" + } + }, + "node_modules/react-brackets/node_modules/styled-components/node_modules/babel-plugin-styled-components": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.1.4.tgz", + "integrity": "sha512-Xgp9g+A/cG47sUyRwwYxGM4bR/jDRg5N6it/8+HxCnbT5XNKSKDT9xm4oag/osgqjC2It/vH0yXsomOG6k558g==", + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-module-imports": "^7.22.5", + "@babel/plugin-syntax-jsx": "^7.22.5", + "lodash": "^4.17.21", + "picomatch": "^2.3.1" + }, + "peerDependencies": { + "styled-components": ">= 2" + } + }, "node_modules/react-dev-utils": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz", @@ -17242,6 +17278,89 @@ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" } }, + "node_modules/react-swipeable-views-core": { + "version": "0.13.7", + "resolved": "https://registry.npmjs.org/react-swipeable-views-core/-/react-swipeable-views-core-0.13.7.tgz", + "integrity": "sha512-ekn9oDYfBt0oqJSGGwLEhKvn+QaqMGTy//9dURTLf+vp7W5j6GvmKryYdnwJCDITaPFI2hujXV4CH9krhvaE5w==", + "dependencies": { + "@babel/runtime": "7.0.0", + "warning": "^4.0.1" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/react-swipeable-views-core/node_modules/@babel/runtime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0.tgz", + "integrity": "sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==", + "dependencies": { + "regenerator-runtime": "^0.12.0" + } + }, + "node_modules/react-swipeable-views-core/node_modules/regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + }, + "node_modules/react-swipeable-views-utils": { + "version": "0.13.9", + "resolved": "https://registry.npmjs.org/react-swipeable-views-utils/-/react-swipeable-views-utils-0.13.9.tgz", + "integrity": "sha512-QLGxRKrbJCbWz94vkWLzb1Daaa2Y/TZKmsNKQ6WSNrS+chrlfZ3z9tqZ7YUJlW6pRWp3QZdLSY3UE3cN0TXXmw==", + "dependencies": { + "@babel/runtime": "7.0.0", + "keycode": "^2.1.7", + "prop-types": "^15.6.0", + "react-event-listener": "^0.6.0", + "react-swipeable-views-core": "^0.13.7", + "shallow-equal": "^1.2.1" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/react-swipeable-views-utils/node_modules/@babel/runtime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0.tgz", + "integrity": "sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==", + "dependencies": { + "regenerator-runtime": "^0.12.0" + } + }, + "node_modules/react-swipeable-views-utils/node_modules/react-event-listener": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/react-event-listener/-/react-event-listener-0.6.6.tgz", + "integrity": "sha512-+hCNqfy7o9wvO6UgjqFmBzARJS7qrNoda0VqzvOuioEpoEXKutiKuv92dSz6kP7rYLmyHPyYNLesi5t/aH1gfw==", + "dependencies": { + "@babel/runtime": "^7.2.0", + "prop-types": "^15.6.0", + "warning": "^4.0.1" + }, + "peerDependencies": { + "react": "^16.3.0" + } + }, + "node_modules/react-swipeable-views-utils/node_modules/react-event-listener/node_modules/@babel/runtime": { + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.5.tgz", + "integrity": "sha512-Nms86NXrsaeU9vbBJKni6gXiEXZ4CVpYVzEjDH9Sb8vmZ3UljyA1GSOJl/6LGPO8EHLuSF9H+IxNXHPX8QHJ4g==", + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/react-swipeable-views-utils/node_modules/react-event-listener/node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + }, + "node_modules/react-swipeable-views-utils/node_modules/regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + }, "node_modules/react-transition-group": { "version": "4.4.5", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", @@ -18212,6 +18331,16 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "node_modules/shallow-equal": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/shallow-equal/-/shallow-equal-1.2.1.tgz", + "integrity": "sha512-S4vJDjHHMBaiZuT9NPb616CSmLf618jawtv3sufLl6ivK8WocjAo58cXwbRV1cgqxH0Qbv+iUt6m05eqEa2IRA==" + }, + "node_modules/shallowequal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz", + "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==" + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -19822,19 +19951,6 @@ "is-typedarray": "^1.0.0" } }, - "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -20144,6 +20260,14 @@ "makeerror": "1.0.12" } }, + "node_modules/warning": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz", + "integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==", + "dependencies": { + "loose-envify": "^1.0.0" + } + }, "node_modules/watchpack": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", diff --git a/package.json b/package.json index 224eea4..258d9af 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "date-fns": "^3.6.0", "jwt-decode": "^4.0.0", "react": "^18.2.0", + "react-brackets": "^0.4.7", "react-dom": "^18.2.0", "react-image-picker-editor": "^1.3.3", "react-paginate": "^8.2.0", diff --git a/src/elements/Ladder/Ladder.js b/src/elements/Ladder/Ladder.js new file mode 100644 index 0000000..8576b93 --- /dev/null +++ b/src/elements/Ladder/Ladder.js @@ -0,0 +1,134 @@ +import { useEffect, useState } from "react" +import { Bracket } from 'react-brackets'; + +const buildRounds = function (json) { + console.log("before") + console.log(json); + let result = json.data; + let temp = []; + result.sort((a, b) => (a.position-b.position)); + const minPosition = result[0].position; + const maxPosition = result[result.length - 1].position; + const heapSize = Math.pow(2, Math.ceil(Math.log2(maxPosition))) - 1; + console.log(result); + for (let i = 0; i < minPosition; i++) { + temp.push({ + id: i, + date: new Date().toDateString(), + teams: [{ name: 'Its a me' }, { name: 'Mario ' + i }], + }); + }; + temp = temp.concat(result); + let tail = heapSize - temp.length; + for (let i = 0; i < tail; i++) { + temp.push({ + id: i + maxPosition + 1, + date: new Date().toDateString(), + teams: [{ name: 'Its a me' }, { name: 'Luigi ' + i }], + }); + } + + result = temp; + + result = result.map(element => { + if (element.botId) element.teams = element.botId.map((id) => {return {name: id}}); + if (!element.status) element.status = "NotReadyToPlay"; + if (!element.winner) element.winner = -1; + if (!element.playedOutDate) element.playedOutDate = "0001-01-01T00:00:00"; + if (!element.position) element.position = element.id; + return element; + }); + + temp = []; + let cursor = -1; + for (let i = result.length - 1; i >= 0 ; i--) { + if (Number.isInteger(Math.log2(i + 2))) { + + temp.push([]); + cursor++; + } + temp[cursor].push(result[i]); + } + result = temp; + + result = result.map((round, index) => { + return { + title: 'Round ' + (index + 1), + seeds: round, + }; + }); + console.log("after") + console.log(result); + return result; +} + +const buildRounds1 = function (json) { + console.log("before") + console.log(json); + let result = json.data; + let temp = []; + result.sort((a, b) => (b.position-a.position)); + const maxPosition = result[0].position; + const minPosition = result[result.length - 1].position; + const heapSize = Math.pow(2, Math.ceil(Math.log2(maxPosition))) - 1; + + for (let i = 0; i < minPosition; i++) { + temp.push({ + id: i, + date: new Date().toDateString(), + teams: [{ name: 'Its a me' }, { name: 'Mario ' + i }], + }); + }; + temp = temp.concat(result); + let tail = heapSize - temp.length; + for (let i = 0; i < tail; i++) { + temp.push({ + id: i + maxPosition + 1, + date: new Date().toDateString(), + teams: [{ name: 'Its a me' }, { name: 'Luigi ' + i }], + }); + } + + result = temp; + + result = result.map(element => { + if (element.botId) element.teams = element.botId.map((id) => {return {name: id}}); + if (!element.status) element.status = "NotReadyToPlay"; + if (!element.winner) element.winner = -1; + if (!element.playedOutDate) element.playedOutDate = "0001-01-01T00:00:00"; + if (!element.position) element.position = element.id; + return element; + }); + + temp = []; + let cursor = -1; + for (let i = result.length; i >= 0; i--) { + if (Number.isInteger(Math.log2(i + 1))) { + temp.push([]); + cursor++; + } + temp[cursor].push(result[i]); + } + result = temp; + + result = result.map((round, index) => { + return { + title: 'Round ' + (index + 1), + seeds: round, + }; + }); + console.log("after") + console.log(result); + return result; +} + +export default function Ladder({status}){ + const [rounds, setRounds] = useState([]); + useEffect(() => { + setRounds(buildRounds(status)); + }, [status]); + + return (<> + + ) +} \ No newline at end of file diff --git a/src/elements/Ladder/Temp.js b/src/elements/Ladder/Temp.js new file mode 100644 index 0000000..64417e8 --- /dev/null +++ b/src/elements/Ladder/Temp.js @@ -0,0 +1,27 @@ +import { useState } from "react" +import Ladder from "./Ladder"; + +export default function Temp(){ + const games = [{ "data": [ { "botId": [ 8, 5 ], "status": "Playing", "winner": -1, "position": 4, "playedOutDate": "0001-01-01T00:00:00" }, { "botId": [ 7, 1 ], "status": "Playing", "winner": -1, "position": 3, "playedOutDate": "0001-01-01T00:00:00" }, { "botId": [ 9, 2 ], "status": "Playing", "winner": -1, "position": 5, "playedOutDate": "0001-01-01T00:00:00" }, { "botId": [ 6 ], "status": "NotReadyToPlay", "winner": -1, "position": 2, "playedOutDate": "0001-01-01T00:00:00" } ]}, + { "data": [ { "botId": [ 8, 5 ], "status": "Played", "winner": 5, "position": 4, "playedOutDate": "2024-05-23T14:30:16.757158" }, { "botId": [ 7, 1 ], "status": "Playing", "winner": -1, "position": 3, "playedOutDate": "0001-01-01T00:00:00" }, { "botId": [ 9, 2 ], "status": "Played", "winner": 2, "position": 5, "playedOutDate": "2024-05-23T14:30:16.538882" }, { "botId": [ 6 ], "status": "NotReadyToPlay", "winner": -1, "position": 2, "playedOutDate": "0001-01-01T00:00:00" } ]}, + { "data": [ { "botId": [ 8, 5 ], "status": "Played", "winner": 5, "position": 4, "playedOutDate": "2024-05-23T14:30:16.757158" }, { "botId": [ 7, 1 ], "status": "Played", "winner": 7, "position": 3, "playedOutDate": "2024-05-23T14:30:17.4027264" }, { "botId": [ 9, 2 ], "status": "Played", "winner": 2, "position": 5, "playedOutDate": "2024-05-23T14:30:16.538882" }, { "botId": [ 6 ], "status": "NotReadyToPlay", "winner": -1, "position": 2, "playedOutDate": "0001-01-01T00:00:00" } ]}, + { "data": [ { "botId": [ 8, 5 ], "status": "Resolve", "winner": 5, "position": 4, "playedOutDate": "2024-05-23T14:30:16.757158" }, { "botId": [ 7, 1 ], "status": "Resolve", "winner": 7, "position": 3, "playedOutDate": "2024-05-23T14:30:17.4027264" }, { "botId": [ 9, 2 ], "status": "Resolve", "winner": 2, "position": 5, "playedOutDate": "2024-05-23T14:30:16.538882" }, { "botId": [ 6, 2 ], "status": "Playing", "winner": -1, "position": 2, "playedOutDate": "0001-01-01T00:00:00" }, { "botId": [ 5, 7 ], "status": "Playing", "winner": -1, "position": 1, "playedOutDate": "0001-01-01T00:00:00" } ]}, + { "data": [ { "botId": [ 8, 5 ], "status": "Resolve", "winner": 5, "position": 4, "playedOutDate": "2024-05-23T14:30:16.757158" }, { "botId": [ 7, 1 ], "status": "Resolve", "winner": 7, "position": 3, "playedOutDate": "2024-05-23T14:30:17.4027264" }, { "botId": [ 9, 2 ], "status": "Resolve", "winner": 2, "position": 5, "playedOutDate": "2024-05-23T14:30:16.538882" }, { "botId": [ 6, 2 ], "status": "Resolve", "winner": 2, "position": 2, "playedOutDate": "2024-05-23T14:30:46.5770369" }, { "botId": [ 5, 7 ], "status": "Resolve", "winner": 7, "position": 1, "playedOutDate": "2024-05-23T14:30:44.3453841" }, { "botId": [ 2, 7 ], "status": "Playing", "winner": -1, "position": 0, "playedOutDate": "0001-01-01T00:00:00" } ]}, + { "data": [ { "botId": [ 8, 5 ], "status": "Resolve", "winner": 5, "position": 4, "playedOutDate": "2024-05-23T14:30:16.757158" }, { "botId": [ 7, 1 ], "status": "Resolve", "winner": 7, "position": 3, "playedOutDate": "2024-05-23T14:30:17.4027264" }, { "botId": [ 9, 2 ], "status": "Resolve", "winner": 2, "position": 5, "playedOutDate": "2024-05-23T14:30:16.538882" }, { "botId": [ 6, 2 ], "status": "Resolve", "winner": 2, "position": 2, "playedOutDate": "2024-05-23T14:30:46.5770369" }, { "botId": [ 5, 7 ], "status": "Resolve", "winner": 7, "position": 1, "playedOutDate": "2024-05-23T14:30:44.3453841" }, { "botId": [ 2, 7 ], "status": "Played", "winner": 7, "position": 0, "playedOutDate": "2024-05-23T14:31:05.9817403" } ]}]; + + const [index, setIndex] = useState(0); + const [status, setStatus] = useState(games[index]); + + return (<> + + +

{index}

+ + ) +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 16b9b21..18f6767 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,8 @@ import { getListOfTournaments } from './Tournaments/getListOfTournaments'; import UserSettings from './User/Settings/UserSettings'; import AnimatedBackground from "./AnimatedBackground"; +import Temp from "./elements/Ladder/Temp"; + const games = [{name:'Szachy', id:1}, {name:'Warcaby', id:2}, {name:'Scrabble', id:3}, {name:'ChiƄczyk', id:4}, {name:'Go', id:5}] const tournaments = getListOfTournaments(); @@ -119,6 +121,10 @@ const router = createBrowserRouter([ path: "/admin/PlayerTournaments", element: , }, + { + path: "/temp", + element: , + } ]);