From ba1a43646e5688d0ed80c386da8d84bd11c7b340 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Fri, 29 Nov 2024 11:16:17 +0100 Subject: [PATCH] Add Album loading progress spinner (#2751) --- resources/js/composables/album/albumRefresher.ts | 7 +++++++ .../js/composables/album/albumsRefresher.ts | 14 +++++++++++--- resources/js/layouts/PhotoLayout.ts | 4 ++-- resources/js/views/gallery-panels/Album.vue | 14 +++++++++----- resources/js/views/gallery-panels/Albums.vue | 16 +++++++++------- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/resources/js/composables/album/albumRefresher.ts b/resources/js/composables/album/albumRefresher.ts index 29a84c1233a..a22bd9b80c7 100644 --- a/resources/js/composables/album/albumRefresher.ts +++ b/resources/js/composables/album/albumRefresher.ts @@ -4,6 +4,7 @@ import { computed, Ref, ref } from "vue"; export function useAlbumRefresher(albumId: Ref, auth: AuthStore, isLoginOpen: Ref, nsfw_consented: Ref) { const isPasswordProtected = ref(false); + const isLoading = ref(false); const user = ref(undefined); const modelAlbum = ref(undefined); const tagAlbum = ref(undefined); @@ -23,6 +24,8 @@ export function useAlbumRefresher(albumId: Ref, auth: AuthStore, isLogin } function loadAlbum(): Promise { + isLoading.value = true; + return AlbumService.get(albumId.value) .then((data) => { isPasswordProtected.value = false; @@ -50,6 +53,9 @@ export function useAlbumRefresher(albumId: Ref, auth: AuthStore, isLogin } else { console.error(error); } + }) + .finally(() => { + isLoading.value = false; }); } @@ -60,6 +66,7 @@ export function useAlbumRefresher(albumId: Ref, auth: AuthStore, isLogin return { isAlbumConsented, isPasswordProtected, + isLoading, albumId, user, modelAlbum, diff --git a/resources/js/composables/album/albumsRefresher.ts b/resources/js/composables/album/albumsRefresher.ts index 9ebf0199099..ab3d749f570 100644 --- a/resources/js/composables/album/albumsRefresher.ts +++ b/resources/js/composables/album/albumsRefresher.ts @@ -8,6 +8,7 @@ export function useAlbumsRefresher(auth: AuthStore, lycheeStore: LycheeStateStor const { spliter } = useSplitter(); const user = ref(undefined); const isKeybindingsHelpOpen = ref(false); + const isLoading = ref(false); const smartAlbums = ref([]); const albums = ref([]); const sharedAlbums = ref[]>([]); @@ -15,8 +16,10 @@ export function useAlbumsRefresher(auth: AuthStore, lycheeStore: LycheeStateStor const rootRights = ref(undefined); const selectableAlbums = computed(() => albums.value.concat(sharedAlbums.value.map((album) => album.data).flat())); - function refresh(): Promise { - auth.getUser().then((data) => { + function refresh(): Promise<[void, void]> { + isLoading.value = true; + + const getUser = auth.getUser().then((data) => { user.value = data; const body_width = document.body.scrollWidth; @@ -26,7 +29,7 @@ export function useAlbumsRefresher(auth: AuthStore, lycheeStore: LycheeStateStor } }); - return AlbumService.getAll() + const getAlbums = AlbumService.getAll() .then((data) => { smartAlbums.value = (data.data.smart_albums as App.Http.Resources.Models.ThumbAlbumResource[]) ?? []; albums.value = data.data.albums as App.Http.Resources.Models.ThumbAlbumResource[]; @@ -54,11 +57,16 @@ export function useAlbumsRefresher(auth: AuthStore, lycheeStore: LycheeStateStor console.error(error); } }); + + return Promise.all([getUser, getAlbums]).finally(() => { + isLoading.value = false; + }); } return { user, isKeybindingsHelpOpen, + isLoading, smartAlbums, albums, sharedAlbums, diff --git a/resources/js/layouts/PhotoLayout.ts b/resources/js/layouts/PhotoLayout.ts index 2e4e9603c18..0ba2dd06197 100644 --- a/resources/js/layouts/PhotoLayout.ts +++ b/resources/js/layouts/PhotoLayout.ts @@ -62,8 +62,8 @@ export function useGetLayoutConfig() { const layoutConfig = ref(null) as Ref; const layout = ref("square") as Ref; - function loadLayoutConfig() { - AlbumService.getLayout().then((data) => { + function loadLayoutConfig(): Promise { + return AlbumService.getLayout().then((data) => { layoutConfig.value = data.data; }); } diff --git a/resources/js/views/gallery-panels/Album.vue b/resources/js/views/gallery-panels/Album.vue index 036445ddcdb..6182a457b95 100644 --- a/resources/js/views/gallery-panels/Album.vue +++ b/resources/js/views/gallery-panels/Album.vue @@ -1,4 +1,5 @@