Skip to content

Commit 0d141d1

Browse files
committed
fixed catchphrases repeated word bug
1 parent f8558b2 commit 0d141d1

File tree

4 files changed

+13
-52
lines changed

4 files changed

+13
-52
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.eslintcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/in-game/ingame.js":"1","/Users/charchill/Work/Projects/catchphrase-word-game/src/index.js":"2","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/router/index.js":"3","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/footer/footer.js":"4","/Users/charchill/Work/Projects/catchphrase-word-game/src/serviceWorkerRegistration.js":"5","/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/main/main.js":"6","/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/pre-game/pregame.js":"7","/Users/charchill/Work/Projects/catchphrase-word-game/src/reportWebVitals.js":"8","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/header/header.js":"9","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/main-body-content/mbc.js":"10"},{"size":4266,"mtime":1609638870468,"results":"11","hashOfConfig":"12"},{"size":900,"mtime":1609638087375,"results":"13","hashOfConfig":"12"},{"size":588,"mtime":1609154204580,"results":"14","hashOfConfig":"12"},{"size":335,"mtime":1609602123392,"results":"15","hashOfConfig":"12"},{"size":5064,"mtime":1609006557317,"results":"16","hashOfConfig":"12"},{"size":834,"mtime":1609638815693,"results":"17","hashOfConfig":"12"},{"size":1278,"mtime":1609638847429,"results":"18","hashOfConfig":"12"},{"size":364,"mtime":1609006557316,"results":"19","hashOfConfig":"12"},{"size":295,"mtime":1609632532445,"results":"20","hashOfConfig":"12"},{"size":3084,"mtime":1609633053862,"results":"21","hashOfConfig":"12"},{"filePath":"22","messages":"23","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":"24","usedDeprecatedRules":"25"},"7yfzp7",{"filePath":"26","messages":"27","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"28"},{"filePath":"29","messages":"30","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"28"},{"filePath":"31","messages":"32","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"33","messages":"34","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"35"},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"28"},{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"44"},{"filePath":"45","messages":"46","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/in-game/ingame.js",["47"],"import React, { useState, useEffect } from \"react\";\nimport '../in-game/ingame.css';\nimport { Button, Container, Row, Col, Alert, Card, ButtonGroup} from 'react-bootstrap';\nimport {useLocation, Link} from 'react-router-dom';\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { faLowVision, faEye } from '@fortawesome/free-solid-svg-icons';\nimport Footer from \"../../components/footer/footer.js\";\nimport TimerSound from \"../../assets/audio/timer.mp3\";\nimport EndTimerSound from \"../../assets/audio/bomb.mp3\";\nimport Header from \"../../components/header/header.js\";\nimport ProgressBar from 'react-customizable-progressbar';\nimport ReactGa from 'react-ga';\n\nReactGa.initialize(\"UA-154721739-1\");\nReactGa.pageview('catchphrase.motasimfoad.com - Ingame Screen');\n\nfunction Ingame() {\n const [myObj, setMyObj] = useState([\"a\",\"b\",\"c\"]);\n const { state } = useLocation();\n const [min] = useState(state);\n const [millisec] = useState((min*60)*1000);\n const [seconds, setSeconds] = useState(0);\n const [flag, setFlag] = useState(true);\n const [rand, setRand] = useState(Math.round(Math.random() * (myObj.length-1)));\n const [temp, setTemp] = useState(rand);\n const [audio] = useState(new Audio(TimerSound));\n const [endAudio] = useState(new Audio(EndTimerSound));\n const [gameStatus, setGameStatus] = useState(false);\n \n const getData=()=>{\n fetch('https://api.motasimfoad.com/catch_phrase/catch_phrase.json'\n ).then(function(response){\n return response.json();\n })\n .then(function(myJson) {\n setMyObj(myJson);\n });\n }\n\n function toggle() {\n setFlag(!flag);\n }\n\n function word() {\n setRand(Math.round(Math.random() * (myObj.length-1)));\n setTemp ( Math.round(rand));\n }\n\n function getPercentageChange(){\n var secToMs = (seconds*1000);\n var decreaseValue = millisec - secToMs;\n var temp = (decreaseValue / millisec) * 100;\n temp = Math.round(temp);\n audio.play();\n return temp;\n }\n\n useEffect(() => {\n getData();\n const interval = setInterval(() => {\n setSeconds(seconds => seconds + 1);\n }, 1000);\n const timeout = setTimeout(() => {\n endAudio.play();\n setGameStatus(true);\n clearInterval(interval);\n }, millisec);\n return () => clearTimeout(timeout);\n }, []);\n \n return (\n <Container className=\"App\" fluid>\n <Header />\n <Row>\n <Col>\n <Alert className=\"App-Header\" variant=\"dark\">\n {flag ? <h3>{seconds}</h3>: <h4>hidden</h4>}\n <small>Timer</small>\n </Alert>\n </Col>\n <Col>\n <Alert className=\"App-Header\" variant=\"dark\">\n <Button variant=\"outline-dark\" onClick={toggle}>{flag ? <FontAwesomeIcon icon={faLowVision} />: <FontAwesomeIcon icon={faEye} />}</Button>\n <small>Visibility</small>\n </Alert>\n </Col>\n </Row>\n <Row>\n <Card>\n <Card.Body className=\"App-Game-Rules\">\n <ProgressBar\n radius={40}\n progress={getPercentageChange()}\n cut={120}\n rotate={-210}\n counterClockwise\n inverse\n initialAnimation\n initialAnimationDelay={1}\n strokeWidth={10}\n strokeColor=\"#d35400\"\n strokeLinecap=\"butt\"\n trackStrokeWidth={10}\n trackStrokeLinecap=\"butt\"\n >\n <div className=\"indicator\">\n <div>{myObj[temp]}</div>\n </div>\n </ProgressBar>\n </Card.Body>\n <Card.Footer>\n <ButtonGroup aria-label=\"Basic example\">\n <Button variant=\"warning\" className=\"btnPadding\" onClick={word} disabled={gameStatus}>Next</Button>\n <Link to=\"/pregame\"><Button variant=\"danger\" className=\"btnPadding\">Reset</Button></Link>\n </ButtonGroup> \n </Card.Footer>\n </Card>\n </Row>\n <Footer />\n </Container>\n );\n}\n\nexport default Ingame;\n",["48","49"],"/Users/charchill/Work/Projects/catchphrase-word-game/src/index.js",[],["50","51"],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/router/index.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/footer/footer.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/serviceWorkerRegistration.js",[],["52","53"],"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/main/main.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/pre-game/pregame.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/reportWebVitals.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/header/header.js",[],["54","55"],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/main-body-content/mbc.js",[],{"ruleId":"56","severity":1,"message":"57","line":69,"column":8,"nodeType":"58","endLine":69,"endColumn":10,"suggestions":"59"},{"ruleId":"60","replacedBy":"61"},{"ruleId":"62","replacedBy":"63"},{"ruleId":"60","replacedBy":"64"},{"ruleId":"62","replacedBy":"65"},{"ruleId":"60","replacedBy":"66"},{"ruleId":"62","replacedBy":"67"},{"ruleId":"60","replacedBy":"68"},{"ruleId":"62","replacedBy":"69"},"react-hooks/exhaustive-deps","React Hook useEffect has missing dependencies: 'endAudio' and 'millisec'. Either include them or remove the dependency array.","ArrayExpression",["70"],"no-native-reassign",["71"],"no-negated-in-lhs",["72"],["71"],["72"],["71"],["72"],["71"],["72"],{"desc":"73","fix":"74"},"no-global-assign","no-unsafe-negation","Update the dependencies array to be: [endAudio, millisec]",{"range":"75","text":"76"},[2323,2325],"[endAudio, millisec]"]25],"[endAudio, millisec]"]
1+
[{"/Users/charchill/Work/Projects/catchphrase-word-game/src/index.js":"1","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/router/index.js":"2","/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/main/main.js":"3","/Users/charchill/Work/Projects/catchphrase-word-game/src/components/main-body-content/mbc.js":"4","/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/in-game/ingame.js":"5"},{"size":900,"mtime":1609638087375,"results":"6","hashOfConfig":"7"},{"size":588,"mtime":1609154204580,"results":"8","hashOfConfig":"7"},{"size":834,"mtime":1609638815693,"results":"9","hashOfConfig":"7"},{"size":3084,"mtime":1609633053862,"results":"10","hashOfConfig":"7"},{"size":4216,"mtime":1611777571688,"results":"11","hashOfConfig":"7"},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"7yfzp7",{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"18","messages":"19","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"20","messages":"21","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/Users/charchill/Work/Projects/catchphrase-word-game/src/index.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/router/index.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/main/main.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/components/main-body-content/mbc.js",[],"/Users/charchill/Work/Projects/catchphrase-word-game/src/pages/in-game/ingame.js",["22"],{"ruleId":"23","severity":1,"message":"24","line":67,"column":8,"nodeType":"25","endLine":67,"endColumn":10,"suggestions":"26"},"react-hooks/exhaustive-deps","React Hook useEffect has missing dependencies: 'endAudio' and 'millisec'. Either include them or remove the dependency array.","ArrayExpression",["27"],{"desc":"28","fix":"29"},"Update the dependencies array to be: [endAudio, millisec]",{"range":"30","text":"31"},[2273,2275],"[endAudio, millisec]"]

src/pages/in-game/ingame.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,33 @@ ReactGa.initialize("UA-154721739-1");
1515
ReactGa.pageview('catchphrase.motasimfoad.com - Ingame Screen');
1616

1717
function Ingame() {
18-
const [myObj, setMyObj] = useState(["a","b","c"]);
18+
const [myObj, setMyObj] = useState("Tap next");
19+
const getData=()=>{
20+
fetch('https://api.motasimfoad.com/catch_phrase/catch_phrase.json'
21+
).then(response => response.json())
22+
.then((jsonData) => {
23+
setMyObj(jsonData);
24+
})
25+
.catch((error) => {
26+
console.error(error)
27+
})
28+
}
1929
const { state } = useLocation();
2030
const [min] = useState(state);
2131
const [millisec] = useState((min*60)*1000);
2232
const [seconds, setSeconds] = useState(0);
2333
const [flag, setFlag] = useState(true);
2434
const [rand, setRand] = useState(Math.round(Math.random() * (myObj.length-1)));
25-
const [temp, setTemp] = useState(rand);
2635
const [audio] = useState(new Audio(TimerSound));
2736
const [endAudio] = useState(new Audio(EndTimerSound));
2837
const [gameStatus, setGameStatus] = useState(false);
2938

30-
const getData=()=>{
31-
fetch('https://api.motasimfoad.com/catch_phrase/catch_phrase.json'
32-
).then(function(response){
33-
return response.json();
34-
})
35-
.then(function(myJson) {
36-
setMyObj(myJson);
37-
});
38-
}
39-
4039
function toggle() {
4140
setFlag(!flag);
4241
}
4342

4443
function word() {
4544
setRand(Math.round(Math.random() * (myObj.length-1)));
46-
setTemp ( Math.round(rand));
4745
}
4846

4947
function getPercentageChange(){
@@ -104,7 +102,7 @@ function Ingame() {
104102
trackStrokeLinecap="butt"
105103
>
106104
<div className="indicator">
107-
<div>{myObj[temp]}</div>
105+
<div>{myObj[rand]}</div>
108106
</div>
109107
</ProgressBar>
110108
</Card.Body>

yarn.lock

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,11 +1454,6 @@
14541454
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.6.0.tgz"
14551455
integrity sha512-cPqjjzuFWNK3BSKLm0abspP0sp/IGOli4p5I5fKFAzdS8fvjdOwDCfZqAaIiXd9lPkOWi3SUUfZof3hEb7J/uw==
14561456

1457-
"@ramonak/react-progress-bar@^2.0.0":
1458-
version "2.0.0"
1459-
resolved "https://registry.yarnpkg.com/@ramonak/react-progress-bar/-/react-progress-bar-2.0.0.tgz#7928331605610495623d40f4a98ec2be754acc6c"
1460-
integrity sha512-AMK9wXfXV2QAC+aQOoqP/0WDA8phvkc+GKPvAqNZcgu0msic3aMAnFl0BjvBXdaxc6HgvGvKF5JC5rygOKe/xw==
1461-
14621457
"@restart/context@^2.1.4":
14631458
version "2.1.4"
14641459
resolved "https://registry.npmjs.org/@restart/context/-/context-2.1.4.tgz"
@@ -5536,11 +5531,6 @@ hosted-git-info@^2.1.4:
55365531
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz"
55375532
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==
55385533

5539-
howler@^2.1.3:
5540-
version "2.2.1"
5541-
resolved "https://registry.yarnpkg.com/howler/-/howler-2.2.1.tgz#a521a9b495841e8bb9aa12e651bebba0affc179e"
5542-
integrity sha512-0iIXvuBO/81CcrQ/HSSweYmbT50fT2mIc9XMFb+kxIfk2pW/iKzDbX1n3fZmDXMEIpYvyyfrB+gXwPYSDqUxIQ==
5543-
55445534
hpack.js@^2.1.6:
55455535
version "2.1.6"
55465536
resolved "https://registry.yarnpkg.com/hpack.js/-/hpack.js-2.1.6.tgz"
@@ -9132,26 +9122,11 @@ react-error-overlay@^6.0.8:
91329122
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.8.tgz"
91339123
integrity sha512-HvPuUQnLp5H7TouGq3kzBeioJmXms1wHy9EGjz2OURWBp4qZO6AfGEcnxts1D/CbwPLRAgTMPCEgYhA3sEM4vw==
91349124

9135-
react-fast-compare@^3.1.1:
9136-
version "3.2.0"
9137-
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
9138-
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==
9139-
91409125
react-ga@^3.3.0:
91419126
version "3.3.0"
91429127
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.0.tgz#c91f407198adcb3b49e2bc5c12b3fe460039b3ca"
91439128
integrity sha512-o8RScHj6Lb8cwy3GMrVH6NJvL+y0zpJvKtc0+wmH7Bt23rszJmnqEQxRbyrqUzk9DTJIHoP42bfO5rswC9SWBQ==
91449129

9145-
react-helmet@^6.1.0:
9146-
version "6.1.0"
9147-
resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-6.1.0.tgz#a750d5165cb13cf213e44747502652e794468726"
9148-
integrity sha512-4uMzEY9nlDlgxr61NL3XbKRy1hEkXmKNXhjbAIOVw5vcFrsdYbH2FEwcNyWvWinl103nXgzYNlns9ca+8kFiWw==
9149-
dependencies:
9150-
object-assign "^4.1.1"
9151-
prop-types "^15.7.2"
9152-
react-fast-compare "^3.1.1"
9153-
react-side-effect "^2.1.0"
9154-
91559130
react-is@^16.3.2, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1:
91569131
version "16.13.1"
91579132
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz"
@@ -9281,11 +9256,6 @@ [email protected]:
92819256
optionalDependencies:
92829257
fsevents "^2.1.3"
92839258

9284-
react-side-effect@^2.1.0:
9285-
version "2.1.1"
9286-
resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-2.1.1.tgz#66c5701c3e7560ab4822a4ee2742dee215d72eb3"
9287-
integrity sha512-2FoTQzRNTncBVtnzxFOk2mCpcfxQpenBMbk5kSVBg5UcPqV9fRbgY2zhb7GTWWOlpFmAxhClBDlIq8Rsubz1yQ==
9288-
92899259
react-transition-group@^4.4.1:
92909260
version "4.4.1"
92919261
resolved "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.1.tgz"
@@ -11046,13 +11016,6 @@ url@^0.11.0:
1104611016
punycode "1.3.2"
1104711017
querystring "0.2.0"
1104811018

11049-
use-sound@^2.0.1:
11050-
version "2.0.1"
11051-
resolved "https://registry.yarnpkg.com/use-sound/-/use-sound-2.0.1.tgz#72e70d4bfdda71a6959e5adab0c7e10ff4080a0a"
11052-
integrity sha512-wNwnyIOe8QPDQgWRZd3PqVEJ9BpLO+VJX+EpQSb6EvvjblHhnYMD7WIOTQ4hgloC2jC7Az6FhclHilC441De7A==
11053-
dependencies:
11054-
howler "^2.1.3"
11055-
1105611019
use@^3.1.0:
1105711020
version "3.1.1"
1105811021
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz"

0 commit comments

Comments
 (0)