Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loading and success indicators for backend checks #9593

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ msgstr ""
msgid "Library Explorer"
msgstr ""

#: books/custom_carousel.html login.html search/work_search_facets.html
#: account/create.html books/custom_carousel.html login.html
#: search/work_search_facets.html
msgid "Loading..."
msgstr ""

Expand Down Expand Up @@ -1033,6 +1034,18 @@ msgid ""
"nonprofit Internet Archive"
msgstr ""

#: account/create.html
msgid "Loading spinner"
msgstr ""

#: account/create.html type/author/view.html
msgid "Success!"
msgstr ""

#: account/create.html
msgid "Checkmark"
msgstr ""

#: account/create.html
msgid "Your URL"
msgstr ""
Expand Down Expand Up @@ -6479,10 +6492,6 @@ msgstr ""
msgid "Refresh the page?"
msgstr ""

#: type/author/view.html
msgid "Success!"
msgstr ""

#: type/author/view.html
msgid ""
"OK. The merge is in motion. <i>It will take <u>a few minutes to "
Expand Down
22 changes: 20 additions & 2 deletions openlibrary/plugins/openlibrary/js/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { debounce } from './nonjquery_utils.js';
export function initSignupForm() {
const signupForm = document.querySelector('form[name=signup]');
const i18nStrings = JSON.parse(signupForm.dataset.i18n);
const emailLoadingIcon = $('.ol-signup-form__input--emailAddr .ol-signup-form__icon--loading');
const usernameLoadingIcon = $('.ol-signup-form__input--username .ol-signup-form__icon--loading');
const emailSuccessIcon = $('.ol-signup-form__input--emailAddr .ol-signup-form__icon--success');
const usernameSuccessIcon = $('.ol-signup-form__input--username .ol-signup-form__icon--success');

// Keep the same with openlibrary/plugins/upstream/forms.py
const VALID_EMAIL_RE = /^.*@.*\..*$/;
Expand Down Expand Up @@ -60,6 +64,8 @@ export function initSignupForm() {
function validateUsername() {
const value_username = $('#username').val();

usernameSuccessIcon.hide();

if (value_username === '') {
clearError('#username', '#usernameMessage');
return;
Expand All @@ -75,15 +81,20 @@ export function initSignupForm() {
return;
}

clearError('#username', '#usernameMessage');
usernameLoadingIcon.show();

$.ajax({
url: '/account/validate',
data: { username: value_username },
type: 'GET',
success: function(errors) {
usernameLoadingIcon.hide();

if (errors.username) {
renderError('#username', '#usernameMessage', errors.username);
} else {
clearError('#username', '#usernameMessage');
usernameSuccessIcon.show();
}
}
});
Expand All @@ -92,6 +103,8 @@ export function initSignupForm() {
function validateEmail() {
const value_email = $('#emailAddr').val();

emailSuccessIcon.hide();

if (value_email === '') {
clearError('#emailAddr', '#emailAddrMessage');
return;
Expand All @@ -102,15 +115,20 @@ export function initSignupForm() {
return;
}

clearError('#emailAddr', '#emailAddrMessage');
emailLoadingIcon.show();

$.ajax({
url: '/account/validate',
data: { email: value_email },
type: 'GET',
success: function(errors) {
emailLoadingIcon.hide();

if (errors.email) {
renderError('#emailAddr', '#emailAddrMessage', errors.email);
} else {
clearError('#emailAddr', '#emailAddrMessage');
emailSuccessIcon.show();
}
}
});
Expand Down
9 changes: 7 additions & 2 deletions openlibrary/templates/account/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1 class="ol-signup-hero__title">$_("Sign Up")</h1>
$# :param openlibrary.utils.form.Input input:
$# :param str suffix: HTML to put at bottom of input

<div class="formElement ol-signup-form__input">
<div class="formElement ol-signup-form__input ol-signup-form__input--$(input.id)">
<div class="label">
<label for="$input.id">$input.description</label>
$if input.help:
Expand All @@ -39,9 +39,14 @@ <h1 class="ol-signup-hero__title">$_("Sign Up")</h1>
<div class="input">
$:input.render()
$if input.name == 'password':
<a href="javascript:;" class="password-visibility-toggle">
<a href="javascript:;" class="password-visibility-toggle ol-signup-form__icon-wrap">
<img src="/static/images/icons/icon_eye-closed.svg" title="$_('Toggle Password Visibility')" alt="$_('Toggle Password Visibility')"/>
</a>
$else:
<div class="ol-signup-form__icon-wrap">
<img src="/static/images/bubble-loader.svg" class="ol-signup-form__icon ol-signup-form__icon--loading" title="$_('Loading...')" alt="$_('Loading spinner')" style="display:none"/>
<img src="/static/images/icons/icon_check-circle.svg" class="ol-signup-form__icon ol-signup-form__icon--success" title="$_('Success!')" alt="$_('Checkmark')" style="display:none" />
cdrini marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
<div class="ol-signup-form__suffix">$:suffix</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/css/page-signup.less
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@
position: relative;
}

.password-visibility-toggle {
.ol-signup-form__icon-wrap {
position: absolute;
right: 5px;
top: 5px;
}

.password-visibility-toggle > img {
.ol-signup-form__icon-wrap > img {
width: 22px;
height: 22px;
}
Expand Down
1 change: 1 addition & 0 deletions static/images/bubble-loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/images/icons/icon_check-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading