Skip to content

Commit 49fe969

Browse files
authored
Merge branch 'master' into 2398-dojoadminpage-create-the-page-for-adding-lessons
2 parents f583f28 + c2f5814 commit 49fe969

File tree

5 files changed

+219
-146
lines changed

5 files changed

+219
-146
lines changed

components/DiffView.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ describe('DiffView component', () => {
101101
)
102102
expect(screen.getByText('js7/1.c')).toBeVisible()
103103
})
104+
test('Should set JSX syntax if language is HTML', async () => {
105+
const cDiff =
106+
"diff --git a/js5/public/index.html b/js5/public/index.html\nnew file mode 100644\nindex 0000000..9d4ae75\n--- /dev/null\n+++ b/js5/public/index.html\n@@ -0,0 +1,142 @@\n+<html>\n+\n+<head>\n+ <meta charset=\"UTF-8\">\n+ <link rel=\"stylesheet\" type=\"text/css\" href=\"4.css\">\n+</head>\n+\n+<body>\n+ <div class=\"container\">\n+ </div>\n+<script>\n+ const container = document.querySelector('.container');\n+\n+function CreateLightsOff(value) {\n+ this.value = value;\n+ this.colsElements = [];\n+\n+ // All marks counter used for winning condition\n+ this.marks = 1;\n+\n+ const changeMark = neighborElement => {\n+ if (neighborElement.value.includes('mark')) {\n+ neighborElement.remove('mark');\n+ this.marks -= 1;\n+ } else {\n+ neighborElement.add('mark');\n+ this.marks += 1;\n+ }\n+ };\n+\n+ const allMarked = () => {\n+ if (this.value * this.value - this.marks === this.value * this.value) {\n+ const answer = parseInt(\n+ prompt(\n+ 'Congrats! Type your next challenge number: (type 0 to stop playing)'\n+ )\n+ );\n+\n+ // Returns NaN (for other types) or number\n+ if (answer) {\n+ container.innerHTML = '';\n+ CreateLightsOff(answer);\n+ }\n+ }\n+ };\n+\n+ const modifyColsElements = (index, currentCol) => {\n+ const currentElementClass = this.colsElements[currentCol].children[index]\n+ .classList;\n+\n+ if (!currentElementClass.value.includes('mark')) {\n+ return;\n+ }\n+\n+ let topNeighbor;\n+\n+ if (this.colsElements[currentCol - 1]) {\n+ topNeighbor = this.colsElements[currentCol - 1].children[index].classList;\n+ changeMark(topNeighbor);\n+ }\n+\n+ let bottomNeighbor;\n+\n+ if (this.colsElements[currentCol + 1]) {\n+ bottomNeighbor = this.colsElements[currentCol + 1].children[index]\n+ .classList;\n+ changeMark(bottomNeighbor);\n+ }\n+\n+ let rightNeighbor;\n+\n+ if (this.colsElements[currentCol].children[index + 1]) {\n+ rightNeighbor = this.colsElements[currentCol].children[index + 1]\n+ .classList;\n+ changeMark(rightNeighbor);\n+ }\n+\n+ let leftNeighbor;\n+\n+ if (this.colsElements[currentCol].children[index - 1]) {\n+ leftNeighbor = this.colsElements[currentCol].children[index - 1]\n+ .classList;\n+ changeMark(leftNeighbor);\n+ }\n+\n+ currentElementClass.remove('mark');\n+ this.marks -= 1;\n+\n+ allMarked();\n+ };\n+\n+ const generateRows = (colCount, currentCol, i = 0, rows = []) => {\n+ if (i === colCount) return rows;\n+\n+ const block = document.createElement('div');\n+ block.classList.add('block');\n+\n+ block.addEventListener('click', () => {\n+ modifyColsElements(i, currentCol);\n+ });\n+\n+ rows.push(block);\n+\n+ return generateRows(colCount, currentCol, i + 1, rows);\n+ };\n+\n+ const generateColumns = (\n+ col,\n+ i = 0,\n+ randomIndex = Math.floor(Math.random() * col)\n+ ) => {\n+ if (i === col) return;\n+\n+ const rows = generateRows(col, i);\n+\n+ const colContainer = document.createElement('div');\n+ colContainer.classList.add('row', `row-${i}`);\n+\n+ rows.forEach(e => colContainer.append(e));\n+\n+ if (i === randomIndex) {\n+ const colChildren = colContainer.children;\n+ colChildren[randomIndex].classList.add('mark');\n+ }\n+\n+ this.colsElements.push(colContainer);\n+\n+ container.append(colContainer);\n+\n+ return generateColumns(col, i + 1, randomIndex);\n+ };\n+\n+ if (this.value) {\n+ generateColumns(this.value);\n+ }\n+}\n+\n+const g = new CreateLightsOff(2);\n+</script>\n+</body>\n+\n+</html>\n"
107+
render(
108+
<DiffView
109+
submission={{ ...dummySumissions[0], diff: cDiff, comments: undefined }}
110+
generalStatus={SubmissionStatus.Open}
111+
/>
112+
)
113+
expect(screen.getAllByText('CreateLightsOff')[0]).toHaveStyle({
114+
color: 'rgb(221, 74, 104);'
115+
})
116+
})
104117
test('Should do nothing with incorrect diff', () => {
105118
const incorrectDiff =
106119
'diff --git \nindex 9c96b34..853bddf 100644\n---@@ -1,8 +1,19 @@\n-// write your code here!\n const solution = () => {\n- // global clear all timeout:\n+ const allT = [];\n+ const old = setTimeout;\n+ window.setTimeout = (func, delay) => {\n+ const realTimeout = old(func, delay);\n+ allT.push(realTimeout);\n+ return realTimeout;\n+ };\n+ window.clearAllTimouts = () => {\n+ while (allT.length) {\n+ clearTimeout(allT.pop());\n+ }\n+ };\n cat = () => {\n- }\n+ window.clearAllTimouts();\n+ };\n };\n \n module.exports = solution;'

components/DiffView.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ const DiffView: React.FC<{
8282
const renderFile = ({ hunks, newPath }: File, fileIdx: number) => {
8383
const newValue: string[] = []
8484
if (!hunks.length || !newPath) return
85-
let extension = newPath.split('.').pop()!
86-
if (!prismLanguages.includes(extension)) extension = 'javascript'
85+
const extension = newPath.split('.').pop()!
86+
87+
let language = extension === 'html' ? 'jsx' : extension
88+
89+
if (!prismLanguages.includes(language)) language = 'javascript'
8790
hunks.forEach(hunk => {
8891
hunk.changes.forEach(change => {
8992
if (!change.isDelete) newValue.push(change.content)
@@ -92,8 +95,8 @@ const DiffView: React.FC<{
9295
const syntaxHighlight = (str: string, n: number) => {
9396
const highlighted = Prism.highlight(
9497
str,
95-
Prism.languages[extension],
96-
extension
98+
Prism.languages[language],
99+
language
97100
)
98101
return (
99102
<>

next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const moduleExports = {
3434
i18n: {
3535
locales: ['en'],
3636
defaultLocale: 'en'
37+
},
38+
sentry: {
39+
hideSourceMaps: true
3740
}
3841
}
3942

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@primer/octicons-react": "17.9.0",
3939
"@prisma/client": "4",
4040
"@quixo3/prisma-session-store": "^3.1.10",
41-
"@sentry/nextjs": "^7.21.1",
41+
"@sentry/nextjs": "^7.22.0",
4242
"apollo-server-micro": "^2.26.1",
4343
"apollo3-cache-persist": "^0.14.1",
4444
"bcrypt": "5.0.0",
@@ -74,14 +74,14 @@
7474
"yup": "^0.32.11"
7575
},
7676
"devDependencies": {
77-
"@graphql-codegen/cli": "^2.13.12",
77+
"@graphql-codegen/cli": "^2.15.0",
7878
"@graphql-codegen/typescript": "^2.8.0",
7979
"@graphql-codegen/typescript-apollo-client-helpers": "^2.2.6",
8080
"@graphql-codegen/typescript-operations": "^2.5.7",
81-
"@graphql-codegen/typescript-react-apollo": "^3.3.6",
81+
"@graphql-codegen/typescript-react-apollo": "^3.3.7",
8282
"@graphql-codegen/typescript-resolvers": "^2.7.7",
8383
"@jest/types": "^29.2.1",
84-
"@next/eslint-plugin-next": "^13.0.4",
84+
"@next/eslint-plugin-next": "^13.0.5",
8585
"@storybook/addon-actions": "^6.5.9",
8686
"@storybook/addon-essentials": "^6.5.13",
8787
"@storybook/addon-storyshots": "^6.5.13",
@@ -94,7 +94,7 @@
9494
"@testing-library/user-event": "^14.4.3",
9595
"@types/bcrypt": "^5.0.0",
9696
"@types/express-session": "^1.17.5",
97-
"@types/lodash": "^4.14.189",
97+
"@types/lodash": "^4.14.191",
9898
"@types/mdx-js__react": "^1.5.5",
9999
"@types/node": "^16.7.5",
100100
"@types/nodemailer": "^6.4.6",
@@ -108,7 +108,7 @@
108108
"copy-webpack-plugin": "^11.0.0",
109109
"cross-env": "^7.0.3",
110110
"eslint": "^7.32.0",
111-
"eslint-config-next": "^13.0.4",
111+
"eslint-config-next": "^13.0.5",
112112
"eslint-config-prettier": "^8.5.0",
113113
"eslint-plugin-mdx": "^1.17.1",
114114
"eslint-plugin-prettier": "^4.2.1",
@@ -118,7 +118,7 @@
118118
"identity-obj-proxy": "^3.0.0",
119119
"jest": "^27.5.1",
120120
"jest-mock-extended": "^3.0.1",
121-
"lint-staged": "^13.0.3",
121+
"lint-staged": "^13.0.4",
122122
"prettier": "^2.8.0",
123123
"prisma": "4",
124124
"react-test-renderer": "^17.0.1",

0 commit comments

Comments
 (0)