edit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <!-- Finish handling of URL -->
  3. <div>
  4. <Header
  5. title="Write your blog"
  6. exitLink="/instructor/blogs">
  7. <!-- TODO: Check if blog status is active -->
  8. <template #actionMenu>
  9. <div class="full-page-takeover-header-button">
  10. <!-- TODO: Check blog validity before publishing -->
  11. <Modal
  12. @opened="checkBlogValidity"
  13. openTitle="Publish"
  14. openBtnClass="button is-success is-medium is-inverted is-outlined"
  15. title="Review Details">
  16. <div>
  17. <div class="title">Once you publish blog you cannot change url to a blog.</div>
  18. <!-- Check for error -->
  19. <div v-if="!publishError">
  20. <div class="subtitle">Current Url is:</div>
  21. <article class="message is-success">
  22. <div class="message-body">
  23. <!-- Get here actual slug -->
  24. <strong>some-slug</strong>
  25. </div>
  26. </article>
  27. </div>
  28. <article v-else class="message is-danger">
  29. <div class="message-body">
  30. {{publishError}}
  31. </div>
  32. </article>
  33. </div>
  34. </Modal>
  35. </div>
  36. </template>
  37. <!-- <template v-else #actionMenu>
  38. <div class="full-page-takeover-header-button">
  39. <Modal
  40. openTitle="Unpublish"
  41. openBtnClass="button is-success is-medium is-inverted is-outlined"
  42. title="Unpublish Blog">
  43. <div>
  44. <div class="title">Unpublish blog so it's no longer displayed in blogs page</div>
  45. </div>
  46. </Modal>
  47. </div>
  48. </template> -->
  49. </Header>
  50. <div class="blog-editor-container">
  51. <div class="container">
  52. <editor
  53. @editorMounted="initBlogContent"
  54. @editorUpdated="updateBlog"
  55. :isSaving="isSaving"
  56. ref="editor"
  57. />
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import Editor from '~/components/editor'
  64. import Header from '~/components/shared/Header'
  65. import Modal from '~/components/shared/Modal'
  66. import { mapState } from "vuex";
  67. export default {
  68. layout: 'instructor',
  69. components: {
  70. Editor, Header, Modal
  71. },
  72. data() {
  73. return {
  74. publishError: ''
  75. }
  76. },
  77. computed : {
  78. ...mapState({
  79. blog: ({instructor}) => instructor.blog.item,
  80. isSaving: ({instructor}) => instructor.blog.isSaving
  81. })
  82. },
  83. async fetch({params, store}){
  84. await store.dispatch('instructor/blog/fetchBlogById', params.id)
  85. },
  86. methods: {
  87. // initBlogContent(editor) {
  88. // if (this.blog && this.blog.content) {
  89. // editor.setContent(this.blog.content)
  90. // }
  91. // }
  92. initBlogContent(initContent) {
  93. if (this.blog && this.blog.content) {
  94. initContent(this.blog.content)
  95. }
  96. },
  97. async updateBlog(blogData) {
  98. try{
  99. if (!this.isSaving) {
  100. await this.$store.dispatch('instructor/blog/updateBlog', {data: blogData, id: this.blog._id})
  101. this.$toasted.success('Blog Updated!', {duration: 2000})
  102. }
  103. }catch(error){
  104. this.$toasted.error('Blog cannot be saved!', {duration: 2000})
  105. }
  106. },
  107. checkBlogValidity() {
  108. const title = this.$refs.editor.getNodeValueByName('title')
  109. this.publishError = ''
  110. if (title && title.length > 24) {
  111. // create slug from title
  112. } else {
  113. this.publishError = 'Cannot publish! Title needs to be longer than 24 characters!'
  114. }
  115. }
  116. }
  117. }
  118. </script>