async createWork ({commit}, payload) {
commit('clearError')
commit('setLoading', true)
let imageSrc = [];
let key
try {
const newWork = new Work (
payload.name,
payload.description,
payload.type,
payload.date,
payload.repository,
payload.link,
payload.tags,
key,
imageSrc
)
await fb.database().ref('works').push(newWork)
.then((data) => {
key = data.key
return key
})
.then(key => {
payload.image.forEach((item,index) => {
let ext = item.name.slice(item.name.lastIndexOf('.'));
let itemRef = fb.storage().ref(`works/${key}/${index}.${ext}`);
itemRef.put(item).then(() => {
itemRef.getDownloadURL().then(url => {
imageSrc.push(url)
})
.then(() => {
fb.database().ref('works').child(key).update({imageSrc: imageSrc})
})
})
})
})
.then(() => {
console.log(key)
commit('setLoading', false)
commit('createWork', {
...newWork,
id: key,
imageSrc: imageSrc
})
})
} catch (error) {
commit('setError', error.message)
commit('setLoading', false)
throw error
}
}
methods: {
blur () {
let el = this.$refs.parallax;
let val = document.documentElement.scrollTop / 100;
el.style.filter = `blur(${val}px)`;
}
},
created () {
window.addEventListener('scroll', this.blur)
},
destroyed () {
window.removeEventListener('scroll', this.blur);
}