Просмотр исходного кода

joinCheckRedirect on one function

Steven Fukase 4 лет назад
Родитель
Сommit
4a37dbefa2
2 измененных файлов с 7 добавлено и 10 удалено
  1. 6 9
      src/client/js/components/PageCreateModal.jsx
  2. 1 1
      src/lib/util/path-utils.js

+ 6 - 9
src/client/js/components/PageCreateModal.jsx

@@ -73,16 +73,16 @@ const PageCreateModal = (props) => {
   /**
    * join path and check if creatable
    * @param {string} paths
-   * @returns {boolean}
    */
-  function joinAndCheck(...paths) {
+  function joinCheckRedirect(...paths) {
     const joinedUrl = encodeURI(urljoin(...paths));
     if (!isCreatablePage(joinedUrl)) {
       toastError('Invalid characters found.');
       return;
     }
-    return joinedUrl;
+    window.location.href = generateEditorPath(joinedUrl);
   }
+
   /**
    * access today page
    */
@@ -91,16 +91,14 @@ const PageCreateModal = (props) => {
     if (tmpTodayInput1 === '') {
       tmpTodayInput1 = t('Memo');
     }
-    const joinedUrl = joinAndCheck(userPageRootPath, tmpTodayInput1, now, todayInput2);
-    window.location.href = generateEditorPath(joinedUrl);
+    joinCheckRedirect(userPageRootPath, tmpTodayInput1, now, todayInput2);
   }
 
   /**
    * access input page
    */
   function createInputPage() {
-    joinAndCheck(pageNameInput);
-    window.location.href = generateEditorPath(pageNameInput);
+    joinCheckRedirect(pageNameInput);
   }
 
   function ppacInputChangeHandler(value) {
@@ -116,8 +114,7 @@ const PageCreateModal = (props) => {
    */
   function createTemplatePage(e) {
     const pageName = (template === 'children') ? '_template' : '__template';
-    const joinedUrl = joinAndCheck(urljoin(pathname, pageName));
-    window.location.href = generateEditorPath(joinedUrl);
+    joinCheckRedirect(pathname, pageName);
   }
 
   function renderCreateTodayForm() {

+ 1 - 1
src/lib/util/path-utils.js

@@ -71,7 +71,7 @@ const isCreatablePage = (path) => {
 };
 
 /**
- * join paths, check url, then redirect to edit page
+ * return path to editor
  * @param {string} path
  * @returns {string}
  */