|
| 1 | +import { useQuery } from "@apollo/client"; |
| 2 | +import { useGlobalContext } from "@context"; |
| 3 | +import { Page1Query } from "./page1.graphql"; |
| 4 | +import { ElementTemplate } from "@components/base/element/element.template"; |
| 5 | +import { ElementNodeFragment, Page1DataFragment } from "@generated/graphql"; |
| 6 | +import { extractText } from "../justpage/justpage.template"; |
| 7 | +import { getContentByPath } from "@components/base/templates/metadata.graphql"; |
| 8 | + |
| 9 | +export interface Page1TemplateProps { |
| 10 | + contentGuid?: string | null; // Content GUID |
| 11 | + version?: string | null; // Optional version |
| 12 | + locale?: string | null; // Optional locale |
| 13 | + // Or queried by just URL |
| 14 | + url?: string | null; // Matched against the URL.Default |
| 15 | +} |
| 16 | + |
| 17 | +export const Page1Template: React.FC<Page1TemplateProps> = ({ |
| 18 | + url, |
| 19 | + contentGuid, |
| 20 | +}) => { |
| 21 | + const { setIsLoading } = useGlobalContext(); |
| 22 | + |
| 23 | + // const { data, refetch, error, loading } = useQuery(Page1Query, { |
| 24 | + // variables: { url, key: contentGuid }, |
| 25 | + // notifyOnNetworkStatusChange: true, |
| 26 | + // onError: (error) => { |
| 27 | + // console.error("[QUERY] Error fetching Experience", error); |
| 28 | + // // refetch(queryVariables); |
| 29 | + // }, |
| 30 | + // onCompleted: (data) => { |
| 31 | + // console.log("[QUERY] Query finished with variables", {}, data); |
| 32 | + // setIsLoading(false); |
| 33 | + // }, |
| 34 | + // }); |
| 35 | + |
| 36 | + const { data, refetch, error, loading } = useQuery(getContentByPath, { |
| 37 | + variables: { url: url! }, |
| 38 | + notifyOnNetworkStatusChange: true, |
| 39 | + onError: (error) => { |
| 40 | + console.error("[QUERY] Error fetching Experience", error); |
| 41 | + // refetch(queryVariables); |
| 42 | + setIsLoading(false); |
| 43 | + }, |
| 44 | + onCompleted: (data) => { |
| 45 | + console.log("[QUERY] Query finished with variables", {}, data); |
| 46 | + setIsLoading(false); |
| 47 | + }, |
| 48 | + }); |
| 49 | + |
| 50 | + const contentItem = data?.content?.items?.[0] as Page1DataFragment; |
| 51 | + |
| 52 | + const paragraph = extractText(contentItem?.Block?.Text?.json) || ""; |
| 53 | + |
| 54 | + return ( |
| 55 | + <article className="relative experience theme--blue"> |
| 56 | + <section className="opti-container outer-padding padding-top--medium padding-bottom--medium"> |
| 57 | + <div className="opti-container__content container-narrow"> |
| 58 | + <p>{paragraph}</p> |
| 59 | + </div> |
| 60 | + </section> |
| 61 | + </article> |
| 62 | + ); |
| 63 | +}; |
0 commit comments