Skip to content

Commit c4bb6b2

Browse files
committed
feat: add authentication messages and refactor channel list components; implement CallToActionMessage for subscription prompts
1 parent 2e9e16c commit c4bb6b2

File tree

11 files changed

+125
-46
lines changed

11 files changed

+125
-46
lines changed

i18n/originals/en.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060
"all_time": "All Time"
6161
}
6262
},
63+
"instructions": {
64+
"login_for_subscriptions": "Please login to view your subscriptions."
65+
},
66+
"authentication": {
67+
"login": "Login",
68+
"logout": "Logout",
69+
"sign_up": "Sign Up",
70+
"forgot_password": "Forgot Password?",
71+
"reset_password": "Reset Password",
72+
"email": "Email",
73+
"password": "Password",
74+
"confirm_password": "Confirm Password"
75+
},
6376
"settings": {
6477
"ui_theme": {
6578
"light": "☀️ Light",

src/app/podcasts/PodcastsContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export const PodcastsContextProvider = ({ children, initialQueryParams, ssrChann
5252
return;
5353
}
5454
}
55-
55+
56+
setShowSubscribeMessage(false);
5657
setIsLoading(true);
5758
const { currentSort, currentRange } = getCurrentSortAndRange({ type, sort, range });
5859
const channels = await apiRequestService.reqChannelGetMany({ page, type, sort: currentSort, range: currentRange, category });

src/app/podcasts/PodcastsList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
2-
import ChannelList from "../../components/Channel/ChannelList";
2+
import ChannelList from "../../components/Channel/ChannelsList";
33
import { usePodcastsContext } from "./PodcastsContext";
44
import LoadingSpinnerOverlay from "../../components/LoadingSpinner/LoadingSpinnerOverlay";
55

66
const PodcastsList: React.FC = () => {
7-
const { page = 1, setPage, channels, totalPages, isLoading } = usePodcastsContext();
7+
const { page = 1, setPage, channels, totalPages, isLoading, showSubscribeMessage } = usePodcastsContext();
88

99
return (
1010
<>
@@ -13,6 +13,7 @@ const PodcastsList: React.FC = () => {
1313
setPage={setPage}
1414
channels={channels}
1515
totalPages={totalPages}
16+
showSubscribeMessage={showSubscribeMessage}
1617
/>
1718
<LoadingSpinnerOverlay isLoading={isLoading} />
1819
</>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from "react";
2+
import styles from "../../styles/components/CallToActionMessage/CallToActionMessage.module.scss";
3+
4+
type CallToActionMessageProps = {
5+
message: React.ReactNode;
6+
buttonLabel: React.ReactNode;
7+
onButtonClick: () => void;
8+
};
9+
10+
const CallToActionMessage: React.FC<CallToActionMessageProps> = ({
11+
message,
12+
buttonLabel,
13+
onButtonClick
14+
}) => (
15+
<div className={styles.message}>
16+
<p>{message}</p>
17+
<button onClick={onButtonClick}>{buttonLabel}</button>
18+
</div>
19+
);
20+
21+
export default CallToActionMessage;

src/components/Channel/ChannelList.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use client";
2+
3+
import { useTranslations } from "next-intl";
4+
import { DTOChannel } from "podverse-helpers";
5+
import React, { useRef } from "react";
6+
import ChannelListItem from "./ChannelsListItem";
7+
import CallToActionMessage from "../CallToActionMessage/CallToActionMessage";
8+
import Pagination from "../Pagination/Pagination";
9+
import { useModals } from "../../contexts/Modals";
10+
import { useSkipInitialEffect } from "../../hooks/useSkipInitialEffect";
11+
12+
type Props = {
13+
page: number;
14+
setPage: (page: number) => void;
15+
channels: DTOChannel[];
16+
totalPages: number;
17+
showSubscribeMessage: boolean;
18+
};
19+
20+
const ChannelList: React.FC<Props> = ({ page = 1, setPage, channels, totalPages, showSubscribeMessage }) => {
21+
const topRef = useRef<HTMLDivElement>(null);
22+
const tInstructions = useTranslations("instructions");
23+
const tAuthentication = useTranslations("authentication");
24+
const { openModal } = useModals();
25+
26+
useSkipInitialEffect(() => {
27+
topRef?.current?.scrollIntoView();
28+
}, [channels]);
29+
30+
return (
31+
<>
32+
<div ref={topRef} />
33+
{showSubscribeMessage && (
34+
<CallToActionMessage
35+
message={tInstructions("login_for_subscriptions")}
36+
buttonLabel={tAuthentication("login")}
37+
onButtonClick={() => openModal("LoginModal")}
38+
/>
39+
)}
40+
{
41+
!showSubscribeMessage && (
42+
<Pagination
43+
currentPage={page}
44+
maxButtons={5}
45+
totalPages={totalPages}
46+
onPageChange={setPage}>
47+
{channels.map((channel) => (
48+
<ChannelListItem key={channel.id} channel={channel} />
49+
))}
50+
</Pagination>
51+
)
52+
}
53+
</>
54+
);
55+
};
56+
57+
export default ChannelList;

src/components/Channel/ChannelListItem.tsx renamed to src/components/Channel/ChannelsListItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use client";
22

3+
import { useTranslations } from "next-intl";
34
import Link from "next/link";
5+
import { DTOChannel, formatDateAbbrev } from "podverse-helpers";
46
import React from "react";
57
import Image from "../Image/Image";
6-
import styles from "../../styles/components/Channel/ChannelListItem.module.scss";
78
import { ROUTES } from "../../constants/routes";
8-
import { DTOChannel, formatDateAbbrev } from "podverse-helpers";
9-
import { useTranslations } from "next-intl";
9+
import styles from "../../styles/components/Channel/ChannelsListItem.module.scss";
1010

1111
interface Props {
1212
channel: DTOChannel;

src/components/Pagination/Pagination.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const Pagination: React.FC<PaginationProps> = ({
4545
children,
4646
maxButtons = 5,
4747
}) => {
48+
if (React.Children.count(children) === 0) {
49+
return null;
50+
}
51+
4852
const pageNumbers = getPageRange(currentPage, totalPages, maxButtons);
4953

5054
const handlePageChange = (page: number) => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.message {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
justify-content: center;
6+
flex: 1;
7+
gap: 1rem;
8+
font-size: var(--font-size-lg);
9+
}
10+
11+
.message button {
12+
color: var(--text-color-link);
13+
}

0 commit comments

Comments
 (0)