Skip to content

Commit

Permalink
Merge pull request #2241 from dfinity/akos/defi-page-2
Browse files Browse the repository at this point in the history
defi page update for cketh
  • Loading branch information
artkorotkikh-dfinity authored Dec 5, 2023
2 parents 1c2eb66 + b5fff6e commit a41f539
Show file tree
Hide file tree
Showing 30 changed files with 738 additions and 582 deletions.
4 changes: 2 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const lightCodeTheme = require("./codeblock-theme");
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
const simplePlantUML = require("@akebifiky/remark-simple-plantuml");
const homeShowcaseProjectsPlugin = require("./plugins/home-showcase");
const icpPricePlugin = require("./plugins/icp-price");
const cryptoPricePlugin = require("./plugins/crypto-price");
const xdrPricePlugin = require("./plugins/xdr-price");
const icpXdrPricePlugin = require("./plugins/icp-xdr-price");
const tailwindPlugin = require("./plugins/tailwind");
Expand Down Expand Up @@ -481,7 +481,7 @@ const config = {
"docusaurus-plugin-sass",
customWebpack,
tailwindPlugin,
icpPricePlugin,
cryptoPricePlugin,
icpXdrPricePlugin,
xdrPricePlugin,
homeShowcaseProjectsPlugin,
Expand Down
27 changes: 27 additions & 0 deletions plugins/crypto-price.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fetch = require("node-fetch-retry");

/** @type {import('@docusaurus/types').PluginModule} */
const icpPricePlugin = async function (context, options) {
return {
name: "crypto-price",
async loadContent() {
const tickers = await Promise.all([
fetch("https://api.coinbase.com/v2/prices/ICP-USD/buy", {
retry: 10,
pause: 500,
}).then((res) => res.json()),
fetch("https://api.coinbase.com/v2/prices/BTC-USD/buy", {
retry: 10,
pause: 500,
}).then((res) => res.json()),
]);
return { icp: +tickers[0].data.amount, btc: +tickers[1].data.amount };
},
async contentLoaded({ content, actions }) {
const { setGlobalData } = actions;
setGlobalData(content);
},
};
};

module.exports = icpPricePlugin;
21 changes: 0 additions & 21 deletions plugins/icp-price.js

This file was deleted.

122 changes: 122 additions & 0 deletions src/components/Common/RotatingStatsPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import clsx from "clsx";
import React, { useEffect, useState } from "react";
import { SpringCounter } from "../../LandingPage/PreHero/Counters";
import { Stat, StatsPanel } from "../Stats";

export type RotatingStat = {
title: string;
value: number | (() => number);
format: (value: number) => string;
fallbackValue?: string;
};

const FadeInOutTitle: React.FC<{
title: string;
}> = ({ title }) => {
const [currentTitle, setCurrentTitle] = useState(title);
const [nextTitle, setNextTitle] = useState(title);

useEffect(() => {
setNextTitle(title);
const handle = setTimeout(() => {
setCurrentTitle(title);
}, 300);
return () => clearTimeout(handle);
}, [title]);

return (
<span className="inline-grid text-center">
<span
className={clsx(
"col-start-1 row-start-1 duration-300",
currentTitle !== nextTitle
? "opacity-0 transition-opacity"
: "opacity-1 transition-none"
)}
>
{currentTitle}
</span>
{currentTitle !== nextTitle && (
<span className="col-start-1 row-start-1 stat-fade-in">
{nextTitle}
</span>
)}
</span>
);
};

const layoutClasses = {
2: "grid grid-cols-1 sm:grid-cols-2 md:justify-between gap-10",
3: "grid grid-cols-1 md:grid-cols-3 md:justify-between gap-10",
4: "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 md:justify-between gap-10",
};

const RotatingStatPanel: React.FC<{
stats: RotatingStat[][];
rotationIndexes: number[];
}> = ({ stats, rotationIndexes }) => {
const [activeIndexes, setActiveIndexes] = useState(
rotationIndexes.map(() => 0)
);
const [rotationIndex, setRotationIndex] = useState(0);
const [windowFocused, setWindowFocused] = useState(true);

useEffect(() => {
const interval = setInterval(() => {
if (!windowFocused) {
return;
}

const newActiveIndexes = [...activeIndexes];
const nextIndexToChange = rotationIndexes[rotationIndex];
newActiveIndexes[nextIndexToChange] =
(newActiveIndexes[nextIndexToChange] + 1) %
stats[nextIndexToChange].length;

setActiveIndexes(newActiveIndexes);
setRotationIndex((i) => (i + 1) % rotationIndexes.length);
}, 2000);

return () => clearInterval(interval);
}, [activeIndexes, rotationIndex, windowFocused]);

useEffect(() => {
const onVisibilityChange = () => setWindowFocused(!document.hidden);
document.addEventListener("visibilitychange", onVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", onVisibilityChange);
};
}, []);

const statsToDisplay = activeIndexes.map((index, i) => stats[i][index]);

const layoutClass = layoutClasses[statsToDisplay.length];

return (
<StatsPanel className={layoutClass}>
{statsToDisplay.map((stat, index) => {
const value =
typeof stat.value === "function" ? stat.value() : stat.value;
return (
<Stat
key={index}
title={<FadeInOutTitle title={stat.title} />}
titleClassName="whitespace-nowrap"
value={
<SpringCounter
initialValue={value}
initialTarget={value}
target={value}
format={stat.format}
springConfig={[3, 1, 8]}
/>
}
fallbackValue={stat.fallbackValue}
/>
);
})}
</StatsPanel>
);
};

export default RotatingStatPanel;
12 changes: 10 additions & 2 deletions src/components/Common/Stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ const Fallback: React.FC<{ children: React.ReactNode }> = ({ children }) => {
);
};

