Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolelim02 committed Sep 19, 2024
1 parent 3b41350 commit 1730d34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
12 changes: 6 additions & 6 deletions frontend/src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { FunctionComponent } from "react";
import AppMargin from "../AppMargin";
import { useNavigate } from "react-router-dom";

type NavbarItems = { label: string; link: string };
type NavbarItem = { label: string; link: string };

const Navbar: FunctionComponent = () => {
const navbarItems: Array<NavbarItems> = [
{ label: "Questions", link: "/questions" },
];
type NavbarProps = { navbarItems?: Array<NavbarItem> };

const Navbar: FunctionComponent<NavbarProps> = (props: NavbarProps) => {
const { navbarItems = [{ label: "Questions", link: "/" }] } = props;
const navigate = useNavigate();

return (
Expand All @@ -29,7 +29,7 @@ const Navbar: FunctionComponent = () => {
<Typography
component={Box}
variant="h5"
sx={[{ flexGrow: 1 }, { "&:hover": { cursor: "pointer" } }]}
sx={[{ flexGrow: 1, "&:hover": { cursor: "pointer" } }]}
onClick={() => navigate("/")}
>
PeerPrep
Expand Down
23 changes: 8 additions & 15 deletions frontend/src/reducers/questionReducer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Dispatch } from "react";
// import { questionClient } from "../utils/api";

type QuestionInfo = {
questionId: string;
title: string;
complexity: string;
categories: Array<string>;
};

type QuestionDetail = {
questionId: string;
title: string;
Expand All @@ -22,15 +15,21 @@ enum QuestionActionTypes {

type QuestionActions = {
type: QuestionActionTypes;
payload: QuestionDetail;
payload: Array<QuestionDetail> | QuestionDetail;
};

type QuestionsState = {
questions: Array<QuestionInfo>;
questions: Array<QuestionDetail>;
selectedQuestion: QuestionDetail | null;
selectedQuestionError: string | null;
};

const isQuestionList = (
questionsList: Array<QuestionDetail> | QuestionDetail
): questionsList is Array<QuestionDetail> => {
return Array.isArray(questionsList);
};

export const initialState: QuestionsState = {
questions: [],
selectedQuestion: null,
Expand Down Expand Up @@ -67,12 +66,6 @@ export const getQuestionById = (
});
};

const isQuestionList = (
questionsList: Array<QuestionInfo> | QuestionDetail
): questionsList is Array<QuestionInfo> => {
return Array.isArray(questionsList);
};

const reducer = (
state: QuestionsState,
action: QuestionActions
Expand Down

0 comments on commit 1730d34

Please sign in to comment.