Scrolling to errors and passing along sync status to YT sync works

This commit is contained in:
ポール ウェッブ 2019-04-19 13:28:05 -05:00
parent ca1856e203
commit 48eab05b62
3 changed files with 32 additions and 11 deletions

View file

@ -29,12 +29,13 @@ class AcquisitionActions extends Actions
public static function executeYoutubeToken()
{
$channelName = Request::encodeStringFromUser($_POST['desired_lbry_channel_name']);
$immediateSync = (boolean)$_POST['immediate_sync'];
if ($channelName && $channelName[0] !== "@") {
$channelName = '@' . $channelName;
}
$token = LBRY::connectYoutube($channelName);
$token = LBRY::connectYoutube($channelName, $immediateSync);
if ($token['success'] && $token['data']) {
Controller::redirect($token['data']);

View file

@ -50,22 +50,25 @@ class LBRY
return Curl::post(static::getApiUrl('/user/unsubscribe'), ['email' => $email], ['json_response' => true]);
}
public static function connectYoutube($channel_name)
{
$type = 'sync';
public static function connectYoutube($channel_name, $immediateSync = false) {
// Uncomment next line for production and comment other return
return Curl::post(static::getApiUrl('/yt/new'), ['desired_lbry_channel_name' => $channel_name, 'type' => $type], ['json_response' => true]);
// Uncomment next line for development and comment other return (this also requires the testnet API)
// return Curl::post(static::getApiUrl('/yt/new'), [
// 'desired_lbry_channel_name' => $channel_name,
// 'immediate_sync' => true,
// 'return_url' => 'http://localhost:8000/youtube/status/',
// 'type' => $type
// 'immediate_sync' => $immediateSync,
// 'type' => 'sync'
// ], [
// 'json_response' => true
// ]);
// Uncomment next line for development and comment other return (this also requires the testnet API)
return Curl::post(static::getApiUrl('/yt/new'), [
'desired_lbry_channel_name' => $channel_name,
'immediate_sync' => $immediateSync,
'return_url' => 'http://localhost:8000/youtube/status/',
'type' => 'sync'
], [
'json_response' => true
]);
}
// Check the sync status

View file

@ -250,6 +250,7 @@ new App();
// Clicking CTAs introduces a smooth scroll to the appropriate section
const youtubeCtas = document.querySelectorAll("[data-id='scroll-to-claim']");
youtubeCtas.forEach(cta => {
@ -264,3 +265,19 @@ youtubeCtas.forEach(cta => {
}, 300);
};
});
// Scroll to error messages if they exist
window.addEventListener("load", (event) => {
const youtubeErrors = document.querySelectorAll(".error-block");
youtubeErrors.forEach(error => {
if (!error.hidden) {
const errorDivOffset = error.offsetTop;
window.scroll({ top: errorDivOffset });
return;
}
});
});