diff --git a/apps/climatemappedafrica/src/components/Page/Base.js b/apps/climatemappedafrica/src/components/Page/Base.js index 8d8336526..870fd2dbf 100644 --- a/apps/climatemappedafrica/src/components/Page/Base.js +++ b/apps/climatemappedafrica/src/components/Page/Base.js @@ -77,10 +77,4 @@ BasePage.propTypes = { variant: PropTypes.string, }; -BasePage.defaultProps = { - children: undefined, - menus: undefined, - variant: undefined, -}; - export default BasePage; diff --git a/apps/climatemappedafrica/src/functions/getImagePlaceholder.js b/apps/climatemappedafrica/src/functions/getImagePlaceholder.js deleted file mode 100644 index 48624bddb..000000000 --- a/apps/climatemappedafrica/src/functions/getImagePlaceholder.js +++ /dev/null @@ -1,15 +0,0 @@ -// import { getPlaiceholder } from "plaiceholder"; - -export default async function getImagePlaceholder(src) { - if (!src) { - return null; - } - // try { - // const { base64, img } = await getPlaiceholder(src); - // const placeholder = base64?.length ? "blur" : "empty"; - // return { ...img, blurDataURL: base64, placeholder }; - // } catch (err) { - // // do nothing; - // } - return null; -} diff --git a/apps/climatemappedafrica/src/utils/fetchApi.js b/apps/climatemappedafrica/src/utils/fetchApi.js deleted file mode 100644 index 00700db10..000000000 --- a/apps/climatemappedafrica/src/utils/fetchApi.js +++ /dev/null @@ -1,10 +0,0 @@ -export default async function fetchAPI(...options) { - return fetch(...options) - .then((res) => { - if (!res.ok) { - throw Error(res.status || res.statusText); - } - return res; - }) - .then((res) => res.json()); -} diff --git a/apps/climatemappedafrica/src/utils/fetchOpenAfricaDatasets.js b/apps/climatemappedafrica/src/utils/fetchOpenAfricaDatasets.js deleted file mode 100644 index 8b6588eda..000000000 --- a/apps/climatemappedafrica/src/utils/fetchOpenAfricaDatasets.js +++ /dev/null @@ -1,72 +0,0 @@ -import fetchJson from "./fetchJson"; - -const DATASET_API_PATH = "/api/3/action/package_show?id="; -const GROUP_API_PATH = "/api/3/action/package_search?fq=groups:"; - -function formatDate(date) { - try { - return `Updated: ${new Date(date).toISOString().substr(0, 10)}`; - } catch (e) { - return date || null; - } -} - -async function extractDatasets(origin, results) { - return results.map((result) => { - const { - metadata_modified: updatedAt, - name, - notes: description, - title, - } = result; - const types = [...new Set(result.resources?.map(({ format }) => format))]; - return { - date: formatDate(updatedAt), - description, - href: `${origin}/dataset/${name}`, - title, - type: "dataset", - types, - }; - }); -} - -async function fetchOpenAfricaDatasets(source) { - const { href } = source; - try { - const url = new URL(href); - if ( - process.env.NEXT_PUBLIC_OPENAFRICA_DOMAINS.split(",") - .map((d) => d.trim()) - .includes(url.hostname) - ) { - const { pathname } = url; - let apiPath; - if (pathname.startsWith("/dataset/")) { - const id = pathname.replace("/dataset/", "").split("/")[0]; - if (id) { - apiPath = `${DATASET_API_PATH}${id}`; - } - } else if (pathname.startsWith("/group/")) { - const groups = pathname.replace("/group/", "").split("/")[0]; - if (groups) { - apiPath = `${GROUP_API_PATH}${groups}`; - } - } - if (apiPath) { - const json = await fetchJson(`${url.origin}${apiPath}`); - // group datasets are in result.results while individual dataset - // is in result - const results = json.result.results || [json.result]; - return extractDatasets(url.origin, results); - } - } - } catch (e) { - /* We'll return original source */ - } - - const { date, ...others } = source; - return { ...others, date: formatDate(date) }; -} - -export default fetchOpenAfricaDatasets; diff --git a/apps/climatemappedafrica/src/utils/fetchSourceAfricaDocuments.js b/apps/climatemappedafrica/src/utils/fetchSourceAfricaDocuments.js deleted file mode 100644 index 7272e3147..000000000 --- a/apps/climatemappedafrica/src/utils/fetchSourceAfricaDocuments.js +++ /dev/null @@ -1,64 +0,0 @@ -import fetchJson from "./fetchJson"; - -function formatDate(date) { - try { - return new Date(date).toISOString().substr(0, 4); - } catch (e) { - return date || null; - } -} - -async function extractDocuments(results) { - return results.map((result) => { - const { - canonical_url: href, - description, - title, - updated_at: updatedAt, - } = result; - return { - date: formatDate(updatedAt), - description, - href, - title, - }; - }); -} - -async function fetchSourceAfricaDocuments(source) { - const { href } = source; - try { - const url = new URL(href); - if ( - process.env.NEXT_PUBLIC_SOURCEAFRICA_DOMAINS.split(",") - .map((d) => d.trim()) - .includes(url.hostname) - ) { - const { pathname } = url; - let apiPath; - if (pathname.startsWith("/documents/") && pathname.endsWith(".html")) { - apiPath = pathname.replace(/\.html$/, ".json"); - } else if (pathname.startsWith("/search/")) { - // Both groups (/search/Group:GGG) and accounts (/search/Account:AAA) - const search = pathname.replace(/\/$/, ""); - // We'll load a maximum of 25 documents from a group - apiPath = `/api${search}.json?per_page=25`; - } - if (apiPath) { - const json = await fetchJson(`${url.origin}${apiPath}`); - // group documents are in json.documents while individual document - // is in json - // NOTE: by default, - const results = json.documents || [json]; - return extractDocuments(results); - } - } - } catch (e) { - /* We'll return original source */ - } - - const { date, ...others } = source; - return { ...others, date: formatDate(date) }; -} - -export default fetchSourceAfricaDocuments; diff --git a/apps/climatemappedafrica/src/utils/formatStoryPosts.js b/apps/climatemappedafrica/src/utils/formatStoryPosts.js deleted file mode 100644 index 23d8b9e49..000000000 --- a/apps/climatemappedafrica/src/utils/formatStoryPosts.js +++ /dev/null @@ -1,34 +0,0 @@ -import getImagePlaceholder from "@/climatemappedafrica/functions/getImagePlaceholder"; - -export default async function formatStoryPosts(posts) { - return Promise.all( - posts?.map( - async ({ - title, - excerpt, - uri, - featuredImage, - blocks: postBlocks, - slug, - }) => { - const chartBlock = postBlocks?.find( - (b) => - Object.hasOwnProperty.call(b, "name") && - b?.name === "lazyblock/insight-chart", - ); - - const image = featuredImage?.node?.sourceUrl ?? null; - const imageProps = await getImagePlaceholder(image); - return { - title, - slug, - description: excerpt?.replace(/<[^>]+>/g, "") ?? "", - href: `/stories${uri}`, - image, - imageProps: imageProps ?? null, - chart: chartBlock?.attributes?.chart ?? null, - }; - }, - ) ?? [], - ); -} diff --git a/apps/climatemappedafrica/src/utils/useProgressiveImage.js b/apps/climatemappedafrica/src/utils/useProgressiveImage.js deleted file mode 100644 index 3a27357ec..000000000 --- a/apps/climatemappedafrica/src/utils/useProgressiveImage.js +++ /dev/null @@ -1,15 +0,0 @@ -import { useEffect, useState } from "react"; - -const useProgressiveImage = (src) => { - const [sourceLoaded, setSourceLoaded] = useState(null); - - useEffect(() => { - /* eslint-env browser */ - const img = new Image(); - img.src = src; - img.onload = () => setSourceLoaded(src); - }, [src]); - - return sourceLoaded; -}; -export default useProgressiveImage;