Skip to content
Open
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
3 changes: 2 additions & 1 deletion client/src/hooks/data/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Challenge = {
participated: boolean;
date: string;
duration: number;
//
problemId: string;
score: number;
ranking: number;
difficulty: Difficulty;
Expand Down Expand Up @@ -42,6 +42,7 @@ export type Problem = {
content: string;
difficulty: Difficulty;
solved: boolean;
isAvailable: boolean;
};

export type Submission = {
Expand Down
33 changes: 28 additions & 5 deletions client/src/modules/Practice/components/Problems/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Badge from '@components/shared/Badge';
import classNames from 'classnames';
import Card from '@components/ui/Card';
import { useProblems } from '@hooks/data/useProblems';
import { Difficulty } from '@models/enums';
import { Difficulty, Status } from '@models/enums';
import { problemTableFields } from '@modules/Practice/models';
import { useRouter } from 'next/router';
import { AiOutlineCheckCircle } from 'react-icons/ai';
Expand All @@ -14,6 +15,19 @@ const Problems = () => {
router.push(`/problem/${id}`);
};

const renderLock = () => {
return (
<svg fill="#435EBE" height="18px" width="18px" viewBox="0 0 330 330">
<g id="XMLID_509_">
<path
id="XMLID_510_"
d="M65,330h200c8.284,0,15-6.716,15-15V145c0-8.284-6.716-15-15-15h-15V85c0-46.869-38.131-85-85-85 S80,38.131,80,85v45H65c-8.284,0-15,6.716-15,15v170C50,323.284,56.716,330,65,330z M180,234.986V255c0,8.284-6.716,15-15,15 s-15-6.716-15-15v-20.014c-6.068-4.565-10-11.824-10-19.986c0-13.785,11.215-25,25-25s25,11.215,25,25 C190,223.162,186.068,230.421,180,234.986z M110,85c0-30.327,24.673-55,55-55s55,24.673,55,55v45H110V85z"
/>
</g>
</svg>
);
};

return (
<Card className="h-fit min-h-[600px] overflow-x-auto rounded-lg">
<div className="text-xl font-semibold text-primary-400">Problems</div>
Expand All @@ -28,13 +42,22 @@ const Problems = () => {
</tr>
</thead>
<tbody>
{problems?.map(({ id, title, difficulty, solved }) => (
{problems?.map(({ id, title, difficulty, solved, isAvailable }) => (
<tr
key={id}
onClick={() => handleProblemNavigation(id)}
className="cursor-pointer border-t border-border hover:bg-background-50"
onClick={() => isAvailable && handleProblemNavigation(id)}
className={classNames(
'border-t border-border hover:bg-background-50',
{'cursor-not-allowed': !isAvailable },
{'cursor-pointer': isAvailable },
)}
>
<td className="text whitespace-nowrap py-3">{title}</td>
<td className="text whitespace-nowrap py-3">
<span className="flex gap-2">
{!isAvailable && renderLock()}
{title}
</span>
</td>
<td className="">
<Badge className="capitalize" intent={difficulty}>
{Difficulty[difficulty]}
Expand Down
3 changes: 0 additions & 3 deletions client/src/modules/Problem/components/Submission/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ const Submission: FC<SubmissionProps> = ({ problemId, code, language }) => {
};

const loading = runLoading || submissionLoading;
const accepted = result?.status == SubmissionStatus.Accepted;
const isSubmission = result?.type == SubmissionTypes.Submission;
const showResult = activeTab == SubmissionTabs.Result && result && !loading;
const showTestcase = activeTab == SubmissionTabs.Testcase && !loading;
const showComplete = accepted && isSubmission;

return (
<Card className="relative">
Expand Down
1 change: 1 addition & 0 deletions server/src/core/data/entities/problem.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class ProblemEntity {
content: string;
difficulty: number;
defaultCodes: DefaultCodes[];
isAvailable: boolean;
}

export type DefaultCodes = {
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/auth/models/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ACCESS_TOKEN = 'access_token';
export const ACCESS_TOKEN = 'codex_access_token';
export const ACCESS_HEADER = 'x-access-token';

export const Roles = {
Expand Down
6 changes: 6 additions & 0 deletions server/src/modules/challenge/challenge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class ChallengeService {
await this.dataService.challenges.update(challengeId, {
activeParticipants: activeParticipants?.map((ap) => ap.id),
});

const challenge = await this.dataService.challenges.findById(challengeId);
const problem = await this.dataService.problems.findById(challenge.problemId);

await this.dataService.problems.update(problem.id, { isAvailable: true });

await this.teamService.setupTeams(challengeId, activeParticipants);
this.lobbyService.changeStatus(challengeId, Status.ongoing);
}
Expand Down
5 changes: 4 additions & 1 deletion server/src/modules/problem/dtos/create-problem.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultCodes } from '@core/data/entities/problem.entity';
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsNumber, IsString } from 'class-validator';
import { IsArray, IsBoolean, IsNumber, IsString } from 'class-validator';

import { Difficulty } from '../models/enums';

Expand All @@ -21,4 +21,7 @@ export class CreateProblemDto {
@IsArray()
readonly defaultCodes: DefaultCodes[];

@ApiProperty()
@IsBoolean()
readonly isAvailable: boolean;
}
5 changes: 3 additions & 2 deletions server/src/modules/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateProblemDto } from './dtos/create-problem.dto';

@Injectable()
export class ProblemService {
constructor(private readonly dataService: IDataService) {}
constructor(private readonly dataService: IDataService) { }

async findAll(userId?: string) {
if (userId) return await this.dataService.queries.findProblems(userId);
Expand All @@ -14,7 +14,8 @@ export class ProblemService {

async findById(id: string) {
const problem = await this.dataService.problems.findById(id);
return problem;

if(problem.isAvailable) return problem;
}

async create(createProblemDto: CreateProblemDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const problemSchema = new Schema({
title: String,
content: String,
difficulty: Number,
isAvailable: Boolean,
defaultCodes: [{ type: Object }],
});