improve performance

This commit is contained in:
rendi12345678 2024-08-17 18:56:01 +07:00
parent f0693d90b6
commit 6eea64a4bc
6 changed files with 115 additions and 75 deletions

View File

@ -0,0 +1,25 @@
robots.txt,1723894396770,2544ca049f223a42bff01f72ad930a5edba75bbb7199d0f8430a02ff5aca16ec
manifest.json,1723894396770,1a9784b8466475389b21e07611f74fb1dd8367643a277a29c503fee0b049140c
index.html,1723894506764,88f92d47b9d678079277fab47a8ef93cc03483a7d668787adcc2d2c47c9f585e
logo.png,1723894396770,fdc50634b1942f229d3b244fd91f8cc141a2fb301cebffecb325d9432f92e35d
asset-manifest.json,1723894506807,e3915da7985732e2d1492a309eeed87f57955959392ffef3987da9fbdf4ec9e0
logo512.png,1723894396770,9ab6cb941e493973baf9755bd3fc76988762e6b514d5bc365aeaccefa0de034f
logo192.png,1723894396770,50bd60c6fefdd7de57fb652cf717e33c712106ffe0a32da5f75a12bf22cecbc0
favicon.ico,1723894396770,fc26b72d1f6d47474d8993a667b2af803ede41c9996d0f69e62ed6e415d7fed0
static/media/typeSoft.3e307070c0d43972460c.wav,1723894506797,1dade6a0dc93ff4a2f1658ae9d71850d6a217993e9f008bbdff6124c4f26c3c2
static/js/main.1c05fc1f.js.LICENSE.txt,1723894506797,863f9d79659576d4828dd820b2b96ab72da24b2f7b5034e53556f00ba3a08263
static/media/discord.b048131aab7bcf46e08115b432eece0a.svg,1723894506797,f5c2d6fa3ec5449e38ba567f81d867468dad78dc9f83c01495f27fce76d735ae
static/js/845.d88f7a05.chunk.js.LICENSE.txt,1723894506797,4be0b6eb0f1a4fd054f85b6a21a7380e9bb7287a99bc268e626a709df6d9a60e
static/js/181.50cd7f54.chunk.js.map,1723894506807,550e32b3c91c7d8e9e86941d23a485d5a816695d861d263d76cdaba764f52d3c
static/js/181.50cd7f54.chunk.js,1723894506797,4be0ba23b2efd5b77e9bc30ef1031482907754666cd70a2cb9f9e1a21ba93dd6
static/js/110.443f5259.chunk.js.map,1723894506804,26d05d3583ecd4920bff67743bfdb6d44246091c78fdbaec34ce37b3296d3548
static/js/110.443f5259.chunk.js,1723894506797,b65c7950a74afd66738cfb80d377ad39536b2558462467b7554f7d731175019a
static/css/main.e6c13ad2.css.map,1723894506797,e845e6a28aaddc1902a601eeb9df71ac53bdd9c9a922c6d49febaf4035e42c47
static/css/main.e6c13ad2.css,1723894506797,20ddccbcb290095bc023db15e46a257ec7d8ee4783d17704654f62d527804f71
static/js/845.d88f7a05.chunk.js,1723894506797,b92104d5a535577378ceb2317c7babe9d122808be04c04ae04c965eacef5712e
static/media/cherryBlue.f4cad75e8a5792bb3d25.wav,1723894506797,22a637101f4b2aaef7335ed58a20e7db780ae522ef535506c05f1594b5e2b8d2
static/media/keyboard.f9440324ce3fbfc79f5b.wav,1723894506797,1b248ff6cd5a2ffdc7f24c03f1dba874b01a1c285162a60589a6bb3e17f4b250
static/media/WeChatSupport.d4d0b5b8d76008986829.png,1723894506797,a2dfd32d2be076a4e5c356ba97001789d403665f3dd90a01a631e9649f2fc32d
static/js/845.d88f7a05.chunk.js.map,1723894506807,acc2fa06363004ca40b27d587ff87677dc97002c7d9a8c52db739433716f8b94
static/js/main.1c05fc1f.js,1723894506797,d98c8eff65ef54b21b23a9dd330abedbf82d961eae2d473bdf6400c8233a044a
static/js/main.1c05fc1f.js.map,1723894506797,9e4de2c25b634c0ae50f09783d8cd7f6f23963c87e5e88ad0f045347d376ee26

5
.firebaserc Normal file
View File

@ -0,0 +1,5 @@
{
"projects": {
"default": "eletypes"
}
}

16
firebase.json Normal file
View File

@ -0,0 +1,16 @@
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}

View File

@ -47,9 +47,6 @@ import {
} from "../../../constants/Constants";
import { SOUND_MAP } from "../sound/sound";
import SocialLinksModal from "../../common/SocialLinksModal";
import WorkerBuilder from "../../../worker/WorkerBuilder";
import calculateWpmWorker from "../../../worker/calculateWpmWorker";
import checkPrevWorker from "../../../worker/checkPrevWorker";
const TypeBox = ({
textInputRef,
@ -414,7 +411,9 @@ const TypeBox = ({
useEffect(() => {
// Initialize worker
wpmWorkerRef.current = new WorkerBuilder(calculateWpmWorker);
wpmWorkerRef.current = new Worker(
new URL("../../../worker/calculateWpmWorker", import.meta.url)
);
return () => {
// Cleanup worker on component unmount
@ -588,7 +587,9 @@ const TypeBox = ({
const workerRef = useRef(null);
useEffect(() => {
workerRef.current = new WorkerBuilder(checkPrevWorker);
workerRef.current = new Worker(
new URL("../../../worker/checkPrevWorker", import.meta.url)
);
return () => {
if (workerRef.current) {

View File

@ -1,12 +1,8 @@
// eslint-disable-next-line import/no-anonymous-default-export
export default () => {
// eslint-disable-next-line no-restricted-globals
self.onmessage = function (e) {
const { wpmKeyStrokes, countDownConstant, countDown } = e.data;
// eslint-disable-next-line no-restricted-globals
self.onmessage = function (e) {
const { wpmKeyStrokes, countDownConstant, countDown } = e.data;
const currWpm =
(wpmKeyStrokes / 5 / (countDownConstant - countDown)) * 60.0;
const currWpm = (wpmKeyStrokes / 5 / (countDownConstant - countDown)) * 60.0;
postMessage(currWpm);
};
postMessage(currWpm);
};

View File

@ -1,67 +1,64 @@
// eslint-disable-next-line import/no-anonymous-default-export
export default () => {
// eslint-disable-next-line no-restricted-globals
self.onmessage = function (event) {
const {
words,
currWordIndex,
currInputWithoutSpaces,
wordsCorrect,
wordsInCorrect,
inputWordsHistory,
prevInput,
wpmKeyStrokes,
} = event.data;
// eslint-disable-next-line no-restricted-globals
self.onmessage = function (event) {
const {
words,
currWordIndex,
currInputWithoutSpaces,
wordsCorrect,
wordsInCorrect,
inputWordsHistory,
prevInput,
wpmKeyStrokes,
} = event.data;
// Validate input data
const wordToCompare = words[currWordIndex];
const isCorrect = wordToCompare === currInputWithoutSpaces;
// Validate input data
const wordToCompare = words[currWordIndex];
const isCorrect = wordToCompare === currInputWithoutSpaces;
// Ensure wpmKeyStrokes is a valid number
const validWpmKeyStrokes =
typeof wpmKeyStrokes === "number" && !isNaN(wpmKeyStrokes)
? wpmKeyStrokes
: 0;
// Ensure wpmKeyStrokes is a valid number
const validWpmKeyStrokes =
typeof wpmKeyStrokes === "number" && !isNaN(wpmKeyStrokes)
? wpmKeyStrokes
: 0;
// Check if the current input is empty
if (!currInputWithoutSpaces || currInputWithoutSpaces.length === 0) {
postMessage({ isCorrect: null });
return;
}
// Check if the current input is empty
if (!currInputWithoutSpaces || currInputWithoutSpaces.length === 0) {
postMessage({ isCorrect: null });
return;
}
let updatedWordsCorrect = new Set(wordsCorrect);
let updatedWordsInCorrect = new Set(wordsInCorrect);
let updatedInputWordsHistory = { ...inputWordsHistory };
let updatedPrevInput = prevInput;
let updatedWpmKeyStrokes = validWpmKeyStrokes;
let updatedWordsCorrect = new Set(wordsCorrect);
let updatedWordsInCorrect = new Set(wordsInCorrect);
let updatedInputWordsHistory = { ...inputWordsHistory };
let updatedPrevInput = prevInput;
let updatedWpmKeyStrokes = validWpmKeyStrokes;
if (isCorrect) {
updatedWordsCorrect.add(currWordIndex);
updatedWordsInCorrect.delete(currWordIndex);
updatedInputWordsHistory[currWordIndex] = currInputWithoutSpaces;
updatedPrevInput = "";
updatedWpmKeyStrokes += 1; // Increment only if valid
postMessage({
isCorrect: true,
updatedWordsCorrect: Array.from(updatedWordsCorrect),
updatedWordsInCorrect: Array.from(updatedWordsInCorrect),
updatedInputWordsHistory,
updatedPrevInput,
updatedWpmKeyStrokes,
});
} else {
updatedWordsInCorrect.add(currWordIndex);
updatedWordsCorrect.delete(currWordIndex);
updatedInputWordsHistory[currWordIndex] = currInputWithoutSpaces;
updatedPrevInput += " " + currInputWithoutSpaces;
postMessage({
isCorrect: false,
updatedWordsCorrect: Array.from(updatedWordsCorrect),
updatedWordsInCorrect: Array.from(updatedWordsInCorrect),
updatedInputWordsHistory,
updatedPrevInput,
updatedWpmKeyStrokes,
});
}
};
if (isCorrect) {
updatedWordsCorrect.add(currWordIndex);
updatedWordsInCorrect.delete(currWordIndex);
updatedInputWordsHistory[currWordIndex] = currInputWithoutSpaces;
updatedPrevInput = "";
updatedWpmKeyStrokes += 1; // Increment only if valid
postMessage({
isCorrect: true,
updatedWordsCorrect: Array.from(updatedWordsCorrect),
updatedWordsInCorrect: Array.from(updatedWordsInCorrect),
updatedInputWordsHistory,
updatedPrevInput,
updatedWpmKeyStrokes,
});
} else {
updatedWordsInCorrect.add(currWordIndex);
updatedWordsCorrect.delete(currWordIndex);
updatedInputWordsHistory[currWordIndex] = currInputWithoutSpaces;
updatedPrevInput += " " + currInputWithoutSpaces;
postMessage({
isCorrect: false,
updatedWordsCorrect: Array.from(updatedWordsCorrect),
updatedWordsInCorrect: Array.from(updatedWordsInCorrect),
updatedInputWordsHistory,
updatedPrevInput,
updatedWpmKeyStrokes,
});
}
};