fix: nsfw album toggle doesn't propagate the changes properly

fix: add nsfw flag to the booleanFields in knex postProcessResponse
This commit is contained in:
Zephyrrus 2020-12-27 18:18:06 +02:00
parent edb3bed988
commit 13058d99d6
5 changed files with 15 additions and 15 deletions

View File

@ -16,7 +16,7 @@ class albumEditPOST extends Route {
try {
const updateObj = {
name: name ? name : album.name,
name: name || album.name,
nsfw: nsfw === true ? true : nsfw === false ? false : album.nsfw
};
await db

View File

@ -16,7 +16,7 @@ const db = require('knex')({
some things like different data types for booleans need to be considered like in
the implementation below where sqlite returns 1 and 0 instead of true and false.
*/
const booleanFields = ['enabled', 'enableDownload', 'isAdmin'];
const booleanFields = ['enabled', 'enableDownload', 'isAdmin', 'nsfw'];
const processResponse = row => {
Object.keys(row).forEach(key => {

View File

@ -100,9 +100,7 @@
<div class="level-right">
<div class="level-item">
<b-switch
v-model="isNsfw"
:false-value="0"
:true-value="1"
:value="nsfw"
@input="toggleNsfw()" />
</div>
<div class="level-item">
@ -132,6 +130,10 @@ export default {
details: {
'type': Object,
'default': () => ({})
},
nsfw: {
'type': Boolean,
'default': false
}
},
data() {
@ -141,10 +143,7 @@ export default {
};
},
computed: {
...mapState(['config', 'auth']),
isNsfw() {
return this.$store.state.albums.list.find(a => a.id === this.albumId).nsfw;
}
...mapState(['config', 'auth'])
},
mounted() {
console.log(this.isNsfw);
@ -156,7 +155,7 @@ export default {
updateLinkOptionsAction: 'albums/updateLinkOptions',
createLinkAction: 'albums/createLink',
createCustomLinkAction: 'albums/createCustomLink',
toggleNsfw: 'albums/toggleNsfw',
toggleNsfwAction: 'albums/toggleNsfw',
alert: 'alert/set'
}),
promptDeleteAlbum(id) {
@ -217,9 +216,9 @@ export default {
},
async toggleNsfw() {
try {
const response = await this.toggleNsfw({
const response = await this.toggleNsfwAction({
albumId: this.albumId,
nsfw: !this.isNsfw
nsfw: !this.nsfw
});
this.alert({ text: response.message, error: false });
} catch (e) {

View File

@ -53,7 +53,8 @@
<AlbumDetails
v-if="isExpanded"
:details="getDetails(album.id)"
:album-id="album.id" />
:album-id="album.id"
:nsfw="album.nsfw" />
</div>
</template>

View File

@ -127,8 +127,8 @@ export const mutations = {
const link = state.albumDetails[albumId].links[foundIndex];
state.albumDetails[albumId].links[foundIndex] = { ...link, ...linkOpts };
},
updateNsfw(state, { albumId, value }) {
state.list.find(el => el.id === albumId).nsfw = value;
updateNsfw(state, { albumId, nsfw }) {
state.list.find(el => el.id === albumId).nsfw = nsfw;
},
removeAlbumLink(state, { albumId, identifier }) {
const foundIndex = state.albumDetails[albumId].links.findIndex(({ identifier: id }) => id === identifier);