Skip to content

Commit

Permalink
add trusted by images
Browse files Browse the repository at this point in the history
  • Loading branch information
bonhokage06 committed Oct 18, 2024
1 parent 3dfd559 commit 98fc4f6
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 67 deletions.
9 changes: 4 additions & 5 deletions apps/website/src/app/clientLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import { Anchor } from "@lilypad/shared-components";
import Footer from "@/components/Footer";
import { animated, useSpring } from "@react-spring/web";
import { createContext } from "react";
import useStrapi, { StrapiContext } from "./hooks/UseStrapi";
import useStrapi from "./hooks/strapi/UseStrapi";
import { StrapiContext } from "./hooks/strapi/types";

const INTER = Inter({ subsets: ["latin"] });

export const PageContext: Context<StrapiContext> = createContext({
strapi: {
mission_statement: "",
},
strapi: {},
});

export default function ClientLayout({
Expand All @@ -46,7 +45,7 @@ export default function ClientLayout({
);
const pathname = usePathname();
const { strapi, isLoading: isCmsLoading } = useStrapi({ pathname });

console.log(strapi, isCmsLoading);
const resourcesArray = [
{
description: "The latest industry news, updates and info",
Expand Down
48 changes: 0 additions & 48 deletions apps/website/src/app/hooks/UseStrapi.ts

This file was deleted.

65 changes: 65 additions & 0 deletions apps/website/src/app/hooks/strapi/UseStrapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useEffect, useState } from "react";
import { getHomepageInfo, getTrustedBy } from "./requests";
import { HomePageCmsInfo, StrapiProps, StrapiResponse } from "./types";

function useStrapi({ pathname }: StrapiProps): StrapiResponse {
const [isLoading, setIsLoading] = useState<boolean>(true);
const [strapi, setStrapi] = useState<HomePageCmsInfo | Object>({});
const getData = () => {
switch (pathname) {
case "/":
Promise.allSettled([getHomepageInfo(), getTrustedBy()])
.then((results) => {
const homepageInfoResp =
results[0] as PromiseFulfilledResult<unknown>;
const trustedByResp =
results[1] as PromiseFulfilledResult<unknown>;
if (
homepageInfoResp.status === "fulfilled" &&
trustedByResp.status === "fulfilled"
) {
setStrapi((prevState: HomePageCmsInfo) => {
return {
...prevState,
mission_statement: homepageInfoResp.value,
trusted_bies: trustedByResp.value,
};
});
}
})
.catch(() => {
throw new Error("Failed to fetch strapi data");
})
.finally(() => {
setIsLoading(false);
});
break;
case "/team":
Promise.allSettled([getTrustedBy()])
.then((results) => {
const trustedByResp =
results[0] as PromiseFulfilledResult<unknown>;
if (trustedByResp.status === "fulfilled") {
setStrapi((prevState: HomePageCmsInfo) => {
return {
...prevState,
trusted_bies: trustedByResp.value,
};
});
}
})
.finally(() => {
setIsLoading(false);
});
break;
default:
setIsLoading(false);
}
};
useEffect(() => {
getData();
}, []);
return { strapi, isLoading };
}

export default useStrapi;
47 changes: 47 additions & 0 deletions apps/website/src/app/hooks/strapi/requests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { TrustedByInfo } from "./types";

const cms_base_url = process.env.NEXT_PUBLIC_STRAPI_URL;
//remove /api from base_url and to home_url variable
const cms_home_url = cms_base_url?.replace("/api", "");
export function getHomepageInfo() {
return new Promise((resolve, reject) => {
fetch(`${cms_base_url}/website-homepage`, {
headers: {
authorization: `bearer ${process.env.NEXT_PUBLIC_STRAPI_API}`,
},
})
.then((data) => {
data.json().then(({ data: info }) => {
resolve(info.mission_statement);
});
})
.catch((err) => {
reject(err);
});
});
}

export function getTrustedBy() {
return new Promise((resolve, reject) => {
fetch(
`${cms_base_url}/website-trusted-bies?populate[image][fields][0]=url`,
{
headers: {
authorization: `bearer ${process.env.NEXT_PUBLIC_STRAPI_API}`,
},
}
).then((data) => {
data.json()
.then(({ data: infos }) => {
const trustedBies = infos.map((infos: TrustedByInfo) => ({
alt: infos.alt,
src: cms_home_url + infos.image.url,
}));
resolve(trustedBies);
})
.catch((err) => {
reject(err);
});
});
});
}
30 changes: 30 additions & 0 deletions apps/website/src/app/hooks/strapi/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export interface StrapiContext {
strapi: HomePageCmsInfo | Object;
}

export interface HomePageCmsInfo {
mission_statement: string;
trusted_bies: {
src: string;
alt: string;
}[];
}
export interface TeamPageCmsInfo {
trusted_bies: {
src: string;
alt: string;
}[];
}
export interface TrustedByInfo {
alt: string;
image: {
url: string;
};
}
export interface StrapiResponse {
strapi: HomePageCmsInfo | Object;
isLoading: Boolean;
}
export interface StrapiProps {
pathname: string;
}
17 changes: 4 additions & 13 deletions apps/website/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import { animated } from "@react-spring/web";
import useFade from "./hooks/UseFade";
import useFadeInView from "./hooks/UseFadeInView";
import { PageContext } from "./clientLayout";
import { HomePageCmsInfo } from "./hooks/strapi/types";

export default function Home() {
const { strapi } = useContext(PageContext);
const { strapi } = useContext(PageContext) as { strapi: HomePageCmsInfo };
const socialLinks = [
{ href: "https://twitter.com/lilypad_tech", iconUrl: "/x.svg" },
{
Expand Down Expand Up @@ -200,16 +201,6 @@ export default function Home() {
}
}, []);

const trustedByArray = [
{ src: "/bacalhau.svg", alt: "Bacalhau" },
{ src: "/bacalhau.svg", alt: "Filecoin" },
{ src: "/bacalhau.svg", alt: "Holon" },
{ src: "/bacalhau.svg", alt: "Protocol Labs" },
{ src: "/bacalhau.svg", alt: "Rare Compute" },
{ src: "/bacalhau.svg", alt: "Spheron" },
{ src: "/bacalhau.svg", alt: "Swan" },
];

const copyEmail = "hello@lilypad.tech";

const [copyState, setCopyState] = useState({
Expand Down Expand Up @@ -370,7 +361,7 @@ export default function Home() {
<SectionContainer className="pb-uui-7xl lg:pb-uui-8xl">
<animated.div style={fade}>
<SocialProofSection
trustedByArray={trustedByArray}
trustedByArray={strapi?.trusted_bies}
title="Trusted by"
></SocialProofSection>
</animated.div>
Expand All @@ -394,7 +385,7 @@ export default function Home() {
that uses underutilized resources to make
efficient, sustainable technology accessible to
everyone. */}
{strapi.mission_statement}
{strapi?.mission_statement}
</animated.h2>
</div>
</SectionContainer>
Expand Down
8 changes: 7 additions & 1 deletion apps/website/src/app/team/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import useFadeInView from "../hooks/UseFadeInView";
import { animated } from "@react-spring/web";
import AnimateSpring from "@/components/AnimateSpring";
import useFade from "../hooks/UseFade";
import { useContext } from "react";
import { PageContext } from "../clientLayout";
import { TeamPageCmsInfo } from "../hooks/strapi/types";

export default function Teams() {
const { strapi } = useContext(PageContext) as {
strapi: TeamPageCmsInfo;
};
const socialLinks = [
{ href: "twitter.com", iconUrl: "/x.svg" },

Expand Down Expand Up @@ -229,7 +235,7 @@ export default function Teams() {
<div className="bg-uui-bg-secondary py-uui-4xl lg:py-uui-7xl">
<SectionContainer>
<SocialProofSection
trustedByArray={trustedByArray}
trustedByArray={strapi.trusted_bies}
title="Supported by"
></SocialProofSection>
</SectionContainer>
Expand Down

0 comments on commit 98fc4f6

Please sign in to comment.