2019-04-09 04:17:26 +00:00
|
|
|
<template>
|
|
|
|
<div class="wallpaper-upload">
|
|
|
|
<div class="loading" v-if="loading">
|
|
|
|
<i class="fas fa-sync-alt fa-2x fast-spin" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-else>
|
2019-04-09 20:40:56 +00:00
|
|
|
<div v-show="!wallpaperUrl">
|
|
|
|
Upload wallpaper
|
|
|
|
|
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
accept='image/*'
|
|
|
|
@change="handleUpload"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-04-09 04:17:26 +00:00
|
|
|
|
|
|
|
<div v-if="wallpaperUrl">
|
2019-04-13 22:05:26 +00:00
|
|
|
<h5>Semi transparent lists</h5>
|
|
|
|
|
|
|
|
<div class="button-group">
|
|
|
|
<button
|
|
|
|
class="small tiny"
|
|
|
|
:class="{ primary: !transparent }"
|
|
|
|
@click="setTransparent(false)"
|
|
|
|
>
|
|
|
|
No
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="small tiny"
|
|
|
|
:class="{ primary: transparent }"
|
|
|
|
@click="setTransparent(true)"
|
|
|
|
>
|
|
|
|
Yes
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<h5>Current wallpaper</h5>
|
|
|
|
|
2019-04-09 04:17:26 +00:00
|
|
|
<img
|
|
|
|
:src="wallpaperUrl"
|
|
|
|
alt="Uploaded wallpaper"
|
|
|
|
/>
|
|
|
|
|
2019-04-13 22:05:26 +00:00
|
|
|
<button class="error small tiny" @click="removeWallpaper">
|
2019-04-09 04:17:26 +00:00
|
|
|
<i class="fas fa-trash" />
|
|
|
|
Remove wallpaper
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import firebase from 'firebase/app';
|
|
|
|
import 'firebase/firestore';
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
2019-04-09 20:43:08 +00:00
|
|
|
const db = firebase.firestore();
|
|
|
|
|
2019-04-09 04:17:26 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
progressUpload: 0,
|
|
|
|
file: File,
|
|
|
|
uploadTask: '',
|
|
|
|
wallpapers: {},
|
2019-04-13 22:05:26 +00:00
|
|
|
transparent: false,
|
2019-04-09 04:17:26 +00:00
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['user', 'settings', 'platform', 'wallpaperUrl']),
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.wallpapers = this.settings && this.settings.wallpapers
|
|
|
|
? JSON.parse(JSON.stringify(this.settings.wallpapers))
|
|
|
|
: {};
|
2019-04-13 22:05:26 +00:00
|
|
|
|
|
|
|
if (!this.wallpapers[this.platform.code]) {
|
|
|
|
this.wallpapers[this.platform.code] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transparent = this.wallpapers[this.platform.code].transparent || false;
|
2019-04-09 04:17:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2019-04-13 22:05:26 +00:00
|
|
|
setTransparent(value) {
|
|
|
|
this.transparent = value;
|
|
|
|
this.saveSettings();
|
|
|
|
},
|
|
|
|
|
2019-04-09 20:43:08 +00:00
|
|
|
removeWallpaper() {
|
2019-04-09 04:17:26 +00:00
|
|
|
delete this.wallpapers[this.platform.code];
|
|
|
|
|
2019-04-13 22:05:26 +00:00
|
|
|
this.saveSettings();
|
|
|
|
},
|
|
|
|
|
|
|
|
saveSettings() {
|
|
|
|
this.wallpapers[this.platform.code].transparent = this.transparent;
|
|
|
|
|
2019-04-09 20:43:08 +00:00
|
|
|
const settings = {
|
2019-04-09 04:17:26 +00:00
|
|
|
...this.settings,
|
|
|
|
wallpapers: this.wallpapers,
|
2019-04-09 21:05:46 +00:00
|
|
|
};
|
2019-04-09 20:43:08 +00:00
|
|
|
|
|
|
|
db.collection('settings').doc(this.user.uid).set(settings)
|
|
|
|
.then(() => {
|
|
|
|
this.$store.commit('SET_SETTINGS', settings);
|
|
|
|
this.$bus.$emit('TOAST', { message: 'Settings saved' });
|
|
|
|
this.loading = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$bus.$emit('TOAST', { message: 'There was an error saving your settings', type: 'error' });
|
|
|
|
this.loading = false;
|
|
|
|
});
|
2019-04-09 04:17:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
handleUpload(e) {
|
|
|
|
this.loading = true;
|
|
|
|
const file = e.target.files[0];
|
|
|
|
const extenstion = file.name.split('.')[1];
|
|
|
|
|
|
|
|
firebase.storage().ref(`${this.user.uid}/wallpapers/${this.platform.code}.${extenstion}`).put(file)
|
|
|
|
.then(({ state, metadata }) => {
|
|
|
|
if (state === 'success') {
|
|
|
|
if (!this.wallpapers[this.platform.code]) {
|
|
|
|
this.wallpapers[this.platform.code] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.wallpapers[this.platform.code].url = metadata.fullPath;
|
|
|
|
|
2019-04-09 20:43:08 +00:00
|
|
|
this.saveSettings({
|
2019-04-09 04:17:26 +00:00
|
|
|
...this.settings,
|
|
|
|
wallpapers: this.wallpapers,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss" scoped>
|
|
|
|
@import "~styles/styles.scss";
|
|
|
|
|
|
|
|
.wallpaper-upload {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
img {
|
|
|
|
width: 100%;
|
|
|
|
height: auto;
|
|
|
|
border: 1px solid $color-gray;
|
|
|
|
padding: $gp / 2;
|
|
|
|
border-radius: $border-radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
input {
|
|
|
|
width: auto;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
padding: $gp / 2;
|
|
|
|
height: auto;
|
|
|
|
width: 100%;
|
|
|
|
border: 1px solid $color-green;
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading {
|
|
|
|
height: 200px;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|