Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor skin selection #894

Merged
merged 21 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions src/components/Pages/ManageWiki/Cards/QuestyCaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,18 @@
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
<v-snackbar :color="message.status" elevation="24" v-model="message.show">
{{ message.text }}
<template v-slot:action>
<v-btn
text
variant="text"
@click="message.show = false"
>
Close
</v-btn>
</template>
</v-snackbar>
<Message ref="message" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://v2.vuejs.org/v2/guide/components#Passing-Data-to-Child-Components-with-Props

I believe generally it's recommended to use props rather than $refs to pass data down to child components. Did you try this and find it wasn't possible?

Copy link
Contributor Author

@deer-wmde deer-wmde Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah I'm just a vue noob, will adjust soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just looked at the docs, I'm not just passing data but calling a method, not sure if there would be another way then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could argue that we shouldnt know about the method and design the component in a way that changing the properties calls the method, but now I'm way out of bounds of my knowledge about vue architecture

</v-card>
</template>

<script>
import Message from '../Features/Message.vue'

export default {
name: 'QuestyCaptcha',
components: {
Message
},
props: [
'wikiId'
],
Expand Down Expand Up @@ -144,9 +138,6 @@ export default {
answers: []
})
},
showMessage (status, message) {
this.message = { status: status, text: message, show: true }
},
formatQuestionsForApi (questions) {
return JSON.stringify(questions.reduce((out, entry) => {
out[entry.question] = entry.answers
Expand All @@ -165,10 +156,10 @@ export default {
}
await this.$store.dispatch('updateSetting', { wiki: this.wikiId, setting: 'wwUseQuestyCaptcha', value: enabled })
await this.$store.dispatch('setEnabledQuestyCaptcha', enabled)
this.showMessage('success', `QuestyCaptcha has been successfully ${enabled ? 'enabled' : 'disabled'}.`)
this.$refs.message.show('success', `QuestyCaptcha has been successfully ${enabled ? 'enabled' : 'disabled'}.`)
} catch (error) {
console.log(error.response)
this.showMessage('error', `Something went wrong while ${enabled ? 'enabling' : 'disabling'} QuestyCaptcha. Please try again.`)
console.error(error.response)
this.$refs.message('error', `Something went wrong while ${enabled ? 'enabling' : 'disabling'} QuestyCaptcha. Please try again.`)
await this.$nextTick()
this.isCaptchaActive = !enabled
} finally {
Expand Down Expand Up @@ -203,12 +194,12 @@ export default {
wiki: this.wikiId, setting: 'wwCaptchaQuestions', value: this.formatQuestionsForApi(this.questionsFromStore)
})
await this.$store.dispatch('setQuestyCaptchaQuestions', this.questionsFromStore)
this.showMessage('success', 'Your questions have been saved.')
this.$refs.message.show('success', 'Your questions have been saved.')
this.hasNoQuestions = false
this.panel = false
} catch (error) {
console.log(error.response)
this.showMessage('error', 'Something went wrong with saving your questions. Please try again.')
console.error(error.response)
this.$refs.message.show('error', 'Something went wrong with saving your questions. Please try again.')
} finally {
this.waitForQuestionsUpdate = false
}
Expand Down
49 changes: 33 additions & 16 deletions src/components/Pages/ManageWiki/Cards/Skin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<v-card-title>Set Skin</v-card-title>
<v-card-text>
<v-select
:items="items"
:items="skins"
label="Skin"
placeholder="Pick a Skin"
hint="The default skin is Vector."
persistent-hint
prepend-icon="mdi-web"
v-model="skin"
:disabled="inFlight"
deer-wmde marked this conversation as resolved.
Show resolved Hide resolved
:error-messages="error"
v-model="skinId"
></v-select>
</v-card-text>
<v-card-actions>
Expand All @@ -22,45 +22,62 @@
<span>It may take up to 10 seconds for changes to be reflected on your wiki</span>
</v-tooltip>
</v-card-actions>
<Message ref="message" />
</v-card>
</template>

<script>
import Message from '../Features/Message.vue'

export default {
name: 'Skin',
components: {
Message
},
props: [
'wikiId'
],
data () {
return {
items: [
'Vector',
'Modern',
'Timeless'
skins: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect minerva and vector-2022 to be part of this array. As I understood we want them added to the skins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, so we removed them again because they are not ready to be used yet. After our next mediawiki update we will be able to include them here. Until then I changed this PR so that it's just some code refactoring, basically preparation to add them in the future + reuse of the snackbar for alerts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see I will then merge this

{
value: 'vector',
text: 'Vector'
},
{
value: 'modern',
text: 'Modern'
},
{
value: 'timeless',
text: 'Timeless'
}
],
skin: '',
inFlight: false,
error: ''
skinId: '',
message: false
}
},
created () {
const skin = this.$store.state.wikis.currentWikiSettings.wgDefaultSkin
this.skin = skin.charAt(0).toUpperCase() + skin.slice(1)
this.skinId = this.$store.state.wikis.currentWikiSettings.wgDefaultSkin
},
computed: {
skin () {
return this.skins.find(skin => skin.value === this.skinId)
}
},
methods: {
doSetSkin () {
const wiki = this.wikiId
// API needs the skin ID which is lower case..
const value = this.skin.toLowerCase()
const value = this.skin.value

this.$store
.dispatch('updateSkin', { wiki, value })
.then(() => {
alert('Update success!')
this.$refs.message.show('success', `Your default skin has been updated to ${this.skin.text}.`)
})
.catch(err => {
console.log(err.response)
alert('Something went wrong.')
console.error(err.response)
this.$refs.message.show('error', 'Something went wrong while updating your default skin. Please try again.')
})
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/components/Pages/ManageWiki/Features/Message.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<v-snackbar :color="status" elevation="24" v-model="visible">
{{ text }}
<template v-slot:action>
<v-btn
text
variant="text"
@click="hide"
>
Close
</v-btn>
</template>
</v-snackbar>
</template>

<script>
export default {
data () {
return {
visible: false,
text: 'Hello, this is a snackbar message!',
status: 'success'
}
},
methods: {
show (status, message) {
this.status = status
this.text = message
this.visible = true
},

hide () {
this.visible = false
}
}
}
</script>

<style scoped>
</style>
Loading