Skip to content

Instantly share code, notes, and snippets.

@mflisikowski
Created February 26, 2018 22:05
Show Gist options
  • Save mflisikowski/f7ccde6ebd1b5b9857b753b170505ba6 to your computer and use it in GitHub Desktop.
Save mflisikowski/f7ccde6ebd1b5b9857b753b170505ba6 to your computer and use it in GitHub Desktop.
Firebase Realtime Database Albums
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