Create a .env file in the project root:
# API Configuration
VITE_API_BASE_URL=/api
# MSW (Mock Service Worker) - set to "true" to use mock data
VITE_ENABLE_MSW=falseTo switch between real API and mock data:
-
Use Real API (default):
VITE_ENABLE_MSW=false
-
Use Mock Data (for development without backend):
VITE_ENABLE_MSW=true
All API hooks are located in src/hooks/api/:
useLogin()- Login with credentialsuseLogout()- Logout
useChannels()- Get all channelsuseRoomList(channelId)- Get rooms in a channeluseActivateChannel()- Activate a channeluseSetLesson()- Set lesson configurationuseFinishLesson()- Finish a lesson
useStudents()- Get all studentsuseAddStudent()- Add a new studentuseDeleteStudent()- Delete a student
useJoinRoom()- Join a room as a student
useMatchHistory()- Get match historyuseDownloadHistory()- Download match history as Excel
The following components have been fully integrated with the API:
-
TeacherLogin.tsx ✅
- Uses
useLogin()for authentication - Stores JWT token in localStorage
- Uses
-
ChannelList.tsx ✅
- Uses
useChannels()for channel list - Uses
useActivateChannel()for activating channels
- Uses
-
StudentManagement.tsx ✅
- Uses
useStudents()for student list - Uses
useAddStudent()for adding students - Uses
useDeleteStudent()for deleting students
- Uses
-
GameRecords.tsx ✅
- Uses
useMatchHistory()for match history with date filtering - Uses
useDownloadMatchHistory()for Excel download
- Uses
-
GameSetup.tsx ✅
- Uses
useStudents()for student list - Uses
useSetLesson()for lesson configuration
- Uses
-
ClassForm.tsx ✅
- Uses
useStudents()for student list in game setup
- Uses
-
RoomManagement.tsx ✅
- Uses
useStudents()for student list in new game dialog - Uses
useRoomList(channel.id)for room data - Uses
useFinishLesson()for deactivating channel
- Uses
All teacher-facing components have been successfully integrated with the real API. The application can now:
- Authenticate teachers
- Manage channels and lessons
- Manage students
- View and manage game rooms
- Track match history
- Download Excel reports
The following components may still use mock data:
- StudentView.tsx / RoomList.tsx
- May need
useRoomList(channelId)for getting rooms - Student-facing components for joining rooms
- May need
const students = [
"김민수",
"이지은",
// ... more students
];
const rooms: Room[] = [
{
id: "1",
roomNumber: 1,
blackPlayer: "김민수",
whitePlayer: "이지은",
status: "waiting",
},
// ... more rooms
];import { useStudents } from "@/hooks/api/useStudents";
import { useRoomList } from "@/hooks/api/useChannels";
function RoomManagement({ channel }) {
// Fetch students from API
const { data: studentsData, isLoading: studentsLoading } = useStudents();
const students = studentsData?.map(s => s.name) || [];
// Fetch rooms from API
const { data: roomsData, isLoading: roomsLoading } = useRoomList(channel.id);
const rooms = roomsData || [];
if (studentsLoading || roomsLoading) {
return <div>Loading...</div>;
}
// ... rest of component
}-
Start backend server:
cd go-chess-timer-be npm run start:dev -
Start frontend with real API:
cd timer-fe # Make sure VITE_ENABLE_MSW=false in .env npm run dev
-
Or start frontend with mock data:
cd timer-fe # Set VITE_ENABLE_MSW=true in .env npm run dev