-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load user profile stats and packs section asynchronously
- Loading branch information
Showing
10 changed files
with
122 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
freesound/static/bw-frontend/src/components/asyncSection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {showToast} from "./toast"; | ||
import {initPlayersInModal} from './modal'; | ||
import {bindSimilarSoundModals} from './similarSoundsModal'; | ||
import {bindBookmarkSoundButtons} from './bookmarkSound'; | ||
import {bindRemixGroupModals} from './remixGroupModal'; | ||
|
||
const asyncSectionPlaceholders = document.getElementsByClassName('async-section'); | ||
|
||
const initPlayersAndPlayerModalsInElement = (element) => { | ||
initPlayersInModal(element); | ||
bindSimilarSoundModals(); | ||
bindBookmarkSoundButtons(); | ||
bindRemixGroupModals(); | ||
} | ||
|
||
asyncSectionPlaceholders.forEach(element => { | ||
const contentUrl = element.dataset.asyncSectionContentUrl; | ||
|
||
const req = new XMLHttpRequest(); | ||
req.open('GET', contentUrl); | ||
req.onload = () => { | ||
if (req.status >= 200 && req.status < 300) { | ||
element.innerHTML = req.responseText; | ||
|
||
// Make sure we initialize sound/pack players inside the async section | ||
initPlayersAndPlayerModalsInElement(element); | ||
} else { | ||
// Unexpected errors happened while processing request: show toast | ||
showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') | ||
} | ||
}; | ||
req.onerror = () => { | ||
// Unexpected errors happened while processing request: show toast | ||
showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') | ||
}; | ||
|
||
// Send the form | ||
req.send(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% load display_pack %} | ||
{% if latest_packs %} | ||
<div class="row"> | ||
{% for pack in latest_packs %} | ||
<div class="col-6 col-lg-4"> | ||
{% display_pack pack %} | ||
</div> | ||
{% endfor %} | ||
</div> | ||
<div class="v-spacing-top-4 text-center"> | ||
<a class="no-hover" href="{{ user.profile.get_user_packs_in_search_url }}"><button class="btn-primary">See all packs by {{ user.username }}</button></a> | ||
</div> | ||
{% else %} | ||
<div class="text-center"> | ||
<h5>No packs... 😟</h5> | ||
<div class="text-grey v-spacing-top-1">Looks like {{ user.username }} has not uploaded any packs yet</div> | ||
</div> | ||
{% endif %} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% load bw_templatetags %} | ||
{% load util %} | ||
<ol> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'wave' 'text-light-grey' %} <a class="text-19 bw-link--black" title="{{ user.username }} has uploaded {{ user_stats.num_sounds|bw_intcomma }} sound{{ user_stats.num_sounds|pluralize }}" href="{{ user.profile.get_user_sounds_in_search_url }}">{{ user_stats.num_sounds|formatnumber }} sound{{ user_stats.num_sounds|pluralize }}</a> | ||
</li> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'stack' 'text-light-grey' %} <a class="text-19 bw-link--black" title="{{ user.username }} has created {{ user_stats.num_packs|bw_intcomma }} pack{{ user_stats.num_packs|pluralize }}" href="{{ user.profile.get_user_packs_in_search_url }}">{{ user_stats.num_packs|formatnumber }} pack{{ user_stats.num_packs|pluralize }}</a> | ||
</li> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'clock' 'text-light-grey' %} <span class="text-19" title="{{ user.username }}'s sounds together account for {{ user_stats.total_uploaded_sounds_length|duration_hours }} hours of audio">{{ user_stats.total_uploaded_sounds_length|duration_hours }} hours of audio</span> | ||
</li> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'star' 'text-light-grey' %} <span class="text-19" title="{{ user.username }}'s sounds have an average rating of {{ user_stats.avg_rating_0_5|floatformat:1 }}">{{ user_stats.avg_rating_0_5|floatformat:1 }} average rating</span> | ||
</li> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'download' 'text-light-grey' %} <span class="text-19" title="{{ user.username }}'s sounds and packs have been downloaded {{ user_stats.num_downloads }} times">{{ user_stats.num_downloads|formatnumber }} download{{ user_stats.num_downloads|pluralize }}</span> | ||
</li> | ||
<li class="v-spacing-3"> | ||
{% bw_icon 'comments' 'text-light-grey' %} <span class="text-19" title="{{ user.username }} has written {{ user_stats.num_posts }} forum posts">{{ user_stats.num_posts|formatnumber }} forum post{{ user_stats.num_posts|pluralize }}</span> | ||
</li> | ||
</ol> |