From 3a6b0f9f112b8a11e812543fbfa3042757c44e70 Mon Sep 17 00:00:00 2001 From: Alfonsina Date: Wed, 5 Jun 2024 17:52:35 -0400 Subject: [PATCH 1/4] feat: enhance Footer component with dynamic links coming from sanity in dynamic pages --- sanity/schemas/basics/link.ts | 59 +++++++++++++++--------- src/api/types.ts | 4 +- src/app/[slug]/client-page.tsx | 6 +++ src/app/[slug]/getPageDetails.gql | 2 + src/components/Footer/Footer.tsx | 76 +++++++++++++++++++++++-------- src/components/Link.tsx | 2 + 6 files changed, 107 insertions(+), 42 deletions(-) diff --git a/sanity/schemas/basics/link.ts b/sanity/schemas/basics/link.ts index 58c2ad3..d7f82cc 100644 --- a/sanity/schemas/basics/link.ts +++ b/sanity/schemas/basics/link.ts @@ -1,35 +1,50 @@ -import { defineField, defineType } from 'sanity' +import { defineField, defineType } from "sanity"; const targets = [ - { title: 'Self', value: '_self' }, - { title: 'Blank', value: '_blank' }, - { title: 'Parent', value: '_parent' }, - { title: 'Top', value: '_top' }, -] + { title: "Self", value: "_self" }, + { title: "Blank", value: "_blank" }, + { title: "Parent", value: "_parent" }, + { title: "Top", value: "_top" }, +]; const icons = [ - { title: 'External', value: 'external' }, -] + { title: "External", value: "external" }, + { title: "Github", value: "github" }, + { title: "LinkedIn", value: "linkedin" }, + { title: "Instagram", value: "instagram" }, + { title: "Twitter", value: "twitter" }, + { title: "Facebook", value: "facebook" }, +]; const styles = [ - { title: 'Link', value: 'link' }, - { title: 'button', value: 'button' }, -] + { title: "Link", value: "link" }, + { title: "button", value: "button" }, +]; const link = defineType({ - name: 'link', - type: 'document', - title: 'Link', + name: "link", + type: "document", + title: "Link", initialValue: { - target: '_self' + target: "_self", }, fields: [ - defineField({ name: 'url', type: 'string', }), - defineField({ name: 'text', type: 'string', }), - defineField({ name: 'target', type: 'string', options: { list: targets } }), - defineField({ name: 'icon', title: 'Icon', type: 'string', options: { list: icons } }), - defineField({ name: 'style', title: 'Style', type: 'string', options: { list: styles } }), + defineField({ name: "text", type: "string" }), + defineField({ name: "url", type: "string" }), + defineField({ name: "target", type: "string", options: { list: targets } }), + defineField({ + name: "icon", + title: "Icon", + type: "string", + options: { list: icons }, + }), + defineField({ + name: "style", + title: "Style", + type: "string", + options: { list: styles }, + }), ], -}) +}); -export default link; \ No newline at end of file +export default link; diff --git a/src/api/types.ts b/src/api/types.ts index a4d92bb..f5cb134 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1530,7 +1530,7 @@ export type GetPageDetailsQueryVariables = Exact<{ }>; -export type GetPageDetailsQuery = { __typename?: 'RootQuery', allPage: Array<{ __typename?: 'Page', _id: string | null, name: string | null, seoTitle: string | null, seoKeywords: string | null, seoDescription: string | null, slug: { __typename?: 'Slug', current: string | null } | null, seoImage: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null, navbar: { __typename?: 'Navbar', links: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null } | null, footer: { __typename?: 'Footer', followLinks: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null, sectionLinks: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null } | null, sections: Array<{ __typename: 'Card' } | { __typename: 'CustomInfo', slug: string | null, name: string | null, description: { __typename?: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null } | { __typename: 'Hero', heading: string | null, tagline: string | null, icon: string | null, actions: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null, image: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, _key: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null, customAttributes: Array<{ __typename?: 'CustomAttributes', name: string | null, value: string | null } | null> | null } | { __typename: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | { __typename: 'Row', rowType: string | null, title: string | null, icon: string | null, description: { __typename?: 'RichText', name: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null, children: Array<{ __typename: 'Card', title: string | null, showType: string | null, icon: string | null, description: { __typename?: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null, image: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null } | { __typename: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | { __typename: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null> | null } | null> | null }> }; +export type GetPageDetailsQuery = { __typename?: 'RootQuery', allPage: Array<{ __typename?: 'Page', _id: string | null, name: string | null, seoTitle: string | null, seoKeywords: string | null, seoDescription: string | null, slug: { __typename?: 'Slug', current: string | null } | null, seoImage: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null, navbar: { __typename?: 'Navbar', links: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null } | null, footer: { __typename?: 'Footer', followLinks: Array<{ __typename?: 'Link', _key: string | null, url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null, sectionLinks: Array<{ __typename?: 'Link', _key: string | null, url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null } | null, sections: Array<{ __typename: 'Card' } | { __typename: 'CustomInfo', slug: string | null, name: string | null, description: { __typename?: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null } | { __typename: 'Hero', heading: string | null, tagline: string | null, icon: string | null, actions: Array<{ __typename?: 'Link', url: string | null, text: string | null, target: string | null, icon: string | null, style: string | null } | null> | null, image: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, _key: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null, customAttributes: Array<{ __typename?: 'CustomAttributes', name: string | null, value: string | null } | null> | null } | { __typename: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | { __typename: 'Row', rowType: string | null, title: string | null, icon: string | null, description: { __typename?: 'RichText', name: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null, children: Array<{ __typename: 'Card', title: string | null, showType: string | null, icon: string | null, description: { __typename?: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null, image: { __typename?: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | null } | { __typename: 'Image', asset: { __typename?: 'SanityImageAsset', _id: string | null, altText: string | null, path: string | null, label: string | null, title: string | null } | null } | { __typename: 'RichText', name: string | null, textType: string | null, htmlTextRaw: unknown | null, markdownText: string | null } | null> | null } | null> | null }> }; export const GetAllPagesDocument = gql` @@ -1575,6 +1575,7 @@ export const GetPageDetailsDocument = gql` } footer { followLinks { + _key url text target @@ -1582,6 +1583,7 @@ export const GetPageDetailsDocument = gql` style } sectionLinks { + _key url text target diff --git a/src/app/[slug]/client-page.tsx b/src/app/[slug]/client-page.tsx index f8e4db9..32b7b31 100644 --- a/src/app/[slug]/client-page.tsx +++ b/src/app/[slug]/client-page.tsx @@ -3,6 +3,7 @@ import { urlForImage } from "@/sanity/lib/image"; import type { Image } from "sanity"; import { Hero } from "@/sections/Hero/Hero"; +import { Footer } from "@/components/Footer/Footer"; import { getMetaData, getViewports } from "@/lib/metadata"; export const generateMetadata = () => getMetaData({}); @@ -10,6 +11,7 @@ export const generateMetadata = () => getMetaData({}); export const generateViewport = getViewports; export default function Page({ page }: { page: PageType }) { + const footerData = page.footer; return (
{page.sections?.map((section, idx) => { @@ -42,6 +44,10 @@ export default function Page({ page }: { page: PageType }) { ); } })} +
); } diff --git a/src/app/[slug]/getPageDetails.gql b/src/app/[slug]/getPageDetails.gql index c81aab8..44f7c0d 100644 --- a/src/app/[slug]/getPageDetails.gql +++ b/src/app/[slug]/getPageDetails.gql @@ -28,6 +28,7 @@ query getPageDetails($input: String!) { } footer { followLinks { + _key url text target @@ -35,6 +36,7 @@ query getPageDetails($input: String!) { style } sectionLinks { + _key url text target diff --git a/src/components/Footer/Footer.tsx b/src/components/Footer/Footer.tsx index 6f24457..0ba1115 100644 --- a/src/components/Footer/Footer.tsx +++ b/src/components/Footer/Footer.tsx @@ -1,15 +1,38 @@ -import { ExternalLink } from "lucide-react"; +import { Link as LinkType } from "@/api/types"; +import { Maybe } from "graphql/jsutils/Maybe"; +import { + ExternalLink, + Facebook, + Github, + Instagram, + Linkedin, + Twitter, +} from "lucide-react"; -import { HeaderLink } from "@/components/Header/HeaderLink"; import { Logo } from "@/components/Icons/Logo"; import { Title } from "@/components/Icons/Title"; import { Link } from "@/components/Link"; -import { footer, links } from "@/lib/data"; import { theme } from "@/lib/theme"; -export function Footer() { +interface FooterProps { + followLinks?: Maybe[]>; + sectionLinks?: Maybe[]>; +} + +const socialMediaIcons: { [key: string]: React.ReactNode } = { + linkedin: , + instagram: , + twitter: , + facebook: , + github: , +}; + +export function Footer({ followLinks, sectionLinks }: FooterProps) { + console.log("followlinks", followLinks); + console.log("sectionLinks", sectionLinks); return ( -