Skip to content

Commit

Permalink
Add presentation and methodologies filters
Browse files Browse the repository at this point in the history
  • Loading branch information
akmatoff committed May 26, 2024
1 parent 37f97d3 commit 4e6ac6c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/interfaces/methodology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export interface IMethodologyCreate {
filePath: string;
topicId: number;
}

export interface IMethodologyFilters {
topicId?: number | null;
}
4 changes: 4 additions & 0 deletions src/interfaces/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export interface IPresentationCreate {
filePath: string;
topicId: number;
}

export interface IPresentationFilters {
topicId?: number | null;
}
8 changes: 6 additions & 2 deletions src/pages/methodologies/MethodologiesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import ResourceList from "@/components/shared/ResourceList/ResourceList";
import MethodologiesTable from "./components/MethodologiesTable";
import { useMethodologies } from "@/queries/methodologies";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import { ROUTES } from "@/constants/routes";

function MethodologiesPage() {
const navigate = useNavigate();

const { methodologies, isMethodologiesLoading } = useMethodologies();
const [searchParams] = useSearchParams();

const { methodologies, isMethodologiesLoading } = useMethodologies({
topicId: Number(searchParams.get("topicId")),
});

return (
<ResourceList
Expand Down
8 changes: 6 additions & 2 deletions src/pages/presentations/PresentationsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import ResourceList from "@/components/shared/ResourceList/ResourceList";
import PresentationsTable from "./components/PresentationsTable";
import { usePresentations } from "@/queries/presentations";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import { ROUTES } from "@/constants/routes";

function PresentationsPage() {
const navigate = useNavigate();

const { presentations, isPresentationsLoading } = usePresentations();
const [searchParams] = useSearchParams();

const { presentations, isPresentationsLoading } = usePresentations({
topicId: Number(searchParams.get("topicId")),
});

return (
<ResourceList
Expand Down
11 changes: 7 additions & 4 deletions src/queries/methodologies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QUERY_KEYS } from "@/constants/queryKeys";
import { IMethodologyCreate } from "@/interfaces/methodology";
import {
IMethodologyCreate,
IMethodologyFilters,
} from "@/interfaces/methodology";
import {
createMethodology,
deleteMethodology,
Expand All @@ -9,10 +12,10 @@ import {
} from "@/requests/methodologies";
import { useMutation, useQuery } from "@tanstack/react-query";

export const useMethodologies = () => {
export const useMethodologies = (filters?: IMethodologyFilters) => {
const { data, isLoading } = useQuery({
queryKey: [QUERY_KEYS.METHODOLOGIES],
queryFn: getMethodologies,
queryKey: [QUERY_KEYS.METHODOLOGIES, filters?.topicId],
queryFn: () => getMethodologies(filters),
});

return {
Expand Down
11 changes: 7 additions & 4 deletions src/queries/presentations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QUERY_KEYS } from "@/constants/queryKeys";
import { IPresentationCreate } from "@/interfaces/presentation";
import {
IPresentationCreate,
IPresentationFilters,
} from "@/interfaces/presentation";
import {
createPresentation,
deletePresentation,
Expand All @@ -9,10 +12,10 @@ import {
} from "@/requests/presentations";
import { useMutation, useQuery } from "@tanstack/react-query";

export const usePresentations = () => {
export const usePresentations = (filters?: IPresentationFilters) => {
const { data, isLoading } = useQuery({
queryKey: [QUERY_KEYS.PRESENTATIONS],
queryFn: getPresentations,
queryKey: [QUERY_KEYS.PRESENTATIONS, filters?.topicId],
queryFn: () => getPresentations(filters),
});

return {
Expand Down
18 changes: 15 additions & 3 deletions src/requests/methodologies.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { API_METHODOLOGIES } from "@/constants/apiConstants";
import { request } from "./request";
import { IMethodology, IMethodologyCreate } from "@/interfaces/methodology";
import {
IMethodology,
IMethodologyCreate,
IMethodologyFilters,
} from "@/interfaces/methodology";

export async function getMethodologies(): Promise<IMethodology[]> {
return request.get(API_METHODOLOGIES).then(({ data }) => data);
export async function getMethodologies(
filters?: IMethodologyFilters
): Promise<IMethodology[]> {
return request
.get(API_METHODOLOGIES, {
params: {
...(filters?.topicId && { topicId: filters.topicId }),
},
})
.then(({ data }) => data);
}

export async function getMethodologyDetails(id: number): Promise<IMethodology> {
Expand Down
18 changes: 15 additions & 3 deletions src/requests/presentations.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { API_PRESENTATIONS } from "@/constants/apiConstants";
import { request } from "./request";
import { IPresentation, IPresentationCreate } from "@/interfaces/presentation";
import {
IPresentation,
IPresentationCreate,
IPresentationFilters,
} from "@/interfaces/presentation";

export async function getPresentations(): Promise<IPresentation[]> {
return request.get(API_PRESENTATIONS).then(({ data }) => data);
export async function getPresentations(
filters?: IPresentationFilters
): Promise<IPresentation[]> {
return request
.get(API_PRESENTATIONS, {
params: {
...(filters?.topicId && { topicId: filters.topicId }),
},
})
.then(({ data }) => data);
}

export async function getPresentationDetails(
Expand Down

0 comments on commit 4e6ac6c

Please sign in to comment.