Skip to content

Commit 8d21119

Browse files
committed
Get feature on pages
1 parent cdd1ba1 commit 8d21119

File tree

7 files changed

+49
-21
lines changed

7 files changed

+49
-21
lines changed

next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ module.exports = (phase, { defaultConfig }) => {
5757
// Modify the file loader rule to ignore *.svg, since we have it handled now.
5858
fileLoaderRule.exclude = /\.svg$/i
5959

60+
config.module.rules.push({
61+
test: /\.(mp3)$/,
62+
type: "asset/resource",
63+
generator: {
64+
filename: "static/media/[name][ext]",
65+
},
66+
})
67+
6068
return config
6169
},
6270
i18n,

src/components/ListenToPlayer/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const ListenToPlayer = ({ slug }) => {
2323
const duration = sound?.duration() ?? 0
2424

2525
useEffect(() => {
26+
// Guard clause to prevent accessing playlist when empty
27+
if (!playlist.length || currentTrackIndex === -1) return
28+
2629
const audioPlayer = new Howl({
2730
src: [playlist[currentTrackIndex].audioFile],
2831
html5: true,
@@ -139,12 +142,7 @@ const ListenToPlayer = ({ slug }) => {
139142
setPlaybackSpeed(speed)
140143
}
141144

142-
const title =
143-
countdown > 0
144-
? `Next article in ${countdown}s`
145-
: t(playlist[currentTrackIndex].title)
146-
147-
return (
145+
return playlist.length > 0 && index !== -1 ? (
148146
<>
149147
<TopOfPagePlayer
150148
duration={duration}
@@ -157,7 +155,11 @@ const ListenToPlayer = ({ slug }) => {
157155
autoplay={autoplay}
158156
setAutoplay={setAutoplay}
159157
showWidget={showWidget}
160-
title={title}
158+
title={
159+
countdown > 0
160+
? `Next article in ${countdown}s`
161+
: t(playlist[currentTrackIndex].title)
162+
}
161163
duration={duration}
162164
timeRemaining={timeRemaining}
163165
onSeek={handleSeek}
@@ -170,6 +172,8 @@ const ListenToPlayer = ({ slug }) => {
170172
handleCloseWidget={handleCloseWidget}
171173
/>
172174
</>
175+
) : (
176+
<></>
173177
)
174178
}
175179

src/data/listen-to-feature/playlist.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ import whatIsEthereumAudio from "@/audio/what-is-ethereum/what-is-ethereum.mp3"
77
export const listenToPlaylists = {
88
learn: [
99
{
10-
title: "what-is-ether",
11-
audioFile: ethAudio,
12-
slug: "/eth",
10+
title: "what-is-ethereum",
11+
audioFile: whatIsEthereumAudio,
12+
slug: "/what-is-ethereum/",
1313
},
1414
{
15-
title: "smart-contracts",
16-
audioFile: smartContractsAudio,
17-
slug: "/smart-contracts",
15+
title: "what-is-ether",
16+
audioFile: ethAudio,
17+
slug: "/eth/",
1818
},
1919
{
2020
title: "wallets",
2121
audioFile: walletsAudio,
22-
slug: "/wallets",
22+
slug: "/wallets/",
2323
},
2424
{
2525
title: "web3",
2626
audioFile: web3Audio,
27-
slug: "/web3",
27+
slug: "/web3/",
2828
},
2929
{
30-
title: "what-is-ethereum",
31-
audioFile: whatIsEthereumAudio,
32-
slug: "/what-is-ethereum",
30+
title: "smart-contracts",
31+
audioFile: smartContractsAudio,
32+
slug: "/smart-contracts/",
3333
},
3434
],
3535
}
@@ -46,5 +46,5 @@ export const getPlaylistBySlug = (
4646
return { playlist, index }
4747
}
4848
}
49-
throw new Error(`Playlist with slug "${slug}" not found`)
49+
return { playlist: [], index: -1 }
5050
}

src/layouts/Static.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import GlossaryDefinition from "@/components/Glossary/GlossaryDefinition"
1313
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
1414
import { HubHero } from "@/components/Hero"
1515
import NetworkUpgradeSummary from "@/components/History/NetworkUpgradeSummary"
16+
import ListenToPlayer from "@/components/ListenToPlayer"
1617
import Logo from "@/components/Logo"
1718
import MainArticle from "@/components/MainArticle"
1819
import MatomoOptOut from "@/components/MatomoOptOut"
@@ -118,6 +119,7 @@ export const StaticLayout = ({
118119
{lastEditLocaleTimestamp}
119120
</p>
120121
)}
122+
<ListenToPlayer slug={asPath} />
121123
</Stack>
122124
)}
123125

src/pages/eth.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GetStaticProps } from "next"
2+
import { useRouter } from "next/router"
23
import { useTranslation } from "next-i18next"
34
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
45
import type { ComponentProps } from "react"
@@ -26,6 +27,7 @@ import HorizontalCard from "@/components/HorizontalCard"
2627
import { Image } from "@/components/Image"
2728
import InfoBanner from "@/components/InfoBanner"
2829
import InlineLink from "@/components/Link"
30+
import ListenToPlayer from "@/components/ListenToPlayer"
2931
import MainArticle from "@/components/MainArticle"
3032
import OldHeading from "@/components/OldHeading"
3133
import Text from "@/components/OldText"
@@ -266,6 +268,7 @@ export const getStaticProps = (async ({ locale }) => {
266268

267269
const EthPage = () => {
268270
const { t } = useTranslation("page-eth")
271+
const { asPath } = useRouter()
269272

270273
const tokens = [
271274
{
@@ -391,6 +394,9 @@ const EthPage = () => {
391394
</Content>
392395
<GrayContainer>
393396
<Content>
397+
<div className="mb-8">
398+
<ListenToPlayer slug={asPath} />
399+
</div>
394400
<Intro>
395401
<Text>{t("page-eth-description")} </Text>
396402
</Intro>

src/pages/wallets/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import HorizontalCard, {
2222
HorizontalCardProps,
2323
} from "@/components/HorizontalCard"
2424
import { Image } from "@/components/Image"
25+
import ListenToPlayer from "@/components/ListenToPlayer"
2526
import MainArticle from "@/components/MainArticle"
2627
import OldHeading from "@/components/OldHeading"
2728
import Text from "@/components/OldText"
@@ -148,7 +149,7 @@ export const getStaticProps = (async ({ locale }) => {
148149
}) satisfies GetStaticProps<BasePageProps>
149150

150151
const WalletsPage = () => {
151-
const { locale } = useRouter()
152+
const { locale, asPath } = useRouter()
152153
const { t } = useTranslation("page-wallets")
153154

154155
const heroContent = {
@@ -296,6 +297,9 @@ const WalletsPage = () => {
296297
/>
297298
<PageHero content={heroContent} isReverse />
298299
<GrayContainer>
300+
<Content mb={-8}>
301+
<ListenToPlayer slug={asPath} />
302+
</Content>
299303
<Intro>
300304
<H2>{t("page-wallets-whats-a-wallet")}</H2>
301305
</Intro>

src/pages/what-is-ethereum.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Card from "@/components/Card"
2626
import EnergyConsumptionChart from "@/components/EnergyConsumptionChart"
2727
import FeedbackCard from "@/components/FeedbackCard"
2828
import { TwImage } from "@/components/Image"
29+
import ListenToPlayer from "@/components/ListenToPlayer"
2930
import MainArticle from "@/components/MainArticle"
3031
import PageMetadata from "@/components/PageMetadata"
3132
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
@@ -206,7 +207,7 @@ const WhatIsEthereumPage = ({
206207
}: InferGetStaticPropsType<typeof getStaticProps>) => {
207208
const { t } = useTranslation(["page-what-is-ethereum", "learn-quizzes"])
208209

209-
const { locale } = useRouter()
210+
const { locale, asPath } = useRouter()
210211
const localeForNumberFormat = getLocaleForNumberFormat(locale! as Lang)
211212

212213
const formatNumber = (
@@ -343,6 +344,9 @@ const WhatIsEthereumPage = ({
343344
</Content>
344345
<div className="w-full bg-background-highlight">
345346
<Section>
347+
<div className="mb-8">
348+
<ListenToPlayer slug={asPath} />
349+
</div>
346350
<Stack className="gap-14">
347351
<TwoColumnContent id="summary">
348352
<Width60>

0 commit comments

Comments
 (0)