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

Loading indicator on large album list #19

Open
envas opened this issue Jul 31, 2024 · 2 comments
Open

Loading indicator on large album list #19

envas opened this issue Jul 31, 2024 · 2 comments

Comments

@envas
Copy link

envas commented Jul 31, 2024

We have approximately 100 albums, and retrieving the list takes a long time. The same is true for albums with a large number of photos. Because the component's API call starts before the page is rendered, there is no chance of a loading indicator showing. It would be nice to have some JavaScript 'before API call' callback to allow a loading indicator.

@Fl0Cri
Copy link
Member

Fl0Cri commented Aug 5, 2024

This is an interesting idea, we may think about implementing some kind of lazy-loading in the future, but we must be careful to not break things for people who have overridden the partials of this component.

For now, here is a trick to lazy-load the albums list using October's AJAX framework:

  1. In your page or layout, remove the [googlePhotosAlbums] component

  2. Instead, add the following function in the code section:

function onLoadGooglePhotosAlbums()
{
    // Register the component dynamically when this handler is called
    $component = $this->controller->addComponent('googlePhotosAlbums', 'googlePhotosAlbums', [
        'albumPage' => 'google-photos/album',
        'thumbHeight' => 160,
        'thumbWidth' => 160,
        'shouldCrop' => 1,
    ]);

    // Specific to this component: ask to load gallery data. This may not be necessary in a future version
    $component->onRun();

    // Replace spinner by the gallery
    return [
        '#googlePhotosAlbums' => $this->renderComponent('googlePhotosAlbums'),
    ];
}
  1. Finally, in the html section of the page, replace {% component 'googlePhotosAlbums' %} by this:
{# The container for the gallery #}
<div id="googlePhotosAlbums">
    {# Inside, put a spinner or anything to be shown on page load. In this example, this is a Bootstrap 5 spinner #}
    <div class="spinner-border" role="status">
        <span class="visually-hidden">Loading...</span>
    </div>
</div>

{# Some JS to trigger the onLoadGooglePhotosAlbums() handler after the page is loaded #}
<script>
    document.addEventListener('DOMContentLoaded', function () {
        oc.request(this, 'onLoadGooglePhotosAlbums'); // OC >= 3
        // $(this).request('onLoadGooglePhotosAlbums'); // OC < 3 (needs jQuery)
    });
</script>

@Fl0Cri Fl0Cri closed this as completed Aug 5, 2024
@Fl0Cri
Copy link
Member

Fl0Cri commented Aug 5, 2024

I will keep this issue open, so I remember to work on this when I get some time

@Fl0Cri Fl0Cri reopened this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants