Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/game screen/typing #120

Merged
merged 13 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions typing-app/src/components/templates/GameTyping.tsx
h-takeyeah marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ const GameTyping: React.FC<GameTypingProps> = ({ nextPage, subjectText, setResul
const [currentTypeSpeed, setCurrentTypeSpeed] = useState(0);
const [averageTypeSpeed, setAverageTypeSpeed] = useState(0);

const toLogarithmWpm = (wpm: number): number => {
const wpmForProgressBar: number = (1000 / 3) * Math.log10((999 / 1000) * wpm + 1);
if (wpmForProgressBar > 1000) {
return 1000;
}
return wpmForProgressBar;
};

const typeIndexRef = useRef(typeIndex);
useEffect(() => {
// setTypeIndexの結果を反映する
Expand All @@ -122,13 +114,13 @@ const GameTyping: React.FC<GameTypingProps> = ({ nextPage, subjectText, setResul
}
const typeTime = getTypingQueueListIndex(typingQueueList.length - 1) - getTypingQueueListIndex(0);
const currentWpm = (typingQueueList.length / typeTime) * 60000;
return toLogarithmWpm(currentWpm);
return currentWpm;
};

const calcAverageTypingSpeed = (): number => {
const timeFromStart: number = new Date().valueOf() - startedAt.valueOf();
const averageTypingSpeed: number = (correctType / timeFromStart) * 60000;
return toLogarithmWpm(averageTypingSpeed);
return averageTypingSpeed;
};

const addTypingQueueList = () => {
Expand Down