From 149b0b77311cdd36e93877c4a48f06b18fb573d9 Mon Sep 17 00:00:00 2001 From: scott lee Date: Thu, 2 Jan 2025 11:29:30 +0900 Subject: [PATCH 1/3] Optimize homepage components --- src/components/Homepage/HomepageAPIRef.tsx | 39 ++--- src/components/Homepage/HomepageFavorites.tsx | 137 ++++++++---------- src/components/Homepage/HomepageSDK.tsx | 39 +++-- 3 files changed, 99 insertions(+), 116 deletions(-) diff --git a/src/components/Homepage/HomepageAPIRef.tsx b/src/components/Homepage/HomepageAPIRef.tsx index 74efd4762160..edde779d2d31 100644 --- a/src/components/Homepage/HomepageAPIRef.tsx +++ b/src/components/Homepage/HomepageAPIRef.tsx @@ -6,7 +6,7 @@ import Translate from '@docusaurus/Translate'; import rpcApiDark from '../../images/rpc-api-dark.png'; import rpcApiLight from '../../images/rpc-api-light.png'; -const Container = styled.div` +const Container = React.memo(styled.div` display: flex; flex-direction: column; gap: 30px; @@ -19,21 +19,21 @@ const Container = styled.div` gap: 40px; align-items: flex-start; } -`; +`); -const ContentColumn = styled.div` +const ContentColumn = React.memo(styled.div` flex: 1; display: flex; flex-direction: column; align-items: flex-start; -`; +`); -const ImageColumn = styled.div` +const ImageColumn = React.memo(styled.div` flex: 1; display: flex; justify-content: center; align-items: center; -`; +`); const Title = styled.h2<{ themeMode: string }>` font-size: 1rem; @@ -56,7 +56,7 @@ const Description = styled.p<{ themeMode: string }>` color: ${({ themeMode }) => (themeMode === 'dark' ? '#e5e7eb' : '#4b5563')}; `; -const StyledLink = styled(Link)` +const StyledLink = React.memo(styled(Link)` display: inline-block; font-size: 1.125rem; font-weight: bold; @@ -65,13 +65,13 @@ const StyledLink = styled(Link)` &:hover { text-decoration: underline; } -`; +`); -const Image = styled.img` +const Image = React.memo(styled.img` max-width: 100%; height: auto; border-radius: 12px; -`; +`); const HomepageAPIRef: React.FC = () => { const { colorMode } = useColorMode(); @@ -80,21 +80,24 @@ const HomepageAPIRef: React.FC = () => { - <Translate>JSON-RPC API Reference</Translate> + <Translate id="homepage.api.title" description="Title for JSON-RPC API Reference section"> + JSON-RPC API Reference + </Translate> - Discover and Engage with Kaia's JSON-RPC APIs + + Discover and Engage with Kaia's JSON-RPC APIs + - - Unlock Kaia's full potential with our interactive API documentation. Test API calls directly in the docs, - explore detailed request and response examples, and generate code snippets in curl, Python, Node.js, and Java. - Whether developing new applications or integrating with existing systems, our comprehensive API reference - provides the tools for efficient development on the Kaia platform. + + Unlock Kaia's full potential with our interactive API documentation. Test API calls directly in the docs, explore detailed request and response examples, and generate code snippets in curl, Python, Node.js, and Java. Whether developing new applications or integrating with existing systems, our comprehensive API reference provides the tools for efficient development on the Kaia platform. - Get started with Kaia's JSON RPC APIs → + + Get started with Kaia's JSON RPC APIs + diff --git a/src/components/Homepage/HomepageFavorites.tsx b/src/components/Homepage/HomepageFavorites.tsx index 7793556263a2..1c35f0988402 100644 --- a/src/components/Homepage/HomepageFavorites.tsx +++ b/src/components/Homepage/HomepageFavorites.tsx @@ -4,78 +4,49 @@ import styled from 'styled-components'; import { useColorMode } from '@docusaurus/theme-common'; import Translate from '@docusaurus/Translate'; -const TRANSLATIONS = { +interface TranslationData { + titleId: string; + titleText: string; + descriptionId: string; + descriptionText: string; +} + +const TRANSLATIONS: Record = { gettingStarted: { - title: ( - - Getting Started - - ), - description: ( - - Deploy your first smart contract using Hardhat. - - ), + titleId: 'homepage.favorites.gettingStarted.title', + titleText: 'Getting Started', + descriptionId: 'homepage.favorites.gettingStarted.description', + descriptionText: 'Deploy your first smart contract using Hardhat.', }, metamask: { - title: ( - - MetaMask Guide - - ), - description: ( - - Connect MetaMask to Kaia. - - ), + titleId: 'homepage.favorites.metamask.title', + titleText: 'MetaMask Guide', + descriptionId: 'homepage.favorites.metamask.description', + descriptionText: 'Connect MetaMask to Kaia.', }, snapshot: { - title: ( - - Node Snapshot Guide - - ), - description: ( - - Use Chaindata Snapshots. - - ), + titleId: 'homepage.favorites.snapshot.title', + titleText: 'Node Snapshot Guide', + descriptionId: 'homepage.favorites.snapshot.description', + descriptionText: 'Use Chaindata Snapshots.', }, rpc: { - title: ( - - Public JSON RPC Endpoints - - ), - description: ( - - Build and test your products without running your own node. - - ), + titleId: 'homepage.favorites.rpc.title', + titleText: 'Public JSON RPC Endpoints', + descriptionId: 'homepage.favorites.rpc.description', + descriptionText: 'Build and test your products without running your own node.', }, wallets: { - title: ( - - Wallets - - ), - description: ( - - Integrate and secure digital assets seamlessly. - - ), + titleId: 'homepage.favorites.wallets.title', + titleText: 'Wallets', + descriptionId: 'homepage.favorites.wallets.description', + descriptionText: 'Integrate and secure digital assets seamlessly.', }, indexers: { - title: ( - - Indexers - - ), - description: ( - - Query and index blockchain data for efficient dApp performance. - - ), + titleId: 'homepage.favorites.indexers.title', + titleText: 'Indexers', + descriptionId: 'homepage.favorites.indexers.description', + descriptionText: 'Query and index blockchain data for efficient dApp performance.', }, }; @@ -98,7 +69,7 @@ const rightFavorites: Favorite[] = [ { type: 'indexers', link: '/build/tools/indexers' }, ]; -const Container = styled.div` +const Container = React.memo(styled.div` display: flex; flex-direction: column; gap: 30px; @@ -111,7 +82,7 @@ const Container = styled.div` gap: 40px; align-items: flex-start; } -`; +`); const Column = styled.div<{ themeMode: string }>` flex: 1; @@ -182,7 +153,7 @@ const FavoriteDescription = styled.p<{ themeMode: string }>` color: ${({ themeMode }) => (themeMode === 'dark' ? '#e5e7eb' : '#4b5563')}; `; -const ViewMoreLink = styled(Link)` +const ViewMoreLink = React.memo(styled(Link)` display: inline-block; margin-top: 8px; font-weight: bold; @@ -191,27 +162,45 @@ const ViewMoreLink = styled(Link)` &:hover { text-decoration: underline; } -`; +`); -const FavoriteContent = ({ favorite }: { favorite: Favorite }) => { +const FavoriteContent = React.memo(({ favorite }: { favorite: Favorite }) => { const { colorMode } = useColorMode(); - const translation = TRANSLATIONS[favorite.type]; + const translation = React.useMemo(() => TRANSLATIONS[favorite.type], [favorite.type]); return ( - {translation.title} + + {translation.titleText} + - {translation.description} + + {translation.descriptionText} + ); -}; +}); const HomepageFavorites: React.FC = () => { const { colorMode } = useColorMode(); + const renderedLeftFavorites = React.useMemo( + () => leftFavorites.map((favorite) => ( + + )), + [leftFavorites] + ); + + const renderedRightFavorites = React.useMemo( + () => rightFavorites.map((favorite) => ( + + )), + [rightFavorites] + ); + return ( @@ -220,9 +209,7 @@ const HomepageFavorites: React.FC = () => { Popular Guides - {leftFavorites.map((favorite) => ( - - ))} + {renderedLeftFavorites} View More Guides @@ -236,9 +223,7 @@ const HomepageFavorites: React.FC = () => { Popular Resources - {rightFavorites.map((favorite) => ( - - ))} + {renderedRightFavorites} View More Resources diff --git a/src/components/Homepage/HomepageSDK.tsx b/src/components/Homepage/HomepageSDK.tsx index 6f39c815b606..3293949274b3 100644 --- a/src/components/Homepage/HomepageSDK.tsx +++ b/src/components/Homepage/HomepageSDK.tsx @@ -4,34 +4,27 @@ import styled from 'styled-components'; import { useColorMode } from '@docusaurus/theme-common'; import Translate from '@docusaurus/Translate'; -const TRANSLATIONS = { +interface TranslationData { + nameId: string; + nameText: string; +} + +const TRANSLATIONS: Record = { ethersjs: { - name: ( - - Ethers.js Extension - - ), + nameId: 'homepage.sdk.ethersjs.name', + nameText: 'Ethers.js Extension', }, web3js: { - name: ( - - Web3.js Extension - - ), + nameId: 'homepage.sdk.web3js.name', + nameText: 'Web3.js Extension', }, web3j: { - name: ( - - Web3j Extension - - ), + nameId: 'homepage.sdk.web3j.name', + nameText: 'Web3j Extension', }, web3py: { - name: ( - - Web3.py Extension - - ), + nameId: 'homepage.sdk.web3py.name', + nameText: 'Web3.py Extension', }, }; @@ -151,7 +144,9 @@ const SDK = ({ sdk }: { sdk: SDKData }) => { - {translation.name} + + {translation.nameText} + ); From 5bd3a1eaa2bbaf4c1e09bc045ae0893287bbe9f7 Mon Sep 17 00:00:00 2001 From: scott lee Date: Thu, 2 Jan 2025 11:49:39 +0900 Subject: [PATCH 2/3] Remove unnecessary changes --- src/components/Homepage/HomepageAPIRef.tsx | 39 +++++++++---------- src/components/Homepage/HomepageFavorites.tsx | 12 +++--- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/components/Homepage/HomepageAPIRef.tsx b/src/components/Homepage/HomepageAPIRef.tsx index edde779d2d31..74efd4762160 100644 --- a/src/components/Homepage/HomepageAPIRef.tsx +++ b/src/components/Homepage/HomepageAPIRef.tsx @@ -6,7 +6,7 @@ import Translate from '@docusaurus/Translate'; import rpcApiDark from '../../images/rpc-api-dark.png'; import rpcApiLight from '../../images/rpc-api-light.png'; -const Container = React.memo(styled.div` +const Container = styled.div` display: flex; flex-direction: column; gap: 30px; @@ -19,21 +19,21 @@ const Container = React.memo(styled.div` gap: 40px; align-items: flex-start; } -`); +`; -const ContentColumn = React.memo(styled.div` +const ContentColumn = styled.div` flex: 1; display: flex; flex-direction: column; align-items: flex-start; -`); +`; -const ImageColumn = React.memo(styled.div` +const ImageColumn = styled.div` flex: 1; display: flex; justify-content: center; align-items: center; -`); +`; const Title = styled.h2<{ themeMode: string }>` font-size: 1rem; @@ -56,7 +56,7 @@ const Description = styled.p<{ themeMode: string }>` color: ${({ themeMode }) => (themeMode === 'dark' ? '#e5e7eb' : '#4b5563')}; `; -const StyledLink = React.memo(styled(Link)` +const StyledLink = styled(Link)` display: inline-block; font-size: 1.125rem; font-weight: bold; @@ -65,13 +65,13 @@ const StyledLink = React.memo(styled(Link)` &:hover { text-decoration: underline; } -`); +`; -const Image = React.memo(styled.img` +const Image = styled.img` max-width: 100%; height: auto; border-radius: 12px; -`); +`; const HomepageAPIRef: React.FC = () => { const { colorMode } = useColorMode(); @@ -80,24 +80,21 @@ const HomepageAPIRef: React.FC = () => { - <Translate id="homepage.api.title" description="Title for JSON-RPC API Reference section"> - JSON-RPC API Reference - </Translate> + <Translate>JSON-RPC API Reference</Translate> - - Discover and Engage with Kaia's JSON-RPC APIs - + Discover and Engage with Kaia's JSON-RPC APIs - - Unlock Kaia's full potential with our interactive API documentation. Test API calls directly in the docs, explore detailed request and response examples, and generate code snippets in curl, Python, Node.js, and Java. Whether developing new applications or integrating with existing systems, our comprehensive API reference provides the tools for efficient development on the Kaia platform. + + Unlock Kaia's full potential with our interactive API documentation. Test API calls directly in the docs, + explore detailed request and response examples, and generate code snippets in curl, Python, Node.js, and Java. + Whether developing new applications or integrating with existing systems, our comprehensive API reference + provides the tools for efficient development on the Kaia platform. - - Get started with Kaia's JSON RPC APIs - → + Get started with Kaia's JSON RPC APIs diff --git a/src/components/Homepage/HomepageFavorites.tsx b/src/components/Homepage/HomepageFavorites.tsx index 1c35f0988402..5e6d349d55c6 100644 --- a/src/components/Homepage/HomepageFavorites.tsx +++ b/src/components/Homepage/HomepageFavorites.tsx @@ -69,7 +69,7 @@ const rightFavorites: Favorite[] = [ { type: 'indexers', link: '/build/tools/indexers' }, ]; -const Container = React.memo(styled.div` +const Container = styled.div` display: flex; flex-direction: column; gap: 30px; @@ -82,7 +82,7 @@ const Container = React.memo(styled.div` gap: 40px; align-items: flex-start; } -`); +`; const Column = styled.div<{ themeMode: string }>` flex: 1; @@ -153,7 +153,7 @@ const FavoriteDescription = styled.p<{ themeMode: string }>` color: ${({ themeMode }) => (themeMode === 'dark' ? '#e5e7eb' : '#4b5563')}; `; -const ViewMoreLink = React.memo(styled(Link)` +const ViewMoreLink = styled(Link)` display: inline-block; margin-top: 8px; font-weight: bold; @@ -162,9 +162,9 @@ const ViewMoreLink = React.memo(styled(Link)` &:hover { text-decoration: underline; } -`); +`; -const FavoriteContent = React.memo(({ favorite }: { favorite: Favorite }) => { +const FavoriteContent = ({ favorite }: { favorite: Favorite }) => { const { colorMode } = useColorMode(); const translation = React.useMemo(() => TRANSLATIONS[favorite.type], [favorite.type]); @@ -182,7 +182,7 @@ const FavoriteContent = React.memo(({ favorite }: { favorite: Favorite }) => { ); -}); +}; const HomepageFavorites: React.FC = () => { const { colorMode } = useColorMode(); From e16ddb203deef6d3ddea6a9b5e561b582a5060fc Mon Sep 17 00:00:00 2001 From: scott lee Date: Thu, 2 Jan 2025 15:15:10 +0900 Subject: [PATCH 3/3] Remove dynamically constructed values inside Translation components --- src/components/Homepage/HomepageFavorites.tsx | 137 +++++++++--------- src/components/Homepage/HomepageSDK.tsx | 51 ++++--- 2 files changed, 92 insertions(+), 96 deletions(-) diff --git a/src/components/Homepage/HomepageFavorites.tsx b/src/components/Homepage/HomepageFavorites.tsx index 5e6d349d55c6..37e24f9ab24f 100644 --- a/src/components/Homepage/HomepageFavorites.tsx +++ b/src/components/Homepage/HomepageFavorites.tsx @@ -4,53 +4,7 @@ import styled from 'styled-components'; import { useColorMode } from '@docusaurus/theme-common'; import Translate from '@docusaurus/Translate'; -interface TranslationData { - titleId: string; - titleText: string; - descriptionId: string; - descriptionText: string; -} - -const TRANSLATIONS: Record = { - gettingStarted: { - titleId: 'homepage.favorites.gettingStarted.title', - titleText: 'Getting Started', - descriptionId: 'homepage.favorites.gettingStarted.description', - descriptionText: 'Deploy your first smart contract using Hardhat.', - }, - metamask: { - titleId: 'homepage.favorites.metamask.title', - titleText: 'MetaMask Guide', - descriptionId: 'homepage.favorites.metamask.description', - descriptionText: 'Connect MetaMask to Kaia.', - }, - snapshot: { - titleId: 'homepage.favorites.snapshot.title', - titleText: 'Node Snapshot Guide', - descriptionId: 'homepage.favorites.snapshot.description', - descriptionText: 'Use Chaindata Snapshots.', - }, - rpc: { - titleId: 'homepage.favorites.rpc.title', - titleText: 'Public JSON RPC Endpoints', - descriptionId: 'homepage.favorites.rpc.description', - descriptionText: 'Build and test your products without running your own node.', - }, - wallets: { - titleId: 'homepage.favorites.wallets.title', - titleText: 'Wallets', - descriptionId: 'homepage.favorites.wallets.description', - descriptionText: 'Integrate and secure digital assets seamlessly.', - }, - indexers: { - titleId: 'homepage.favorites.indexers.title', - titleText: 'Indexers', - descriptionId: 'homepage.favorites.indexers.description', - descriptionText: 'Query and index blockchain data for efficient dApp performance.', - }, -}; - -type FavoriteType = keyof typeof TRANSLATIONS; +type FavoriteType = 'gettingStarted' | 'metamask' | 'snapshot' | 'rpc' | 'wallets' | 'indexers'; interface Favorite { type: FavoriteType; @@ -166,19 +120,72 @@ const ViewMoreLink = styled(Link)` const FavoriteContent = ({ favorite }: { favorite: Favorite }) => { const { colorMode } = useColorMode(); - const translation = React.useMemo(() => TRANSLATIONS[favorite.type], [favorite.type]); return ( - - {translation.titleText} - + {favorite.type === 'gettingStarted' && ( + + Getting Started + + )} + {favorite.type === 'metamask' && ( + + MetaMask Guide + + )} + {favorite.type === 'snapshot' && ( + + Node Snapshot Guide + + )} + {favorite.type === 'rpc' && ( + + Public JSON RPC Endpoints + + )} + {favorite.type === 'wallets' && ( + + Wallets + + )} + {favorite.type === 'indexers' && ( + + Indexers + + )} - - {translation.descriptionText} - + {favorite.type === 'gettingStarted' && ( + + Deploy your first smart contract using Hardhat. + + )} + {favorite.type === 'metamask' && ( + + Connect MetaMask to Kaia. + + )} + {favorite.type === 'snapshot' && ( + + Use Chaindata Snapshots. + + )} + {favorite.type === 'rpc' && ( + + Build and test your products without running your own node. + + )} + {favorite.type === 'wallets' && ( + + Integrate and secure digital assets seamlessly. + + )} + {favorite.type === 'indexers' && ( + + Query and index blockchain data for efficient dApp performance. + + )} ); @@ -187,20 +194,6 @@ const FavoriteContent = ({ favorite }: { favorite: Favorite }) => { const HomepageFavorites: React.FC = () => { const { colorMode } = useColorMode(); - const renderedLeftFavorites = React.useMemo( - () => leftFavorites.map((favorite) => ( - - )), - [leftFavorites] - ); - - const renderedRightFavorites = React.useMemo( - () => rightFavorites.map((favorite) => ( - - )), - [rightFavorites] - ); - return ( @@ -209,7 +202,9 @@ const HomepageFavorites: React.FC = () => { Popular Guides - {renderedLeftFavorites} + {leftFavorites.map((favorite) => ( + + ))} View More Guides @@ -223,7 +218,9 @@ const HomepageFavorites: React.FC = () => { Popular Resources - {renderedRightFavorites} + {rightFavorites.map((favorite) => ( + + ))} View More Resources diff --git a/src/components/Homepage/HomepageSDK.tsx b/src/components/Homepage/HomepageSDK.tsx index 3293949274b3..a7aac57a0fac 100644 --- a/src/components/Homepage/HomepageSDK.tsx +++ b/src/components/Homepage/HomepageSDK.tsx @@ -4,28 +4,11 @@ import styled from 'styled-components'; import { useColorMode } from '@docusaurus/theme-common'; import Translate from '@docusaurus/Translate'; -interface TranslationData { - nameId: string; - nameText: string; -} - -const TRANSLATIONS: Record = { - ethersjs: { - nameId: 'homepage.sdk.ethersjs.name', - nameText: 'Ethers.js Extension', - }, - web3js: { - nameId: 'homepage.sdk.web3js.name', - nameText: 'Web3.js Extension', - }, - web3j: { - nameId: 'homepage.sdk.web3j.name', - nameText: 'Web3j Extension', - }, - web3py: { - nameId: 'homepage.sdk.web3py.name', - nameText: 'Web3.py Extension', - }, +const TRANSLATIONS = { + ethersjs: 'Ethers.js Extension', + web3js: 'Web3.js Extension', + web3j: 'Web3j Extension', + web3py: 'Web3.py Extension', }; type SDKType = keyof typeof TRANSLATIONS; @@ -138,15 +121,31 @@ const StyledLink = styled(Link)` const SDK = ({ sdk }: { sdk: SDKData }) => { const { colorMode } = useColorMode(); - const translation = TRANSLATIONS[sdk.type]; return ( - - {translation.nameText} - + {sdk.type === 'ethersjs' && ( + + Ethers.js Extension + + )} + {sdk.type === 'web3js' && ( + + Web3.js Extension + + )} + {sdk.type === 'web3j' && ( + + Web3j Extension + + )} + {sdk.type === 'web3py' && ( + + Web3.py Extension + + )} );