Skip to content

Commit 347af28

Browse files
committed
Improves YouTube sync UI and error handling.
Enhances the YouTube sync page by improving error handling and UI logic. It now correctly displays error messages received after YouTube authentication. It also correctly displays the YouTube transfer status component, and ensures 'new_channel' param is correctly interpreted, fixing a logic error where the transfer status wouldn't show.
1 parent ca1aaa7 commit 347af28

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

ui/page/youtubeSync/view.jsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const YoutubeTransferStatus = lazyImport(() =>
2121
);
2222

2323
const STATUS_TOKEN_PARAM = 'status_token';
24+
const ERROR_PARAM = 'error';
2425
const ERROR_MESSAGE_PARAM = 'error_message';
2526
const NEW_CHANNEL_PARAM = 'new_channel';
2627

@@ -40,14 +41,21 @@ export default function YoutubeSync(props: Props) {
4041
} = useHistory();
4142
const urlParams = new URLSearchParams(search);
4243
const statusToken = urlParams.get(STATUS_TOKEN_PARAM);
44+
const hasErrorParam = urlParams.get(ERROR_PARAM) === 'true';
4345
const errorMessage = urlParams.get(ERROR_MESSAGE_PARAM);
4446
const newChannelParam = urlParams.get(NEW_CHANNEL_PARAM);
4547
const [channel, setChannel] = React.useState('');
4648
const [language, setLanguage] = React.useState(getDefaultLanguage());
4749
const [nameError, setNameError] = React.useState(undefined);
4850
const [acknowledgedTerms, setAcknowledgedTerms] = React.useState(false);
49-
const [addingNewChannel, setAddingNewChannel] = React.useState(newChannelParam);
51+
const [addingNewChannel, setAddingNewChannel] = React.useState(Boolean(newChannelParam));
52+
const hasYoutubeAuthError = hasErrorParam || Boolean(errorMessage);
53+
const youtubeAuthErrorMessage =
54+
hasYoutubeAuthError && !errorMessage
55+
? __('There was a problem connecting this YouTube channel. Please try again.')
56+
: errorMessage;
5057
const hasYoutubeChannels = youtubeChannels && youtubeChannels.length > 0;
58+
const showYoutubeTransferStatus = hasYoutubeChannels && !addingNewChannel && !hasYoutubeAuthError;
5159

5260
React.useEffect(() => {
5361
const urlParamsInEffect = new URLSearchParams(search);
@@ -66,9 +74,7 @@ export default function YoutubeSync(props: Props) {
6674
}, [statusToken, hasYoutubeChannels, doUserFetch]);
6775

6876
React.useEffect(() => {
69-
if (!newChannelParam) {
70-
setAddingNewChannel(false);
71-
}
77+
setAddingNewChannel(Boolean(newChannelParam));
7278
}, [newChannelParam]);
7379

7480
function handleCreateChannel() {
@@ -95,7 +101,7 @@ export default function YoutubeSync(props: Props) {
95101
}
96102

97103
function handleNewChannel() {
98-
urlParams.append('new_channel', 'true');
104+
urlParams.set('new_channel', 'true');
99105
push(`${pathname}?${urlParams.toString()}`);
100106
setAddingNewChannel(true);
101107
}
@@ -113,12 +119,13 @@ export default function YoutubeSync(props: Props) {
113119
return (
114120
<Wrapper>
115121
<div className="main__channel-creation">
116-
{hasYoutubeChannels && !addingNewChannel ? (
122+
{showYoutubeTransferStatus ? (
117123
<React.Suspense fallback={null}>
118124
<YoutubeTransferStatus alwaysShow addNewChannel={handleNewChannel} />
119125
</React.Suspense>
120126
) : (
121127
<Card
128+
className="card--youtube-sync"
122129
title={__('Sync your YouTube channel to %site_name%', { site_name: IS_WEB ? SITE_NAME : 'Odysee' })}
123130
subtitle={__(
124131
`Don't want to manually upload? Get your YouTube videos in front of the %site_name% audience.`,
@@ -197,11 +204,11 @@ export default function YoutubeSync(props: Props) {
197204
label={__('Claim Now')}
198205
/>
199206

200-
{inSignUpFlow && !errorMessage && (
207+
{inSignUpFlow && !hasYoutubeAuthError && (
201208
<Button button="link" label={__('Skip')} onClick={() => doToggleInterestedInYoutubeSync()} />
202209
)}
203210

204-
{errorMessage && <Button button="link" label={__('Skip')} navigate={`/$/${PAGES.REWARDS}`} />}
211+
{hasYoutubeAuthError && <Button button="link" label={__('Skip')} navigate={`/$/${PAGES.REWARDS}`} />}
205212
</div>
206213
<div className="help--card-actions">
207214
<I18nMessage
@@ -229,7 +236,7 @@ export default function YoutubeSync(props: Props) {
229236
</div>
230237
</Form>
231238
}
232-
nag={errorMessage && <Nag message={errorMessage} type="error" relative />}
239+
nag={youtubeAuthErrorMessage && <Nag message={youtubeAuthErrorMessage} type="error" relative />}
233240
/>
234241
)}
235242
</div>

ui/scss/component/_main.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,15 @@ body {
941941
.checkbox {
942942
margin-bottom: var(--spacing-m);
943943
}
944+
945+
.card--youtube-sync {
946+
.nag--error.nag--relative {
947+
left: 0;
948+
right: 0;
949+
bottom: auto;
950+
margin-top: var(--spacing-s);
951+
}
952+
}
944953
}
945954

946955
// Temp hacks until 'section__actions--no-margin' is generic again.

0 commit comments

Comments
 (0)