MCPcopy Create free account
hub / github.com/SuboptimalEng/coding-tutorials / App

Function App

react-vim-tutor/client/src/App.jsx:7–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { useState } from 'react';
6
7function App() {
8 const getNewCodingTest = () => {
9 const lastLine = ` `;
10 const emptyLine = ` \n`;
11 const codeToRemove = ` %\n`;
12 let testCode = '';
13 let randomLine = Math.floor(Math.random() * 9);
14 for (let i = 0; i < 9; i++) {
15 if (randomLine === i) {
16 testCode += codeToRemove;
17 } else {
18 testCode += emptyLine;
19 }
20 }
21 testCode += lastLine;
22 return testCode;
23 };
24
25 const testCode = getNewCodingTest();
26 const [code, setCode] = useState(testCode);
27 const [numOfWins, setNumOfWins] = useState(0);
28
29 return (
30 <div className="App">
31 <header className="App-header">
32 <div className="absolute top-20 bottom-40 left-20 right-20 text-left">
33 <div>Move with 'h/j/k/w' and delete with 'x'</div>
34 <div>Won {numOfWins} time(s)!</div>
35 <CodeMirror
36 value={code}
37 options={{
38 theme: 'dracula',
39 keyMap: 'vim',
40 mode: 'js',
41 }}
42 onChange={(editor, data) => {
43 const editedCode = editor.getValue();
44 if (!editedCode.includes('%')) {
45 setCode(getNewCodingTest());
46 setNumOfWins(numOfWins + 1);
47 }
48 }}
49 />
50 </div>
51 </header>
52 </div>
53 );
54}
55
56export default App;

Callers

nothing calls this directly

Calls 1

getNewCodingTestFunction · 0.85

Tested by

no test coverage detected