Add option to remove a list background

This commit is contained in:
kolaente 2021-03-21 18:11:24 +01:00
parent da9d511f87
commit 1686663a3f
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 44 additions and 9 deletions

View file

@ -56,4 +56,19 @@ export default class ListService extends AbstractService {
return e return e
}) })
} }
removeBackground(list) {
const cancel = this.setLoading()
return this.http.delete(`/lists/${list.id}/background`, list)
.then(response => {
return Promise.resolve(response.data)
})
.catch(error => {
return this.errorHandler(error)
})
.finally(() => {
cancel()
})
}
} }

View file

@ -103,6 +103,10 @@ export const store = new Vuex.Store({
} }
} }
if (typeof currentList.backgroundInformation === 'undefined' || currentList.backgroundInformation === null) {
state.background = null
}
// Server updates don't return the right. Therefore the right is reset after updating the list which is // Server updates don't return the right. Therefore the right is reset after updating the list which is
// confusing because all the buttons will disappear in that case. To prevent this, we're keeping the right // confusing because all the buttons will disappear in that case. To prevent this, we're keeping the right
// when updating the list in global state. // when updating the list in global state.

View file

@ -6,6 +6,8 @@
class="list-background-setting" class="list-background-setting"
:wide="true" :wide="true"
v-if="uploadBackgroundEnabled || unsplashBackgroundEnabled" v-if="uploadBackgroundEnabled || unsplashBackgroundEnabled"
:tertary="hasBackground ? 'Remove Background' : ''"
@tertary="removeBackground()"
> >
<div class="mb-4" v-if="uploadBackgroundEnabled"> <div class="mb-4" v-if="uploadBackgroundEnabled">
<input <input
@ -53,15 +55,17 @@
type="secondary" type="secondary"
v-if="backgroundSearchResult.length > 0" v-if="backgroundSearchResult.length > 0"
> >
{{ backgroundService.loading ? 'Loading...' : 'Load more photos'}} {{ backgroundService.loading ? 'Loading...' : 'Load more photos' }}
</x-button> </x-button>
</template> </template>
</create-edit> </create-edit>
</template> </template>
<script> <script>
import {mapState} from 'vuex'
import BackgroundUnsplashService from '../../../services/backgroundUnsplash' import BackgroundUnsplashService from '../../../services/backgroundUnsplash'
import BackgroundUploadService from '../../../services/backgroundUpload' import BackgroundUploadService from '../../../services/backgroundUpload'
import ListService from '@/services/list'
import {CURRENT_LIST} from '@/store/mutation-types' import {CURRENT_LIST} from '@/store/mutation-types'
import CreateEdit from '@/components/misc/create-edit' import CreateEdit from '@/components/misc/create-edit'
@ -78,19 +82,19 @@ export default {
backgroundSearchTimeout: null, backgroundSearchTimeout: null,
backgroundUploadService: null, backgroundUploadService: null,
listService: null,
} }
}, },
computed: { computed: mapState({
unsplashBackgroundEnabled() { unsplashBackgroundEnabled: state => state.config.enabledBackgroundProviders.includes('unsplash'),
return this.$store.state.config.enabledBackgroundProviders.includes('unsplash') uploadBackgroundEnabled: state => state.config.enabledBackgroundProviders.includes('upload'),
}, currentList: state => state.currentList,
uploadBackgroundEnabled() { hasBackground: state => state.background !== null,
return this.$store.state.config.enabledBackgroundProviders.includes('upload') }),
},
},
created() { created() {
this.backgroundService = new BackgroundUnsplashService() this.backgroundService = new BackgroundUnsplashService()
this.backgroundUploadService = new BackgroundUploadService() this.backgroundUploadService = new BackgroundUploadService()
this.listService = new ListService()
this.setTitle('Set a list background') this.setTitle('Set a list background')
// Show the default collection of backgrounds // Show the default collection of backgrounds
this.newBackgroundSearch() this.newBackgroundSearch()
@ -161,6 +165,18 @@ export default {
this.error(e, this) this.error(e, this)
}) })
}, },
removeBackground() {
this.listService.removeBackground(this.currentList)
.then(l => {
this.$store.commit(CURRENT_LIST, l)
this.$store.commit('namespaces/setListInNamespaceById', l)
this.success({message: 'The background has been removed successfully!'}, this)
this.$router.back()
})
.catch(e => {
this.error(e, this)
})
},
}, },
} }
</script> </script>