Skip to content

Commit 4da97d6

Browse files
committed
Fix linter
1 parent a4731a6 commit 4da97d6

File tree

9 files changed

+49
-66
lines changed

9 files changed

+49
-66
lines changed

frontend/src/api/leetcode-dashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const getLeetcodeDashboardData = async (): Promise<
4040

4141
export const fetchSingleLeetcodeQuestion = async (
4242
questionId: string
43-
): Promise<any> => {
43+
): Promise<QuestionFull> => {
4444
const url = `${QUESTION_SERVICE}/${questionId}`;
4545
const response = await fetch(url);
4646
const data = await response.json();

frontend/src/app/(auth)/leetcode-dashboard/AddQuestionDialog.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use client";
22

3-
import { topicsList } from "@/app/(auth)/match/page";
43
import { Button } from "@/components/ui/button";
54
import {
65
Form,
@@ -21,14 +20,9 @@ import Swal from "sweetalert2";
2120
import { z } from "zod";
2221
import MoonLoader from "react-spinners/MoonLoader";
2322
import { createSingleLeetcodeQuestion } from "@/api/leetcode-dashboard";
23+
import { topicsList } from "@/utils/constants";
2424

25-
const QUESTION_SERVICE = process.env.NEXT_PUBLIC_QUESTION_SERVICE;
26-
27-
interface AddQuestionDialogProp {
28-
setClose: () => void;
29-
}
30-
31-
const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
25+
const AddQuestionDialog = () => {
3226
const [isSubmitting, setIsSubmitting] = useState(false);
3327

3428
const formSchema = z.object({
@@ -65,14 +59,14 @@ const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
6559
category: values.questionTopics,
6660
complexity: values.questionDifficulty,
6761
})
68-
.then((response) => {
62+
.then(() => {
6963
Swal.fire({
7064
icon: "success",
7165
title: "Question Added",
7266
text: "Question has been added successfully.",
7367
});
7468
})
75-
.catch((error) => {
69+
.catch(() => {
7670
Swal.fire({
7771
icon: "error",
7872
title: "Question Add Failed",
@@ -81,7 +75,6 @@ const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
8175
})
8276
.finally(() => {
8377
setIsSubmitting(false);
84-
setClose();
8578
});
8679
}
8780

frontend/src/app/(auth)/leetcode-dashboard/EditQuestionDialog.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use client";
22

3-
import { capitalizeWords, topicsList } from "@/app/(auth)/match/page";
43
import { Button } from "@/components/ui/button";
54
import {
65
Form,
@@ -24,27 +23,31 @@ import {
2423
fetchSingleLeetcodeQuestion,
2524
updateSingleLeetcodeQuestion,
2625
} from "@/api/leetcode-dashboard";
27-
28-
const QUESTION_SERVICE = process.env.NEXT_PUBLIC_QUESTION_SERVICE;
26+
import { capitalizeWords } from "@/utils/string_utils";
27+
import { topicsList } from "@/utils/constants";
2928

3029
interface EditQuestionDialogProp {
31-
setClose: () => void;
3230
questionId: string;
3331
}
3432

35-
const initialValues = {
33+
interface EditQuestionValues {
34+
questionTitle: string;
35+
questionDifficulty: string;
36+
questionTopics: string[];
37+
questionDescription: string;
38+
}
39+
40+
const initialValues: EditQuestionValues = {
3641
questionTitle: "",
3742
questionDifficulty: "",
3843
questionTopics: [],
3944
questionDescription: "",
4045
};
4146

42-
const EditQuestionDialog = ({
43-
setClose,
44-
questionId,
45-
}: EditQuestionDialogProp) => {
47+
const EditQuestionDialog = ({ questionId }: EditQuestionDialogProp) => {
4648
const [isSubmitting, setIsSubmitting] = useState(false);
47-
const [leetcodeData, setLeetcodeData] = useState(initialValues);
49+
const [leetcodeData, setLeetcodeData] =
50+
useState<EditQuestionValues>(initialValues);
4851
const formSchema = z.object({
4952
questionTitle: z.string().min(2, {
5053
message: "Title must be at least 2 characters.",
@@ -75,8 +78,6 @@ const EditQuestionDialog = ({
7578
questionTopics: resp.category.map((x: string) => capitalizeWords(x)),
7679
questionDescription: resp.description,
7780
};
78-
console.log(questionData.questionTopics);
79-
console.log(typeof questionData.questionTopics);
8081
setLeetcodeData(questionData);
8182
reset(questionData);
8283
});
@@ -92,14 +93,14 @@ const EditQuestionDialog = ({
9293
complexity: values.questionDifficulty,
9394
questionId: questionId,
9495
})
95-
.then((response) => {
96+
.then(() => {
9697
Swal.fire({
9798
icon: "success",
9899
title: "Question Added",
99100
text: "Question has been modified successfully.",
100101
});
101102
})
102-
.catch((error) => {
103+
.catch(() => {
103104
Swal.fire({
104105
icon: "error",
105106
title: "Question Add Failed",
@@ -108,7 +109,6 @@ const EditQuestionDialog = ({
108109
})
109110
.finally(() => {
110111
setIsSubmitting(false);
111-
setClose();
112112
});
113113
}
114114

frontend/src/app/(auth)/leetcode-dashboard/LeetcodeDashboardTable.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ const Cell = ({
4646

4747
export function LeetcodeDashboardTable() {
4848
const [data, setData] = useState<QuestionMinified[]>([]);
49-
const [modalIsOpen, setIsOpen] = useState(false);
50-
const [isDeleting, setIsDeleting] = useState(false);
5149
const [editingQuestionId, setEditingQuestionId] = React.useState<
5250
string | null
5351
>(null);
5452
const [refreshKey, setRefreshKey] = useState(0); // State to trigger re-fetch
5553

5654
function handleDelete(questionId: string) {
57-
setIsDeleting(true);
5855
Swal.fire({
5956
icon: "warning",
6057
title: "Confirm delete?",
@@ -71,21 +68,17 @@ export function LeetcodeDashboardTable() {
7168
setRefreshKey((prev) => prev + 1);
7269
} catch (error) {
7370
Swal.showValidationMessage(`Failed to delete question: ${error}`);
74-
} finally {
75-
setIsDeleting(false);
7671
}
7772
},
7873
allowOutsideClick: () => !Swal.isLoading(),
7974
});
8075
}
8176

8277
function openModal(questionId: string) {
83-
setIsOpen(true);
8478
setEditingQuestionId(questionId);
8579
}
8680

8781
function closeModal() {
88-
setIsOpen(false);
8982
setEditingQuestionId(null);
9083
}
9184

@@ -155,10 +148,7 @@ export function LeetcodeDashboardTable() {
155148
variants={modalAnimation}
156149
transition={{ duration: 0.3 }}
157150
>
158-
<EditQuestionDialog
159-
setClose={closeModal}
160-
questionId={questionId}
161-
/>
151+
<EditQuestionDialog questionId={questionId} />
162152
</motion.div>
163153
</Modal>
164154
<Button variant={"ghost"} onClick={() => handleDelete(questionId)}>
@@ -171,10 +161,7 @@ export function LeetcodeDashboardTable() {
171161
];
172162

173163
useEffect(() => {
174-
setIsDeleting(true);
175-
getLeetcodeDashboardData()
176-
.then((data) => setData(data))
177-
.finally(() => setIsDeleting(false));
164+
getLeetcodeDashboardData().then((data) => setData(data));
178165
}, [refreshKey]);
179166

180167
const table = useReactTable({

frontend/src/app/(auth)/leetcode-dashboard/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const LeetcodeDashboard = () => {
7272
variants={modalAnimation}
7373
transition={{ duration: 0.3 }}
7474
>
75-
<AddQuestionDialog setClose={closeModal} />
75+
<AddQuestionDialog />
7676
</motion.div>
7777
</Modal>
7878
</div>

frontend/src/app/(auth)/match/page.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,14 @@ import {
1616
QuestionLanguages,
1717
QuestionTopics,
1818
} from "@/types/find-match";
19+
import { capitalizeWords } from "@/utils/string_utils";
1920
import { useForm } from "react-hook-form";
2021

2122
interface FindMatchFormOutput {
2223
questionDifficulty: string;
2324
preferredLanguages: string;
2425
}
2526

26-
export function capitalizeWords(input: string): string {
27-
return input
28-
.split(" ") // Split the string by spaces to get each word
29-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter and lowercase the rest
30-
.join(" "); // Join the words back into a single string
31-
}
32-
33-
export const preferredLanguagesList = Object.values(QuestionLanguages).map(
34-
(ql) => {
35-
return {
36-
label: ql,
37-
value: ql,
38-
};
39-
}
40-
);
41-
42-
export const topicsList = Object.values(QuestionTopics).map((qt) => {
43-
return {
44-
label: qt,
45-
value: qt,
46-
};
47-
});
48-
4927
const FindPeerHeader = () => {
5028
return (
5129
<div className="flex flex-col mt-8">

frontend/src/types/find-match.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// eslint-disable no-invalid-page-export
2+
13
export enum QuestionDifficulty {
24
EASY = "easy",
35
MEDIUM = "medium",

frontend/src/utils/constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { QuestionLanguages, QuestionTopics } from "@/types/find-match";
2+
3+
export const preferredLanguagesList = Object.values(QuestionLanguages).map(
4+
(ql) => {
5+
return {
6+
label: ql,
7+
value: ql,
8+
};
9+
}
10+
);
11+
12+
export const topicsList = Object.values(QuestionTopics).map((qt) => {
13+
return {
14+
label: qt,
15+
value: qt,
16+
};
17+
});

frontend/src/utils/string_utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function capitalizeWords(input: string): string {
2+
return input
3+
.split(" ") // Split the string by spaces to get each word
4+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter and lowercase the rest
5+
.join(" "); // Join the words back into a single string
6+
}

0 commit comments

Comments
 (0)