Skip to content

Commit 1730d34

Browse files
committed
Refactor code
1 parent 3b41350 commit 1730d34

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

frontend/src/components/Navbar/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { FunctionComponent } from "react";
44
import AppMargin from "../AppMargin";
55
import { useNavigate } from "react-router-dom";
66

7-
type NavbarItems = { label: string; link: string };
7+
type NavbarItem = { label: string; link: string };
88

9-
const Navbar: FunctionComponent = () => {
10-
const navbarItems: Array<NavbarItems> = [
11-
{ label: "Questions", link: "/questions" },
12-
];
9+
type NavbarProps = { navbarItems?: Array<NavbarItem> };
10+
11+
const Navbar: FunctionComponent<NavbarProps> = (props: NavbarProps) => {
12+
const { navbarItems = [{ label: "Questions", link: "/" }] } = props;
1313
const navigate = useNavigate();
1414

1515
return (
@@ -29,7 +29,7 @@ const Navbar: FunctionComponent = () => {
2929
<Typography
3030
component={Box}
3131
variant="h5"
32-
sx={[{ flexGrow: 1 }, { "&:hover": { cursor: "pointer" } }]}
32+
sx={[{ flexGrow: 1, "&:hover": { cursor: "pointer" } }]}
3333
onClick={() => navigate("/")}
3434
>
3535
PeerPrep

frontend/src/reducers/questionReducer.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { Dispatch } from "react";
22
// import { questionClient } from "../utils/api";
33

4-
type QuestionInfo = {
5-
questionId: string;
6-
title: string;
7-
complexity: string;
8-
categories: Array<string>;
9-
};
10-
114
type QuestionDetail = {
125
questionId: string;
136
title: string;
@@ -22,15 +15,21 @@ enum QuestionActionTypes {
2215

2316
type QuestionActions = {
2417
type: QuestionActionTypes;
25-
payload: QuestionDetail;
18+
payload: Array<QuestionDetail> | QuestionDetail;
2619
};
2720

2821
type QuestionsState = {
29-
questions: Array<QuestionInfo>;
22+
questions: Array<QuestionDetail>;
3023
selectedQuestion: QuestionDetail | null;
3124
selectedQuestionError: string | null;
3225
};
3326

27+
const isQuestionList = (
28+
questionsList: Array<QuestionDetail> | QuestionDetail
29+
): questionsList is Array<QuestionDetail> => {
30+
return Array.isArray(questionsList);
31+
};
32+
3433
export const initialState: QuestionsState = {
3534
questions: [],
3635
selectedQuestion: null,
@@ -67,12 +66,6 @@ export const getQuestionById = (
6766
});
6867
};
6968

70-
const isQuestionList = (
71-
questionsList: Array<QuestionInfo> | QuestionDetail
72-
): questionsList is Array<QuestionInfo> => {
73-
return Array.isArray(questionsList);
74-
};
75-
7669
const reducer = (
7770
state: QuestionsState,
7871
action: QuestionActions

0 commit comments

Comments
 (0)