Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/OP-131/Dropdown-content #164

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pwa/src/apiService/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEFAULT_FOOTER_CONTENT_URL } from "../templates/templateParts/footer/Fo
import OpenWoo from "./resources/openWoo";
import FooterContent from "./resources/footerContent";
import Markdown from "./resources/markdown";
import FilterCount from "./resources/filterCount";
import AvailableFilters from "./resources/availableFilters";

interface PromiseMessage {
loading?: string;
Expand All @@ -33,7 +33,7 @@ export default class APIService {
});
}

public get FilterCountClient(): AxiosInstance {
public get AvailableFiltersClient(): AxiosInstance {
return axios.create({
baseURL: process.env.GATSBY_API_BASE_URL,
headers: {
Expand Down Expand Up @@ -66,8 +66,8 @@ export default class APIService {
return new OpenWoo(this.BaseClient, this.Send);
}

public get FilterCount(): FilterCount {
return new FilterCount(this.FilterCountClient, this.Send);
public get AvailableFilters(): AvailableFilters {
return new AvailableFilters(this.AvailableFiltersClient, this.Send);
}

public get FooterContent(): FooterContent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSendFunction } from "../apiService";
import { AxiosInstance } from "axios";

export default class FilterCount {
export default class AvailableFilters {
private _instance: AxiosInstance;
private _send: TSendFunction;

Expand All @@ -10,7 +10,7 @@ export default class FilterCount {
this._send = send;
}

public getCategoryCount = async (): Promise<any> => {
public getCategory = async (): Promise<any> => {
remko48 marked this conversation as resolved.
Show resolved Hide resolved
let endpoint = "/openWOO?_queries[]=Categorie";

if (process.env.GATSBY_OIDN_NUMBER) {
Expand Down
71 changes: 0 additions & 71 deletions pwa/src/data/PublicationType.ts

This file was deleted.

98 changes: 0 additions & 98 deletions pwa/src/data/features.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";

export const useFilterCount = () => {
export const useAvailableFilters = () => {
const API: APIService | null = React.useContext(APIContext);

const getCategoryCount = () =>
useQuery<any, Error>(["CategoryCount"], () => API?.FilterCount.getCategoryCount(), {
const getCategory = () =>
remko48 marked this conversation as resolved.
Show resolved Hide resolved
useQuery<any, Error>(["available_catagories"], () => API?.AvailableFilters.getCategory(), {
onError: (error) => {
console.warn(error.message);
},
});

return { getCategoryCount };
return { getCategory };
};
30 changes: 14 additions & 16 deletions pwa/src/templates/templateParts/filters/FiltersTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { Button } from "@utrecht/component-library-react/dist/css-module";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faMagnifyingGlass, faSpinner } from "@fortawesome/free-solid-svg-icons";
import { generateYearsArray } from "../../../data/years";
import { TEMP_PUBLICATION_TYPES } from "../../../data/PublicationType";
import { useTranslation } from "react-i18next";
import { filtersToUrlQueryParams } from "../../../services/filtersToQueryParams";
import { navigate } from "gatsby";
import { useGatsbyContext } from "../../../context/gatsby";
import { useFilterCount } from "../../../hooks/filterCount";
import { useAvailableFilters } from "../../../hooks/availableFilters";

interface FiltersTemplateProps {
isLoading: boolean;
Expand Down Expand Up @@ -62,7 +61,7 @@ export const FiltersTemplate: React.FC<FiltersTemplateProps> = ({ isLoading }) =
};

const handleSetSelectFormValues = (params: any): void => {
getItems.isSuccess &&
getCategories.isSuccess &&
setValue(
"category",
categoryOptions.find((option: any) => option.value === params.Categorie?.replace(/_/g, " ")),
Expand Down Expand Up @@ -105,19 +104,18 @@ export const FiltersTemplate: React.FC<FiltersTemplateProps> = ({ isLoading }) =
navigate(`/${filtersToUrlQueryParams(filters)}`);
}, [filters]);

const getItems = useFilterCount().getCategoryCount();
const getCategories = useAvailableFilters().getCategory();

React.useEffect(() => {
if (!getItems.isSuccess) return;
if (!getCategories.isSuccess) return;

const categoriesWithData = getItems.data.Categorie.map((test: any) => {
return TEMP_PUBLICATION_TYPES?.find((option) => {
return option.value === test._id.toLowerCase();
});
});
const categoriesWithData = getCategories.data.Categorie.map((category: any) => ({
label: _.upperFirst(category._id.toLowerCase()),
value: category._id.toLowerCase(),
}));

setCategoryOptions(Array.from(new Set(categoriesWithData)));
}, [getItems.isSuccess]);
setCategoryOptions(_.orderBy(_.uniqBy(categoriesWithData, "value"), "label", "asc"));
}, [getCategories.isSuccess]);

return (
<div id="filters" className={styles.container}>
Expand All @@ -144,15 +142,15 @@ export const FiltersTemplate: React.FC<FiltersTemplateProps> = ({ isLoading }) =
ariaLabel={t("Select year")}
/>

{getItems.isLoading && <Skeleton height="50px" />}
{getItems.isSuccess && (
{getCategories.isLoading && <Skeleton height="50px" />}
{getCategories.isSuccess && (
<SelectSingle
options={categoryOptions}
name="category"
placeholder={t("Category")}
defaultValue={TEMP_PUBLICATION_TYPES.find((option) => option.value === filters.Categorie)}
defaultValue={categoryOptions && categoryOptions.find((option: any) => option.value === filters.Categorie)}
isClearable
disabled={getItems.isLoading}
disabled={getCategories.isLoading}
{...{ register, errors, control }}
ariaLabel={t("Select category")}
/>
Expand Down
10 changes: 0 additions & 10 deletions pwa/src/templates/templateParts/footer/FooterTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export const FooterTemplate: React.FC = () => {
// setFooterContent(data);
// }, []);

React.useEffect(() => {
if (!process.env.GATSBY_FOOTER_CONTENT) return;

try {
setFooterContent(JSON.parse(process.env.GATSBY_FOOTER_CONTENT));
} catch {
console.warn("Could not parse footer content.");
}
}, [process.env.GATSBY_FOOTER_CONTENT]);

return (
<PageFooter className={styles.footer}>
<div className={styles.container}>
Expand Down
Loading