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

Load config explicitly and remove setup routine of settings component #1892

Merged
merged 6 commits into from Nov 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -27,12 +27,14 @@
[#1832](https://github.com/nextcloud/cookbook/pull/1832) @christianlupus
- Provide id of recipe stub in API endpoints as well to make API consistend with recipe API
[#1834](https://github.com/nextcloud/cookbook/pull/1834) @christianlupus
- Hode the button to copy ingredients unless there are some ingredients to copy
- Hide the button to copy ingredients unless there are some ingredients to copy
[#1844](https://github.com/nextcloud/cookbook/pull/1844) @christianlupus
- Allow single tool in JSON+LD import, fixes #1641
[#1864](https://github.com/nextcloud/cookbook/pull/1844) @seyfeb
- Allow parsing more ISO 8601 duration strings. See issue [#1749](https://github.com/nextcloud/cookbook/issues/1749)
[#1871](https://github.com/nextcloud/cookbook/pull/1871) @seyfeb
- Load config at app loading only once and do not rewrite complete config
[#1892](https://github.com/nextcloud/cookbook/pull/1892) @christianlupus

### Maintenance
- Fix URL of Transifex after upstream subdomain change
Expand Down
2 changes: 1 addition & 1 deletion src/components/RecipeView.vue
Expand Up @@ -130,9 +130,9 @@
<section class="container">
<section class="ingredients">
<NcButton
v-if="scaledIngredients.length"
class="copy-ingredients"
:type="'tertiary'"
v-if="scaledIngredients.length"
@click="copyIngredientsToClipboard"
>
<template #icon>
Expand Down
99 changes: 35 additions & 64 deletions src/components/SettingsDialog.vue
Expand Up @@ -188,6 +188,8 @@

import { enableLogging } from "cookbook/js/logging"

import Vue from "vue"

export const SHOW_SETTINGS_EVENT = "show-settings"

const INFO_BLOCK_KEYS = [
Expand Down Expand Up @@ -221,25 +223,19 @@
isOpen: false,
printImage: false,
recipeFolder: "",
resetPrintImage: true,
showTagCloudInRecipeList: true,
resetTagCloud: true,
scanningLibrary: false,
// By setting the reset value initially to true, it will skip one watch event
// (the one when config is loaded at page load)
resetInterval: true,
updateInterval: 0,
visibleInfoBlocks: [...INFO_BLOCK_KEYS],
resetVisibleInfoBlocks: true,
writeChanges: true,
}
},
watch: {
async printImage(newVal, oldVal) {
// Avoid infinite loop on page load and when reseting value after failed submit
if (this.resetPrintImage) {
this.resetPrintImage = false
if (!this.writeChanges) {
seyfeb marked this conversation as resolved.
Show resolved Hide resolved
return
}

try {
await api.config.printImage.update(newVal)
// Should this check the response of the query? To catch some errors that redirect the page
Expand All @@ -248,25 +244,26 @@
// prettier-ignore
t("cookbook","Could not set preference for image printing"),
)
this.resetPrintImage = true
this.printImage = oldVal
}
},
// eslint-disable-next-line no-unused-vars
showTagCloudInRecipeList(newVal, oldVal) {
if (!this.writeChanges) {
return
}

this.$store.dispatch("setShowTagCloudInRecipeList", {
showTagCloud: newVal,
})
},
async updateInterval(newVal, oldVal) {
// Avoid infinite loop on page load and when reseting value after failed submit
if (this.resetInterval) {
this.resetInterval = false
if (!this.writeChanges) {
return
}

try {
await api.config.updateInterval.update(newVal)
// Should this check the response of the query? To catch some errors that redirect the page
} catch {
await showSimpleAlertModal(
// prettier-ignore
Expand All @@ -276,40 +273,56 @@
}
),
)
this.resetInterval = true
this.updateInterval = oldVal
}
},
async visibleInfoBlocks(newVal, oldVal) {
// Avoid infinite loop on page load and when reseting value after failed submit
if (this.resetVisibleInfoBlocks) {
this.resetVisibleInfoBlocks = false
if (!this.writeChanges) {
return
}

try {
const data = visibleInfoBlocksEncode(newVal)
await api.config.visibleInfoBlocks.update(data)
await this.$store.dispatch("refreshConfig")
seyfeb marked this conversation as resolved.
Show resolved Hide resolved
// Should this check the response of the query? To catch some errors that redirect the page
} catch (err) {
// eslint-disable-next-line no-console
console.error("Error while trying to save info blocks", err)
await showSimpleAlertModal(
t("cookbook", "Could not save visible info blocks"),
)
this.resetVisibleInfoBlocks = true
this.visibleInfoBlocks = oldVal
}
},
},
mounted() {
this.setup()

subscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings)
},
methods: {
handleShowSettings() {
this.isOpen = true

// Temporarily disable the storage of data
this.writeChanges = false

const { config } = this.$store.state

if (!config) {
throw new Error()
}

this.printImage = config.print_image
this.visibleInfoBlocks = visibleInfoBlocksDecode(
config.visibleInfoBlocks,
)
this.showTagCloudInRecipeList =
this.$store.state.localSettings.showTagCloudInRecipeList
this.updateInterval = config.update_interval
this.recipeFolder = config.folder

Vue.nextTick(() => {
this.writeChanges = true
})
},

/**
Expand Down Expand Up @@ -348,36 +361,6 @@
})
},

/**
* Initial setup
*/
async setup() {
try {
await this.$store.dispatch("refreshConfig")
const { config } = this.$store.state
this.resetPrintImage = false
this.resetVisibleInfoBlocks = false

if (!config) {
throw new Error()
}

this.printImage = config.print_image
this.visibleInfoBlocks = visibleInfoBlocksDecode(
config.visibleInfoBlocks,
)
this.showTagCloudInRecipeList =
this.$store.state.localSettings.showTagCloudInRecipeList
this.updateInterval = config.update_interval
this.recipeFolder = config.folder
} catch (err) {
this.$log.error("Error setting up SettingsDialog", err)
await showSimpleAlertModal(
t("cookbook", "Loading config failed"),
)
}
},

/**
* Reindex all recipes
*/
Expand Down Expand Up @@ -419,7 +402,7 @@
</script>

<style scoped>
/* TODO: Use @nextcloud/vue LoadingIcon once we update to 7.0.0 and we won't

Check warning on line 405 in src/components/SettingsDialog.vue

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found TODO: Use @nextcloud/vue LoadingIcon once we update to 7.0.0 and we won't
* have to do this */
.material-design-icon.loading-icon:deep(svg) {
animation: rotate var(--animation-duration, 0.8s) linear infinite;
Expand All @@ -438,16 +421,4 @@
display: block;
width: 100%;
}

/* #app-settings .button { */
/* z-index: 2; */
/* height: 44px; */
/* padding: 0; */
/* border-radius: var(--border-radius); */
/* } */

/* #app-settings .button p { */
/* margin: auto; */
/* font-size: 13px; */
/* } */
</style>
2 changes: 2 additions & 0 deletions src/guest.js
Expand Up @@ -27,6 +27,8 @@ Vue.prototype.OC = OC
// Pass translation engine to Vue
Vue.prototype.t = window.t

store.dispatch("refreshConfig")

// Start the app once document is done loading
const App = Vue.extend(AppInvalidGuest)
new App({
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Expand Up @@ -51,12 +51,14 @@
flavor: "vanilla",
})

// TODO: Equivalent library for Vue3 when we make that transition:

Check warning on line 54 in src/main.js

View workflow job for this annotation

GitHub Actions / Check for added todo messages

Found TODO: Equivalent library for Vue3 when we make that transition:
// https://github.com/rlemaigre/vue3-promise-dialog
Vue.use(ModalDialogs)

setupLogging(Vue)

store.dispatch("refreshConfig")

// Pass translation engine to Vue
Vue.prototype.t = window.t

Expand Down