From e9858b81cc2c3a79d32743061a3b566edde80297 Mon Sep 17 00:00:00 2001 From: Roman Cervantes Date: Sun, 1 Nov 2020 14:46:17 -0700 Subject: [PATCH] fetch metadatas for wallpapers --- src/store/actions.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/store/actions.js b/src/store/actions.js index a007d272..b77ba302 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -144,13 +144,6 @@ export default { .listAll() .then(({ items }) => { const wallpapers = items.map(({ fullPath, name }) => { - const forestRef = firebase.storage().ref(fullPath); - - forestRef.getMetadata().then((metadata) => { - // TODO: get sizes - console.log(metadata); - }); - const wallpaper = { fullPath, name, @@ -160,6 +153,7 @@ export default { }); // TODO: refactor? there's gotta be a better way to do this + // TODO: for real, refactor this crap, use promise.all or something better const fetchedUrls = []; wallpapers.forEach(({ fullPath }, index) => { @@ -172,8 +166,22 @@ export default { wallpapers[index].url = url; if (fetchedUrls.length === wallpapers.length) { - commit('SET_WALLPAPERS', wallpapers); - resolve(); + const fetchedMetadatas = []; + + wallpapers.forEach((wallpaper, i) => { + const forestRef = firebase.storage().ref(wallpaper.fullPath); + + forestRef.getMetadata().then((metadata) => { + fetchedMetadatas.push(metadata); + + wallpapers[i].metadata = metadata; + + if (fetchedMetadatas.length === wallpapers.length) { + commit('SET_WALLPAPERS', wallpapers); + resolve(); + } + }); + }); } }) .catch(reject);