Skip to content

Commit

Permalink
fix(link-publications): add landingpage link to publi
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jun 20, 2024
1 parent a96c141 commit 8ed60af
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/api/contribution-api/getLandingPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useQuery } from "@tanstack/react-query";
import { postHeaders } from "../../config/api";
import { Publication } from "../../types";

const LandingPage = (id: string) => {
const fetchContributions = async (): Promise<Publication> => {
const response = await fetch(
"https://scanr.enseignementsup-recherche.gouv.fr/api/scanr-publications/_search",
{
method: "POST",
headers: postHeaders,
body: JSON.stringify({
_source: ["landingPage"],
query: {
match: { id: id },
},
}),
}
);

if (!response.ok) {
throw new Error("Network response was not ok");
}

return response.json();
};

const { data, error, isLoading } = useQuery(
["contributions", id],
fetchContributions
);

const landingPage = data?.hits?.hits?.[0]?._source.landingPage;

return { landingPage, isLoading, error };
};

export default LandingPage;
21 changes: 19 additions & 2 deletions src/pages/api-operation-page/link-publications/external-links.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Link } from "@dataesr/dsfr-plus";
import { useState } from "react";
import LandingPage from "../../../api/contribution-api/getLandingPage";

export const ExternalLinks = ({ productionId, name }) => {
const formattedProductionId = productionId.replace(/\//g, "%2f");
const [google, setGoogleClicked] = useState(false);
const [scanRClicked, setScanRClicked] = useState(false);
const [landingPageClicked, setLandingPageClicked] = useState(false);
const { landingPage } = LandingPage(productionId);
return (
<>
<Link
className={`fr-ml-5w fr-mr-5w fr-footer__content-link ${
className={` fr-ml-2w fr-footer__content-link ${
scanRClicked ? "clicked-link" : ""
}`}
target="_blank"
Expand All @@ -18,8 +21,22 @@ export const ExternalLinks = ({ productionId, name }) => {
>
scanR
</Link>
{landingPage && (
<Link
className={` fr-ml-2w fr-mr-2w fr-footer__content-link ${
landingPageClicked ? "clicked-link" : ""
}`}
target="_blank"
rel="noreferrer noopener external"
href={landingPage}
onClick={() => setLandingPageClicked(true)}
>
Editeur
</Link>
)}

<Link
className={`fr-mr-1w fr-footer__content-link ${
className={`fr-ml-2w fr-footer__content-link ${
google ? "clicked-link" : ""
}`}
target="_blank"
Expand Down
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ export interface PersonInfo {
email: string;
phone: string;
}
export type Publication = {
hits: any;
// id: string;
// isOa: boolean;
// type: string;
// year: number;
landingPage?: string;
};

0 comments on commit 8ed60af

Please sign in to comment.