From 899d2bf551e111bdc68608dba02e93782eec9f85 Mon Sep 17 00:00:00 2001 From: Amine Date: Tue, 31 Mar 2020 14:09:05 +0100 Subject: #418 #477 Refactor Todo settings, add predefined Todo apps list * add condition if on todo options * add drop down for todo server * fix error TODOS_FRONTEND * add todo list apps' * update name of dropdown menu to Todo Service * add other service to dropdown menu and subsetting field for user to input url * add Other Service to drop down * fixed typos * reverted wording * fix custom field * fix linting * fix linting * Delete tsconfig.tsbuildinfo * Delete tsconfig.tsbuildinfo * Delete tsconfig.tsbuildinfo * Add regex to validate custom todo url * Add note with source of regex function * Move regex function declaration to function body root * Apply code style * Add migration for todo settings * Apply code style Co-authored-by: romain Co-authored-by: Roman <46404814+yourcontact@users.noreply.github.com> Co-authored-by: romain --- src/features/todos/components/TodosWebview.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/features/todos') diff --git a/src/features/todos/components/TodosWebview.js b/src/features/todos/components/TodosWebview.js index e9b1963f7..2626186e9 100644 --- a/src/features/todos/components/TodosWebview.js +++ b/src/features/todos/components/TodosWebview.js @@ -9,10 +9,20 @@ import { defineMessages, intlShape } from 'react-intl'; import { mdiCheckAll } from '@mdi/js'; import SettingsStore from '../../../stores/SettingsStore'; -import * as environment from '../../../environment'; import Appear from '../../../components/ui/effects/Appear'; import UpgradeButton from '../../../components/ui/UpgradeButton'; +// NOTE: https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url +function validURL(str) { + const pattern = new RegExp('^(https?:\\/\\/)?' // protocol + + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' // domain name + + '((\\d{1,3}\\.){3}\\d{1,3}))' // OR ip (v4) address + + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' // port and path + + '(\\?[;&a-z\\d%_.~+=-]*)?' // query string + + '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator + return !!pattern.test(str); +} + const messages = defineMessages({ premiumInfo: { id: 'feature.todos.premium.info', @@ -194,6 +204,16 @@ class TodosWebview extends Component { const { intl } = this.context; + const isUsingPredefinedTodoServer = stores.settings.all.app.predefinedTodoServer !== 'isUsingCustomTodoService'; + const todoUrl = isUsingPredefinedTodoServer + ? stores.settings.all.app.predefinedTodoServer + : stores.settings.all.app.customTodoServer; + let isTodoUrlValid = true; + if (isUsingPredefinedTodoServer === false) { + isTodoUrlValid = validURL(todoUrl); + } + + return (
)} {isTodosIncludedInCurrentPlan ? ( + isTodoUrlValid + && ( { @@ -223,8 +245,9 @@ class TodosWebview extends Component { partition="persist:todos" preload="./features/todos/preload.js" ref={(webview) => { this.webview = webview ? webview.view : null; }} - src={stores.settings.all.app.todoServer || environment.TODOS_FRONTEND} + src={todoUrl} /> + ) ) : (
-- cgit v1.2.3-54-g00ecf