Skip to content

Commit

Permalink
feat: rerender page
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Sep 4, 2023
1 parent add3631 commit a9784c3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 7 deletions.
6 changes: 3 additions & 3 deletions server/graph/resolvers/page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -603,17 +603,17 @@ export default {
}
},
/**
* RENDER PAGE
* RERENDER PAGE
*/
async renderPage (obj, args, context) {
async rerenderPage (obj, args, context) {
try {
const page = await WIKI.db.pages.query().findById(args.id)
if (!page) {
throw new WIKI.Error.PageNotFound()
}
await WIKI.db.pages.renderPage(page)
return {
operation: generateSuccess('Page rendered successfully.')
operation: generateSuccess('Page rerendered successfully.')
}
} catch (err) {
return generateError(err)
Expand Down
4 changes: 2 additions & 2 deletions server/graph/schemas/page.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ extend type Mutation {

rebuildPageTree: DefaultResponse

renderPage(
id: Int!
rerenderPage(
id: UUID!
): DefaultResponse

restorePage(
Expand Down
2 changes: 2 additions & 0 deletions server/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@
"profile.title": "Profile",
"profile.uploadNewAvatar": "Upload New Image",
"profile.viewPublicProfile": "View Public Profile",
"renderPageDialog.loading": "Rendering page...",
"renderPageDialog.success": "Page rerendered successfully.",
"search.editorAny": "Any editor",
"search.emptyQuery": "Enter a query in the search field above and press Enter.",
"search.filterEditor": "Editor",
Expand Down
15 changes: 13 additions & 2 deletions ux/src/components/PageActionsCol.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
q-icon(color='deep-orange-9', name='las la-atom', size='sm')
q-item-section
q-item-label Convert Page
q-item(clickable, v-if='userStore.can(`edit:pages`)')
q-item(clickable, v-if='userStore.can(`edit:pages`)', @click='rerenderPage')
q-item-section.items-center(avatar)
q-icon(color='deep-orange-9', name='las la-magic', size='sm')
q-item-section
q-item-label Re-render Page
q-item-label Rerender Page
q-item(clickable)
q-item-section.items-center(avatar)
q-icon(color='deep-orange-9', name='las la-sun', size='sm')
Expand Down Expand Up @@ -204,6 +204,17 @@ function viewPageSource () {
siteStore.$patch({ overlay: 'PageSource', overlayOpts: { } })
}
function rerenderPage () {
$q.dialog({
component: defineAsyncComponent(() => import('../components/RerenderPageDialog.vue')),
componentProps: {
id: pageStore.id
}
}).onOk(() => {
pageStore.pageLoad({ id: pageStore.id })
})
}
function duplicatePage () {
$q.dialog({
component: defineAsyncComponent(() => import('../components/TreeBrowserDialog.vue')),
Expand Down
81 changes: 81 additions & 0 deletions ux/src/components/RerenderPageDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template lang="pug">
q-dialog(ref='dialogRef', @hide='onDialogHide' position='bottom', persistent)
q-card(style='width: 350px;')
q-linear-progress(query, color='page')
q-card-section.text-center {{ t('renderPageDialog.loading') }}
</template>

<script setup>
import gql from 'graphql-tag'
import { useI18n } from 'vue-i18n'
import { useDialogPluginComponent, useQuasar } from 'quasar'
import { computed, onMounted, reactive } from 'vue'
import { usePageStore } from 'src/stores/page'
// EMITS
defineEmits([
...useDialogPluginComponent.emits
])
// QUASAR
const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginComponent()
const $q = useQuasar()
// STORES
const pageStore = usePageStore()
// I18N
const { t } = useI18n()
// METHODS
async function rerenderPage () {
await new Promise(resolve => setTimeout(resolve, 1000)) // allow for dialog to show
try {
const resp = await APOLLO_CLIENT.mutate({
mutation: gql`
mutation rerenderPage(
$id: UUID!
) {
rerenderPage (
id: $id
) {
operation {
succeeded
message
}
}
}
`,
variables: {
id: pageStore.id
}
})
if (resp?.data?.rerenderPage?.operation?.succeeded) {
$q.notify({
type: 'positive',
message: t('renderPageDialog.success')
})
onDialogOK()
} else {
throw new Error(resp?.data?.rerenderPage?.operation?.message || 'An unexpected error occured.')
}
} catch (err) {
$q.notify({
type: 'negative',
message: err.message
})
onDialogCancel()
}
}
// MOUNTED
onMounted(() => {
rerenderPage()
})
</script>

0 comments on commit a9784c3

Please sign in to comment.