Skip to content

Commit

Permalink
Merge pull request #2173 from zeitgeistpm/tr-cms-news
Browse files Browse the repository at this point in the history
Sanity CMS migration
  • Loading branch information
yornaath authored Jan 17, 2024
2 parents 7d90852 + cd6216b commit 3256d03
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 268 deletions.
16 changes: 9 additions & 7 deletions components/front-page/News.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { News } from "lib/cms/get-news";
import { CmsNews } from "lib/cms/news";
import { isCurrentOrigin } from "lib/util/is-current-origin";
import Image from "next/image";
import Link from "next/link";
Expand All @@ -7,21 +7,23 @@ export const NewsSection = ({
news,
imagePlaceholders,
}: {
news: News[];
news: CmsNews[];
imagePlaceholders: string[];
}) => {
return (
<div className="mb-12">
<h2 className="mb-6 text-center sm:col-span-2 sm:text-start">News</h2>
<div className="flex flex-col gap-8 md:flex-row md:gap-4">
{news.map((news, index) => {
const isExternalLink = news.ctaLink
? !isCurrentOrigin(news.ctaLink)
: false;
const link = news.link?.isMarket
? `/markets/${news.link?.market?.marketId}`
: news.link?.url;

const isExternalLink = link ? !isCurrentOrigin(link) : false;

return (
<Link
href={news.ctaLink!}
href={link!}
key={index}
className="ztg-transition flex-1 md:hover:scale-[1.035]"
target={isExternalLink ? "_blank" : "_parent"}
Expand All @@ -30,7 +32,7 @@ export const NewsSection = ({
<Image
key={index}
priority
src={news.imageUrl ?? ""}
src={news.image ?? ""}
alt={`Image depicting ${news.title}`}
placeholder="blur"
fill
Expand Down
4 changes: 2 additions & 2 deletions components/hero-slider/HeroControls.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { News } from "lib/cms/get-news";
import { CmsNews } from "lib/cms/news";
import { UseSliderControls } from "lib/hooks/slides";
import { FC } from "react";
import { ChevronLeft, ChevronRight } from "react-feather";

export interface HeroControlsProps {
slides: News[];
slides: CmsNews[];
slider: UseSliderControls;
}

Expand Down
117 changes: 62 additions & 55 deletions components/hero-slider/HeroSlide.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
import { CSSProperties, FC, useMemo } from "react";
import Link from "next/link";
import { News } from "lib/cms/get-news";
import { CmsNews } from "lib/cms/news";
import { isCurrentOrigin } from "lib/util/is-current-origin";

export interface HeroSlideProps {
className?: string;
style?: CSSProperties;
banner: News;
banner: CmsNews;
}

export const HeroSlide: FC<HeroSlideProps> = ({ banner, style, className }) => {
const isExternalLink = banner.ctaLink
? !isCurrentOrigin(banner.ctaLink)
: false;
const linkProps = {
style: {
backgroundColor: `${banner.buttonColor}`,
borderColor: `${banner.buttonColor}`,
color: banner.buttonTextColor,
},
className:
"leading-[42px] w-full sm:w-fit text-center sm:text-start border rounded px-5 mb-5 mr-5 font-bold",
href: banner.ctaLink,
};
return <></>;
// const link = banner.link?.isMarket
// ? `/markets/${news.link?.market?.marketId}`
// : news.link?.url;

return (
<div
className={`flex h-full w-full items-center ${className}`}
style={style}
>
<div className="w-full pb-8">
<h2
className={`mb-4 text-center font-sans text-5xl font-extrabold text-white sm:text-left sm:text-7xl md:whitespace-pre lg:text-8xl`}
>
{banner.title}
</h2>
<p
className={
"mb-6 whitespace-pre text-center font-sans text-3xl font-extrabold text-white sm:text-start md:text-4xl"
}
>
{banner.subtitle}
</p>
<div className="flex flex-col sm:flex-row">
{isExternalLink ? (
<a {...linkProps} target="_blank">
{banner.ctaText}
</a>
) : (
<>
{linkProps.href && (
<Link
href={linkProps.href}
className={linkProps.className}
style={linkProps.style}
>
{banner.ctaText}
</Link>
)}
</>
)}
</div>
</div>
</div>
);
// const isExternalLink = link ? !isCurrentOrigin(link) : false;

// const isExternalLink = banner.ctaLink
// ? !isCurrentOrigin(banner.ctaLink)
// : false;
// const linkProps = {
// style: {
// backgroundColor: `${banner.buttonColor}`,
// borderColor: `${banner.buttonColor}`,
// color: banner.buttonTextColor,
// },
// className:
// "leading-[42px] w-full sm:w-fit text-center sm:text-start border rounded px-5 mb-5 mr-5 font-bold",
// href: banner.ctaLink,
// };

// return (
// <div
// className={`flex h-full w-full items-center ${className}`}
// style={style}
// >
// <div className="w-full pb-8">
// <h2
// className={`mb-4 text-center font-sans text-5xl font-extrabold text-white sm:text-left sm:text-7xl md:whitespace-pre lg:text-8xl`}
// >
// {banner.title}
// </h2>
// <p
// className={
// "mb-6 whitespace-pre text-center font-sans text-3xl font-extrabold text-white sm:text-start md:text-4xl"
// }
// >
// {banner.subtitle}
// </p>
// <div className="flex flex-col sm:flex-row">
// {isExternalLink ? (
// <a {...linkProps} target="_blank">
// {banner.ctaText}
// </a>
// ) : (
// <>
// {linkProps.href && (
// <Link
// href={linkProps.href}
// className={linkProps.className}
// style={linkProps.style}
// >
// {banner.ctaText}
// </Link>
// )}
// </>
// )}
// </div>
// </div>
// </div>
// );
};
107 changes: 54 additions & 53 deletions components/hero-slider/HeroSlider.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
import Image from "next/image";
import { HeroControls } from "./HeroControls";
import { HeroSlide } from "./HeroSlide";
import { News } from "lib/cms/get-news";
import { CmsNews } from "lib/cms/news";
import { useSliderControls } from "lib/hooks/slides";
import { Transition } from "@headlessui/react";

const HeroSlider = ({
banners,
bannerPlaceHolders,
}: {
banners: News[];
banners: CmsNews[];
bannerPlaceHolders: string[];
}) => {
const slider = useSliderControls({
count: banners.length,
autoplay: 15 * 1000,
pauseOnUserInteraction: 45 * 1000,
});
return <></>;
// const slider = useSliderControls({
// count: banners.length,
// autoplay: 15 * 1000,
// pauseOnUserInteraction: 45 * 1000,
// });

return (
<section
className={`relative mx-auto h-[527px] w-full`}
data-testid="HeroSlider__container"
>
{banners.map((banner, index) => (
<Image
key={index}
priority
src={banner.imageUrl ?? ""}
alt={`Image depicting ${banner.title}`}
placeholder="blur"
blurDataURL={bannerPlaceHolders[index]}
sizes="100vw"
fill
className="object-cover"
style={{
objectFit: "cover",
transitionDuration: index == slider.currentSlide ? "0.5s" : "1s",
opacity: index == slider.currentSlide ? "1" : "0.001",
objectPosition: `${banner.imageAlignment} 50%`,
}}
/>
))}
<div className="container-fluid relative h-full">
{banners.map((banner, index) => (
<Transition
className="container-fluid absolute left-0 h-full w-full"
show={index == slider.currentSlide}
enter="transition-all duration-1000"
enterFrom="opacity-0 blur-md"
enterTo="opacity-100 blur-none"
leave="transition-all duration-1000"
leaveFrom="opacity-100 blur-none"
leaveTo="opacity-0 blur-md"
key={index}
>
<HeroSlide banner={banner} />
</Transition>
))}
{banners.length > 1 && (
<HeroControls slides={banners} slider={slider} />
)}
</div>
</section>
);
// return (
// <section
// className={`relative mx-auto h-[527px] w-full`}
// data-testid="HeroSlider__container"
// >
// {banners.map((banner, index) => (
// <Image
// key={index}
// priority
// src={banner.imageUrl ?? ""}
// alt={`Image depicting ${banner.title}`}
// placeholder="blur"
// blurDataURL={bannerPlaceHolders[index]}
// sizes="100vw"
// fill
// className="object-cover"
// style={{
// objectFit: "cover",
// transitionDuration: index == slider.currentSlide ? "0.5s" : "1s",
// opacity: index == slider.currentSlide ? "1" : "0.001",
// objectPosition: `${banner.imageAlignment} 50%`,
// }}
// />
// ))}
// <div className="container-fluid relative h-full">
// {banners.map((banner, index) => (
// <Transition
// className="container-fluid absolute left-0 h-full w-full"
// show={index == slider.currentSlide}
// enter="transition-all duration-1000"
// enterFrom="opacity-0 blur-md"
// enterTo="opacity-100 blur-none"
// leave="transition-all duration-1000"
// leaveFrom="opacity-100 blur-none"
// leaveTo="opacity-0 blur-md"
// key={index}
// >
// <HeroSlide banner={banner} />
// </Transition>
// ))}
// {banners.length > 1 && (
// <HeroControls slides={banners} slider={slider} />
// )}
// </div>
// </section>
// );
};
export default HeroSlider;
19 changes: 19 additions & 0 deletions lib/cms/featured-markets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import groq from "groq";
import { sanity } from "./sanity";

export type CmsFeaturedMarkets = {
marketIds: number[];
};

const fields = groq`{
"marketIds": markets[].marketId,
}`;

export const getCmsFeaturedMarkets = async () => {
// Short circuit to use default if NOTION_API_KEY doesn't exist.
const data = await sanity.fetch<CmsFeaturedMarkets[]>(
groq`*[_type == "featuredMarkets"]${fields}`,
);

return data?.[0];
};
39 changes: 0 additions & 39 deletions lib/cms/get-featured-marketids.ts

This file was deleted.

Loading

0 comments on commit 3256d03

Please sign in to comment.