Browse Source

feat: handle create path

NGPixel 2 years ago
parent
commit
4d1ab1f193
4 changed files with 38 additions and 15 deletions
  1. 14 3
      ux/src/components/PageHeader.vue
  2. 17 0
      ux/src/pages/Index.vue
  3. 6 11
      ux/src/router/routes.js
  4. 1 1
      ux/src/stores/page.js

+ 14 - 3
ux/src/components/PageHeader.vue

@@ -108,6 +108,7 @@
         icon='las la-print'
         color='grey'
         aria-label='Print'
+        @click='printPage'
         )
         q-tooltip Print
     template(v-if='editorStore.isActive')
@@ -230,13 +231,19 @@ function openEditorSettings () {
 }
 
 async function discardChanges () {
-  // Is it the home page in create mode?
-  if (editorStore.mode === 'create' && pageStore.path === '' && pageStore.locale === 'en') {
+  // From create mode
+  if (editorStore.mode === 'create') {
     editorStore.$patch({
       isActive: false,
       editor: ''
     })
-    siteStore.overlay = 'Welcome'
+
+    // Is it the home page in create mode?
+    if ((pageStore.path === '' || pageStore.path === 'home') && pageStore.locale === 'en') {
+      siteStore.overlay = 'Welcome'
+    }
+
+    router.replace('/')
     return
   }
 
@@ -371,4 +378,8 @@ async function editPage () {
   await pageStore.pageEdit()
   $q.loading.hide()
 }
+
+function printPage () {
+  window.print()
+}
 </script>

+ 17 - 0
ux/src/pages/Index.vue

@@ -262,7 +262,24 @@ const lastModified = computed(() => {
 // WATCHERS
 
 watch(() => route.path, async (newValue) => {
+  // -> Enter Create Mode?
+  if (newValue.startsWith('/_create')) {
+    if (!route.params.editor) {
+      $q.notify({
+        type: 'negative',
+        message: 'No editor specified!'
+      })
+      return router.replace('/')
+    }
+    $q.loading.show()
+    await pageStore.pageCreate({ editor: route.params.editor })
+    $q.loading.hide()
+  }
+
+  // -> Moving to a non-page path? Ignore
   if (newValue.startsWith('/_')) { return }
+
+  // -> Load Page
   try {
     await pageStore.pageLoad({ path: newValue })
     if (editorStore.isActive) {

+ 6 - 11
ux/src/router/routes.js

@@ -1,14 +1,6 @@
 import { usePageStore } from 'src/stores/page'
 
 const routes = [
-  {
-    path: '/',
-    component: () => import('../layouts/MainLayout.vue'),
-    children: [
-      { path: '', component: () => import('../pages/Index.vue') },
-      { path: '_create/:editor?', component: () => import('../pages/Index.vue') }
-    ]
-  },
   {
     path: '/login',
     component: () => import('layouts/AuthLayout.vue'),
@@ -85,11 +77,14 @@ const routes = [
   // },
 
   // --------------------------------
-  // SYSTEM ROUTES CATCH-ALL FALLBACK
+  // CREATE
   // --------------------------------
   {
-    path: '/_:catchAll(.*)*',
-    redirect: '/_error/notfound'
+    path: '/_create/:editor?',
+    component: () => import('../layouts/MainLayout.vue'),
+    children: [
+      { path: '', component: () => import('../pages/Index.vue') }
+    ]
   },
   // -----------------------
   // STANDARD PAGE CATCH-ALL

+ 1 - 1
ux/src/stores/page.js

@@ -352,7 +352,7 @@ export const usePageStore = defineStore('page', {
         mode: 'edit'
       })
 
-      this.router.push('/_create')
+      this.router.push(`/_create/${editor}`)
     },
     /**
      * PAGE - EDIT