export const StatsPanel: React.FC<{ children: ReactNode }> = ({ children }) => {
export const StatsPanel: React.FC<{
children: ReactNode;
className?: string;
}> = ({ children, className }) => {
return (
<div className="mt-20 backdrop-blur-md bg-white/80 border border-white border-solid rounded-xl py-12 px-6 md:px-20 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 md:justify-between gap-10">
<div
className={clsx(
"mt-20 backdrop-blur-md bg-white/80 border border-white border-solid rounded-xl py-12 px-6 md:px-20 ",
className
)}
>
{children}
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Common/VideoCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from "@docusaurus/Link";
import PlaySVG from "@site/static/img/svgIcons/play.svg";
import clsx from "clsx";
import React from "react";
import React, { ReactNode } from "react";

export const PlayButton: React.FC<{}> = ({}) => {
return (
Expand Down Expand Up @@ -33,7 +33,7 @@ export const ImageOnlyVideoCard: React.FC<{
const VideoCard: React.FC<{
title: string;
label: string;
description?: string;
description?: ReactNode;
image: string;
link: string;
withPlayButton?: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/components/LandingPage/BackgroundPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ const BackgroundPanel: React.FC<{
{inView && <DarkHeroStyles bgColor="transparent" />}
<div
className={clsx(
"fixed z-[10] inset-0 pointer-events-none transition-opacity duration-500",
"fixed z-[10] inset-0 transition-opacity duration-500",
className,
inView ? "opacity-100" : "opacity-0"
inView ? "opacity-100" : "opacity-0 pointer-events-none"
)}
></div>
<div ref={ref} className="relative z-[13] " id={id}>
<div ref={ref} className="relative z-[13] pointer-events-none" id={id}>
<BackgroundPanelContext.Provider value={inView}>
<div
style={{ opacity: inView ? 1 : 0 }}
className="transition-opacity"
className="transition-opacity pointer-events-auto"
>
{children}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/LandingPage/PreHero/Counters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const SpringCounter: React.FC<{
function paint() {
if (spring.current) {
spring.current.update(60);
const nextValue = format(Math.round(spring.current.x));
const nextValue = format(spring.current.x);
if (lastValue !== nextValue) {
ref.current.innerText = format(Math.round(spring.current.x));
ref.current.innerText = format(spring.current.x);
lastValue = nextValue;
}
}
Expand All @@ -39,7 +39,7 @@ export const SpringCounter: React.FC<{
return () => {
lastHandle >= 0 && cancelAnimationFrame(lastHandle);
};
}, []);
}, [format, target, initialValue, initialTarget]);

useEffect(() => {
if (!spring.current) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NodeProvidersPage/Stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Stats: React.FC = () => {
);

return (
<StatsPanel>
<StatsPanel className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 md:justify-between gap-10">
<Stat
title="Node providers"
value={
Expand Down
4 changes: 2 additions & 2 deletions src/pages/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ const RotatingStatPanel: React.FC<{}> = () => {
const statsToDisplay = activeIndexes.map((index, i) => stats[i][index]);

return (
<StatsPanel>
<StatsPanel className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 md:justify-between gap-10">
{statsToDisplay.map((stat, index) => (
<Stat
key={index}
key={stat.title}
title={<FadeInOutTitle title={stat.title} />}
titleClassName="whitespace-nowrap"
value={
Expand Down
Loading

0 comments on commit a41f539

Please sign in to comment.