From b0ecce5eab2a6d0eed3ade7c43e252ca9bac7edb Mon Sep 17 00:00:00 2001 From: kytwb <412895+kytwb@users.noreply.github.com> Date: Sat, 12 Jun 2021 19:51:28 +0200 Subject: Fix active Todos service behaviour (#1481) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Return false instead of null in isTodosServiceAdded * Resolve from TODOS_RECIPES_ID instead of hardcoded TODOS_RECIPE_ID * Fix TodosWebview width toggling when isTodosServiceActive * Add more todo service recipe IDs * Refactor todos state management * Moved todos service URL and recipe ID computation logic to todos/store * Simplified TodosWebview by delegating to the store for the URL and removing the (unused) payment logic * Made the todos service computation logic in the Service model depend on the logic in todos/store * Made ServicesStore depend on the todos service logic from the Service model * Todos appearance fixes * Hide double horizontal rules if todo settings are hidden due to an added todo service * Hide todos panel border when the panel is hidden or expanded * Make expanded todos panel obey sidebar width and vertical style settings * Make todos/store use isValidExternalURL * Harden isValidExternalURL against malformed URLs * Reduce todo URL string duplication in config.js Co-authored-by: Kristóf Marussy --- src/features/todos/store.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/features/todos/store.js') diff --git a/src/features/todos/store.js b/src/features/todos/store.js index af8519d9c..4febd7bb1 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js @@ -7,6 +7,8 @@ import { import localStorage from 'mobx-localstorage'; import { todoActions } from './actions'; +import { CUSTOM_TODO_SERVICE, TODO_SERVICE_RECIPE_IDS } from '../../config'; +import { isValidExternalURL } from '../../helpers/url-helpers'; import { FeatureStore } from '../utils/FeatureStore'; import { createReactions } from '../../stores/lib/Reaction'; import { createActionBindings } from '../utils/ActionBinding'; @@ -21,6 +23,8 @@ import UserAgent from '../../models/UserAgent'; const debug = require('debug')('Ferdi:feature:todos:store'); export default class TodoStore extends FeatureStore { + @observable stores = null; + @observable isFeatureEnabled = false; @observable isFeatureActive = false; @@ -59,6 +63,31 @@ export default class TodoStore extends FeatureStore { return this.userAgentModel.userAgent; } + @computed get isUsingPredefinedTodoServer() { + return this.stores && this.stores.settings.app.predefinedTodoServer !== CUSTOM_TODO_SERVICE; + } + + @computed get todoUrl() { + if (!this.stores) { + return null; + } + return this.isUsingPredefinedTodoServer + ? this.stores.settings.app.predefinedTodoServer + : this.stores.settings.app.customTodoServer; + } + + @computed get isTodoUrlValid() { + return !this.isUsingPredefinedTodoServer || isValidExternalURL(this.todoUrl); + } + + @computed get todoRecipeId() { + if (this.isFeatureEnabledByUser && this.isUsingPredefinedTodoServer + && this.todoUrl in TODO_SERVICE_RECIPE_IDS) { + return TODO_SERVICE_RECIPE_IDS[this.todoUrl]; + } + return null; + } + // ========== PUBLIC API ========= // @action start(stores, actions) { -- cgit v1.2.3-70-g09d2