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

[#113] 소켓 로직 변경 적용 #114

Merged
merged 8 commits into from
Nov 24, 2023
3 changes: 3 additions & 0 deletions frontend/src/components/Main/CompetitionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export default function CompetitionList() {
<td>
<ViewDashboardButton id={competition.id} />
</td>
<td>
<Link to={`/contest/${competition.id}`}>대회 참여</Link>
</td>
</tr>
))}
</tbody>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/Submission/SubmissionResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ export function SubmissionResult({ socket }: Props) {
};

const handleMessage = (rawData: string) => {
const { message } = JSON.parse(rawData) as Message;
const totalSubmissionResult = 10;
const { message, testcaseNum } = JSON.parse(rawData) as Message;

setSubmissionMessage(message);
setScoreResults(
range(0, totalSubmissionResult).map((_, index) => ({
testcaseId: index,
range(0, testcaseNum).map((_, index) => ({
testcaseId: index + 1,
submitState: SUBMIT_STATE.loading,
})),
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Submission/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface SubmitResult {

export type Message = {
message: string;
testcaseNum: number;
};

export type ScoreResult = {
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/hooks/competition/useCompetition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createSocketInstance } from '@/utils/socket';
import { isNil } from '@/utils/type';

export type SubmissionForm = {
competitionId: number;
problemId: ProblemId;
code: string;
};
Expand All @@ -24,10 +25,14 @@ const notFoundCompetition: CompetitionInfo = {

export const useCompetition = (competitionId: number) => {
const [competition, setCompetition] = useState<CompetitionInfo>(notFoundCompetition);

const socket = useRef(
createSocketInstance('/competitions', {
transports: ['websocket'],
query: { competitionId: 3 },
query: { competitionId },
auth: {
token: `${localStorage.getItem('accessToken')}`,
},
}),
);

Expand All @@ -49,7 +54,9 @@ export const useCompetition = (competitionId: number) => {
}, []);

function submitSolution(form: SubmissionForm) {
socket.current.emit('submissions', form);
socket.current.emit('submissions', {
...form,
});
}

async function updateCompetition(competitionId: number) {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/ContestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export default function ContestPage() {
const form = {
problemId: currentProblem.id,
code,
competitionId,
} satisfies SubmissionForm;

submitSolution(form);
}

Expand Down
51 changes: 23 additions & 28 deletions frontend/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@ import ProblemPage from '@/pages/ProblemPage';

import App from './App';

const router = createBrowserRouter(
[
{
path: '/',
element: <App />,
children: [
{
index: true,
element: <MainPage />,
},
{
path: '/contest/:id',
element: <ContestPage />,
},
{
path: '/problem/:id',
element: <ProblemPage />,
},
{
path: '/contest/create',
element: <CreateCompetitionPage />,
},
{ path: '/login', element: <LoginPage /> },
],
},
],
const router = createBrowserRouter([
{
basename: process.env.NODE_ENV === 'production' ? '/web12-Algo-With-Me' : '',
path: '/',
element: <App />,
children: [
{
index: true,
element: <MainPage />,
},
{
path: '/contest/:id',
element: <ContestPage />,
},
{
path: '/problem/:id',
element: <ProblemPage />,
},
{
path: '/contest/create',
element: <CreateCompetitionPage />,
},
{ path: '/login', element: <LoginPage /> },
],
},
);
]);

export default router;
1 change: 0 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
base: './',
resolve: {
alias: [
{
Expand Down
Loading