Created
February 26, 2018 22:05
-
-
Save mflisikowski/f7ccde6ebd1b5b9857b753b170505ba6 to your computer and use it in GitHub Desktop.
Firebase Realtime Database Albums
This file contains hidden or 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
export default { | |
data() { | |
return { | |
galleryAlbums: [], | |
dialogAlbumImages: false | |
} | |
}, | |
created() { | |
this.getAlbums() | |
}, | |
computed: { | |
reverseAlbums() { | |
return this.galleryAlbums.slice().reverse() | |
} | |
}, | |
methods: { | |
async getAlbums() { | |
const album = await this.$database.ref(`albums`).once('value') | |
const albumData = await album.val() || {} | |
const newAlbum = [] | |
Object.entries(albumData).map(albums => { | |
const images = [] | |
const covers = [] | |
const id = albums[0] | |
Object.values(albums[1]).map(async imageId => { | |
const image = await this.$database.ref(`images/${imageId}`).once('value') | |
const snapshotData = image.val() | |
delete snapshotData.original | |
delete snapshotData.slider | |
const gallery = snapshotData.gallery['url'] | |
const about = snapshotData.about['url'] | |
const icon = snapshotData.icon['url'] | |
covers.push(icon) | |
images.push({ gallery, about, icon }) | |
}) | |
newAlbum.push({id, covers, images}) | |
this.galleryAlbums = [] | |
this.galleryAlbums.push(...newAlbum) // Array.from(new Set([...newAlbum])) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment