Add Editor, cancel/submit buttons for comments

- to PagesPost_id_slugIndex.vue
- handle simple comment creation using auto-generated resolver

Co-authored-by: Joseph "Kachulio" Ngugi <jngugi88@gmail.com>
This commit is contained in:
Matt Rider 2019-04-16 13:45:07 -03:00
parent f6eb5474d1
commit 674cdddfc3
2 changed files with 79 additions and 29 deletions

View File

@ -106,7 +106,8 @@
}, },
"takeAction": { "takeAction": {
"name": "Take action" "name": "Take action"
} },
"submitComment": "Submit Comment"
}, },
"quotes": { "quotes": {
"african": { "african": {

View File

@ -96,34 +96,67 @@
<ds-space margin="small" /> <ds-space margin="small" />
<!-- Comments --> <!-- Comments -->
<ds-section slot="footer"> <ds-section slot="footer">
<h3 style="margin-top: 0;"> <ds-flex>
<span> <ds-flex-item width="30%">
<ds-icon name="comments" /> <h3 style="margin-top: 0;">
<ds-tag <span>
v-if="post.comments" <ds-icon name="comments" />
style="margin-top: -4px; margin-left: -12px; position: absolute;" <ds-tag
color="primary" v-if="post.comments"
size="small" style="margin-top: -4px; margin-left: -12px; position: absolute;"
round color="primary"
>{{ post.commentsCount }}</ds-tag>&nbsp; Comments size="small"
</span> round
</h3> >{{ post.commentsCount }}</ds-tag>&nbsp; Comments
<ds-space margin-bottom="large" /> </span>
<div </h3>
v-if="post.comments" </ds-flex-item>
id="comments" <ds-flex-item width="70%">
class="comments" <no-ssr>
> <hc-editor
<comment v-model="value"
v-for="comment in post.comments" />
:key="comment.id" </no-ssr>
:comment="comment" <ds-flex>
<ds-flex-item>
<ds-button
:disabled="loading || disabled"
ghost
@click.prevent="$router.back()"
>
{{ $t('actions.cancel') }}
</ds-button>
</ds-flex-item>
<ds-flex-item>
<ds-button
type="submit"
:loading="loading"
:disabled="disabled || errors"
primary
@click="handleSubmit"
>
{{ $t('post.submitComment') }}
</ds-button>
</ds-flex-item>
</ds-flex>
</ds-flex-item>
<ds-space margin-bottom="large" />
<div
v-if="post.comments"
id="comments"
class="comments"
>
<comment
v-for="comment in post.comments"
:key="comment.id"
:comment="comment"
/>
</div>
<hc-empty
v-else
icon="messages"
/> />
</div> </ds-flex>
<hc-empty
v-else
icon="messages"
/>
</ds-section> </ds-section>
</ds-card> </ds-card>
</transition> </transition>
@ -139,6 +172,7 @@ import HcUser from '~/components/User'
import HcShoutButton from '~/components/ShoutButton.vue' import HcShoutButton from '~/components/ShoutButton.vue'
import HcEmpty from '~/components/Empty.vue' import HcEmpty from '~/components/Empty.vue'
import Comment from '~/components/Comment.vue' import Comment from '~/components/Comment.vue'
import HcEditor from '~/components/Editor/Editor.vue'
export default { export default {
transition: { transition: {
@ -152,7 +186,8 @@ export default {
HcShoutButton, HcShoutButton,
HcEmpty, HcEmpty,
Comment, Comment,
ContentMenu ContentMenu,
HcEditor
}, },
head() { head() {
return { return {
@ -278,6 +313,20 @@ export default {
methods: { methods: {
isAuthor(id) { isAuthor(id) {
return this.$store.getters['auth/user'].id === id return this.$store.getters['auth/user'].id === id
},
handleSubmit() {
this.$apollo.mutate({
mutation: gql`
mutation($content: String!) {
CreateComment(content: $content) {
content
}
}
`,
variables: {
content: this.value
}
})
} }
} }
} }