Skip to content

Commit

Permalink
fix: studymaterial fetch action identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
akshat-OwO committed Nov 2, 2024
1 parent 795df50 commit e42ef78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
38 changes: 22 additions & 16 deletions src/components/StudyMaterial.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { Tab } from "@/config";
import { Courses, Tab } from "@/config";
import { useEmbed } from "@/hooks/use-embed";
import { useFeedback } from "@/hooks/use-feedback";
import { getBcaStudyMaterial, getBtechStudyMaterial } from "@/lib/server";
Expand All @@ -22,7 +22,7 @@ import axios, { AxiosResponse } from "axios";

interface StudyMaterialProps {
tab: Tab;
course: string;
course: Courses;
semester: string | null;
branch: string | null;
subject: string | null;
Expand Down Expand Up @@ -53,24 +53,28 @@ const StudyMaterial = ({
};

const generateQueryKey = (): QueryKey => {
if (course == "btech") {
if (course === Courses.BTECH) {
return [course, tab, semester, branch, subject];
} else if (course === Courses.BCA) {
return [course, tab, semester, subject];
}
return [course, tab, semester, subject];
return [];
};

const generateUpvoteQueryKey = (): QueryKey => {
if (course == "btech") {
if (course === Courses.BTECH) {
return ["votes", course, tab, semester, branch, subject];
} else if (course === Courses.BCA) {
return ["votes", course, tab, semester, subject];
}
return ["votes", course, tab, semester, subject];
return [];
};

const { data, isLoading, error, refetch, isFetching } = useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: generateQueryKey(),
queryFn: async () => {
if (course == "btech") {
if (course === Courses.BTECH) {
return await getBtechStudyMaterial({
semester,
branch,
Expand All @@ -81,16 +85,18 @@ const StudyMaterial = ({
practical,
pyq,
});
} else if (course === Courses.BCA) {
return await getBcaStudyMaterial({
semester,
subject,
tab,
book,
note,
practical,
pyq,
});
}
return await getBcaStudyMaterial({
semester,
subject,
tab,
book,
note,
practical,
pyq,
});
return null;
},
});

Expand Down
6 changes: 3 additions & 3 deletions src/components/SubjectView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { Tab } from "@/config";
import { Courses, Tab } from "@/config";
import { useSubjectView } from "@/hooks/use-subject-view";
import { cn } from "@/lib/utils";
import { Expand } from "lucide-react";
Expand All @@ -16,7 +16,7 @@ import { Tabs, TabsList, TabsTrigger } from "./ui/tabs";
import { SubjectDetail } from "@/lib/server";

interface SubjectViewProps {
course: string;
course: Courses;
subjectDetail: SubjectDetail;
isModal?: boolean;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ SubjectView.Box = function SubjectViewBox({
}: {
sub: SubjectDetail;
tab: Tab;
course: string;
course: Courses;
semester: string | null;
branch: string | null;
subject: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const getBtechStudyMaterial = async ({
}) => {
if (
!semesterList.some((s) => semester === s.label) ||
!branchList.some((b) => branch === b.value) ||
!branchList.some((b) => branch === b.value.toLowerCase()) ||
!subject
) {
throw new AxiosError("Please check again what you searched.");
Expand Down

0 comments on commit e42ef78

Please sign in to comment.