Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions typing-app/.eslintrc.json

This file was deleted.

6 changes: 6 additions & 0 deletions typing-app/eslint.config.mjs
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

移行先

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import nextCoreWebVitals from "eslint-config-next/core-web-vitals";
import eslintConfigPrettier from "eslint-config-prettier/flat";

const eslintConfig = [...nextCoreWebVitals, eslintConfigPrettier];
Comment thread
KinjiKawaguchi marked this conversation as resolved.

export default eslintConfig;
59 changes: 23 additions & 36 deletions typing-app/package.json
Comment thread
KinjiKawaguchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,44 @@
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint": "eslint .",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next lint deprecated
https://nextjs.org/blog/next-15-5

"format": "prettier . --write",
"format:ci": "prettier . --check",
"sanitize": "tsx scripts/sanitizeText.ts",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.468.0",
"next": "15.2.4",
"openapi-fetch": "0.13.3",
"prettier": "^3.4.2",
"react": "19.0.0",
"react-dom": "19.0.0",
"next": "16.2.3",
"openapi-fetch": "0.17.0",
"react": "19.2.5",
"react-dom": "19.2.5",
"server-only": "^0.0.1",
"sharp": "^0.33.5",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7"
"sharp": "^0.34.5"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^14.3.1",
"@types/node": "^20.17.10",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.2",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.1",
"eslint-config-next": "15.1.0",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"openapi-typescript": "6.7.6",
"postcss": "^8.4.49",
"sass": "^1.85.0",
"tailwindcss": "^3.4.16",
"tsx": "^4.19.3",
"typescript": "^5.7.2"
"@jest/globals": "^30.3.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/node": "^25.6.0",
"@types/react": "19.2.14",
"@types/react-dom": "19.2.3",
"eslint": "^9.39.4",
Comment thread
KinjiKawaguchi marked this conversation as resolved.
"eslint-config-next": "16.2.3",
"eslint-config-prettier": "^10.1.8",
"jest": "^30.3.0",
"jest-environment-jsdom": "^30.3.0",
"openapi-typescript": "7.13.0",
Comment thread
KinjiKawaguchi marked this conversation as resolved.
"prettier": "^3.8.2",
"sass": "^1.99.0",
"tsx": "^4.21.0",
"typescript": "^6.0.2"
},
"repository": "https://github.com/su-its/typing",
"author": "su-its",
"packageManager": "yarn@4.6.0",
"engines": {
"npm": "use yarn instead"
},
"resolutions": {
"@types/react": "19.0.1",
"@types/react-dom": "19.0.2"
Comment on lines -57 to -60
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next.js 14.1.0 → 15.1.0にした際のcodemodが自動で追加したもの。
現時点では不要

}
}
6 changes: 0 additions & 6 deletions typing-app/postcss.config.js

This file was deleted.

10 changes: 6 additions & 4 deletions typing-app/src/app/game/page.tsx
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reactの新しいpurity lintがレンダー中のimpure callを禁止
https://react.dev/reference/eslint-plugin-react-hooks/lints/purity

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import fs from "fs";

const filenames = fs.readdirSync("public/texts/");

const getRandomSubjectText = () => {
const randomFilename = filenames[Math.floor(Math.random() * filenames.length)] ?? filenames[0];
Comment thread
KinjiKawaguchi marked this conversation as resolved.
return fs.readFileSync(`public/texts/${randomFilename}`, "utf-8");
};

export default function Typing() {
const subjectText = fs.readFileSync(
`public/texts/${filenames[Math.floor(Math.random() * filenames.length)]}`,
"utf-8"
);
const subjectText = getRandomSubjectText();
const subjectTextOneLine = subjectText.replace(/\n/gm, " ");

return <GamePage subjectText={subjectTextOneLine} />;
Expand Down
54 changes: 33 additions & 21 deletions typing-app/src/components/organism/RankingTabs.tsx
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set-state-in-effectを改善

Comment thread
KinjiKawaguchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import RankingTable from "../organism/RankingTable";
import { Pagination } from "../molecules/Pagination";
import RefreshButton from "../atoms/RefreshButton";
import { useCallback, useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { client } from "@/libs/api";
import type { components } from "@/libs/api/v1";
import { showErrorToast } from "@/utils/toast";
Expand Down Expand Up @@ -53,30 +53,42 @@ const RankingTabs = () => {
const [rankingStartFrom, setRankingStartFrom] = useState(1);
const [sortBy, setSortBy] = useState<"accuracy" | "keystrokes">("accuracy");
const [totalRankingCount, setTotalRankingCount] = useState<number>(0);
const [refreshKey, setRefreshKey] = useState(0);

const LIMIT = 10; //TODO: Configファイルから取得

const fetchData = useCallback(async () => {
const { data, error } = await client.GET("/scores/ranking", {
params: {
query: {
sort_by: sortBy,
start: rankingStartFrom,
limit: LIMIT,
useEffect(() => {
let isCancelled = false;

const fetchData = async () => {
const { data, error } = await client.GET("/scores/ranking", {
params: {
query: {
sort_by: sortBy,
start: rankingStartFrom,
limit: LIMIT,
},
},
},
});
if (data) {
setScoreRankings(data.rankings);
setTotalRankingCount(data.total_count);
} else {
showErrorToast(error);
}
}, [sortBy, rankingStartFrom]);
});

useEffect(() => {
fetchData();
}, [fetchData]);
if (isCancelled) {
return;
}

if (data) {
setScoreRankings(data.rankings);
setTotalRankingCount(data.total_count);
} else {
showErrorToast(error);
}
};

void fetchData();

return () => {
isCancelled = true;
};
}, [refreshKey, sortBy, rankingStartFrom]);

const handleTabChange = (index: number) => {
const sortOption = index === 0 ? "accuracy" : "keystrokes";
Expand Down Expand Up @@ -118,7 +130,7 @@ const RankingTabs = () => {
<RefreshButton
onClick={() => {
setRankingStartFrom(1);
fetchData();
setRefreshKey((prev) => prev + 1);
Comment thread
KinjiKawaguchi marked this conversation as resolved.
}}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion typing-app/src/components/templates/GameTyping.tsx
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reactの新しいpurity lintがレンダー中のimpure callを禁止
https://react.dev/reference/eslint-plugin-react-hooks/lints/purity

mount 時 effect で startTimeRef.current = Date.now() を入れ直しているのでバグらない。

Comment thread
KinjiKawaguchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const GameTyping: React.FC<GameTypingProps> = ({ nextPage, subjectText, setScore
});

// 開始時刻と処理フラグの参照
const startTimeRef = useRef<number>(Date.now());
const startTimeRef = useRef<number>(0);
Comment thread
KinjiKawaguchi marked this conversation as resolved.
const isProcessingRef = useRef(false);

const typingQueueRef = useRef<number[]>([]);
Expand Down
Loading
Loading