Skip to content

Commit

Permalink
Get feature on pages
Browse files Browse the repository at this point in the history
  • Loading branch information
corwintines committed Feb 12, 2025
1 parent cdd1ba1 commit 8d21119
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ module.exports = (phase, { defaultConfig }) => {
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i

config.module.rules.push({
test: /\.(mp3)$/,
type: "asset/resource",
generator: {
filename: "static/media/[name][ext]",
},
})

return config
},
i18n,
Expand Down
18 changes: 11 additions & 7 deletions src/components/ListenToPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const ListenToPlayer = ({ slug }) => {
const duration = sound?.duration() ?? 0

useEffect(() => {
// Guard clause to prevent accessing playlist when empty
if (!playlist.length || currentTrackIndex === -1) return

const audioPlayer = new Howl({
src: [playlist[currentTrackIndex].audioFile],
html5: true,
Expand Down Expand Up @@ -139,12 +142,7 @@ const ListenToPlayer = ({ slug }) => {
setPlaybackSpeed(speed)
}

const title =
countdown > 0
? `Next article in ${countdown}s`
: t(playlist[currentTrackIndex].title)

return (
return playlist.length > 0 && index !== -1 ? (
<>
<TopOfPagePlayer
duration={duration}
Expand All @@ -157,7 +155,11 @@ const ListenToPlayer = ({ slug }) => {
autoplay={autoplay}
setAutoplay={setAutoplay}
showWidget={showWidget}
title={title}
title={
countdown > 0
? `Next article in ${countdown}s`
: t(playlist[currentTrackIndex].title)
}
duration={duration}
timeRemaining={timeRemaining}
onSeek={handleSeek}
Expand All @@ -170,6 +172,8 @@ const ListenToPlayer = ({ slug }) => {
handleCloseWidget={handleCloseWidget}
/>
</>
) : (
<></>
)
}

Expand Down
24 changes: 12 additions & 12 deletions src/data/listen-to-feature/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import whatIsEthereumAudio from "@/audio/what-is-ethereum/what-is-ethereum.mp3"
export const listenToPlaylists = {
learn: [
{
title: "what-is-ether",
audioFile: ethAudio,
slug: "/eth",
title: "what-is-ethereum",
audioFile: whatIsEthereumAudio,
slug: "/what-is-ethereum/",
},
{
title: "smart-contracts",
audioFile: smartContractsAudio,
slug: "/smart-contracts",
title: "what-is-ether",
audioFile: ethAudio,
slug: "/eth/",
},
{
title: "wallets",
audioFile: walletsAudio,
slug: "/wallets",
slug: "/wallets/",
},
{
title: "web3",
audioFile: web3Audio,
slug: "/web3",
slug: "/web3/",
},
{
title: "what-is-ethereum",
audioFile: whatIsEthereumAudio,
slug: "/what-is-ethereum",
title: "smart-contracts",
audioFile: smartContractsAudio,
slug: "/smart-contracts/",
},
],
}
Expand All @@ -46,5 +46,5 @@ export const getPlaylistBySlug = (
return { playlist, index }
}
}
throw new Error(`Playlist with slug "${slug}" not found`)
return { playlist: [], index: -1 }
}
2 changes: 2 additions & 0 deletions src/layouts/Static.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GlossaryDefinition from "@/components/Glossary/GlossaryDefinition"
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
import { HubHero } from "@/components/Hero"
import NetworkUpgradeSummary from "@/components/History/NetworkUpgradeSummary"
import ListenToPlayer from "@/components/ListenToPlayer"
import Logo from "@/components/Logo"
import MainArticle from "@/components/MainArticle"
import MatomoOptOut from "@/components/MatomoOptOut"
Expand Down Expand Up @@ -118,6 +119,7 @@ export const StaticLayout = ({
{lastEditLocaleTimestamp}
</p>
)}
<ListenToPlayer slug={asPath} />
</Stack>
)}

Expand Down
6 changes: 6 additions & 0 deletions src/pages/eth.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetStaticProps } from "next"
import { useRouter } from "next/router"
import { useTranslation } from "next-i18next"
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
import type { ComponentProps } from "react"
Expand Down Expand Up @@ -26,6 +27,7 @@ import HorizontalCard from "@/components/HorizontalCard"
import { Image } from "@/components/Image"
import InfoBanner from "@/components/InfoBanner"
import InlineLink from "@/components/Link"
import ListenToPlayer from "@/components/ListenToPlayer"
import MainArticle from "@/components/MainArticle"
import OldHeading from "@/components/OldHeading"
import Text from "@/components/OldText"
Expand Down Expand Up @@ -266,6 +268,7 @@ export const getStaticProps = (async ({ locale }) => {

const EthPage = () => {
const { t } = useTranslation("page-eth")
const { asPath } = useRouter()

const tokens = [
{
Expand Down Expand Up @@ -391,6 +394,9 @@ const EthPage = () => {
</Content>
<GrayContainer>
<Content>
<div className="mb-8">
<ListenToPlayer slug={asPath} />
</div>
<Intro>
<Text>{t("page-eth-description")} </Text>
</Intro>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/wallets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import HorizontalCard, {
HorizontalCardProps,
} from "@/components/HorizontalCard"
import { Image } from "@/components/Image"
import ListenToPlayer from "@/components/ListenToPlayer"
import MainArticle from "@/components/MainArticle"
import OldHeading from "@/components/OldHeading"
import Text from "@/components/OldText"
Expand Down Expand Up @@ -148,7 +149,7 @@ export const getStaticProps = (async ({ locale }) => {
}) satisfies GetStaticProps<BasePageProps>

const WalletsPage = () => {
const { locale } = useRouter()
const { locale, asPath } = useRouter()
const { t } = useTranslation("page-wallets")

const heroContent = {
Expand Down Expand Up @@ -296,6 +297,9 @@ const WalletsPage = () => {
/>
<PageHero content={heroContent} isReverse />
<GrayContainer>
<Content mb={-8}>
<ListenToPlayer slug={asPath} />
</Content>
<Intro>
<H2>{t("page-wallets-whats-a-wallet")}</H2>
</Intro>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/what-is-ethereum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Card from "@/components/Card"
import EnergyConsumptionChart from "@/components/EnergyConsumptionChart"
import FeedbackCard from "@/components/FeedbackCard"
import { TwImage } from "@/components/Image"
import ListenToPlayer from "@/components/ListenToPlayer"
import MainArticle from "@/components/MainArticle"
import PageMetadata from "@/components/PageMetadata"
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
Expand Down Expand Up @@ -206,7 +207,7 @@ const WhatIsEthereumPage = ({
}: InferGetStaticPropsType<typeof getStaticProps>) => {
const { t } = useTranslation(["page-what-is-ethereum", "learn-quizzes"])

const { locale } = useRouter()
const { locale, asPath } = useRouter()
const localeForNumberFormat = getLocaleForNumberFormat(locale! as Lang)

const formatNumber = (
Expand Down Expand Up @@ -343,6 +344,9 @@ const WhatIsEthereumPage = ({
</Content>
<div className="w-full bg-background-highlight">
<Section>
<div className="mb-8">
<ListenToPlayer slug={asPath} />
</div>
<Stack className="gap-14">
<TwoColumnContent id="summary">
<Width60>
Expand Down

0 comments on commit 8d21119

Please sign in to comment.