Implement post creation in a group

This commit is contained in:
Wolfgang Huß 2022-10-07 11:32:04 +02:00
parent a4cd7a8698
commit 7b9b253211
6 changed files with 94 additions and 16 deletions

View File

@ -99,6 +99,10 @@ export default {
type: Object, type: Object,
default: () => ({}), default: () => ({}),
}, },
groupId: {
type: String,
default: () => null,
},
}, },
data() { data() {
const { title, content, image, categories } = this.contribution const { title, content, image, categories } = this.contribution
@ -164,6 +168,14 @@ export default {
} }
} }
this.loading = true this.loading = true
// Wolle: console.log('variables: ', {
// title,
// content,
// categoryIds,
// id: this.contribution.id || null,
// image,
// groupId: this.groupId,
// })
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: this.contribution.id ? PostMutations().UpdatePost : PostMutations().CreatePost, mutation: this.contribution.id ? PostMutations().UpdatePost : PostMutations().CreatePost,
@ -173,6 +185,7 @@ export default {
categoryIds, categoryIds,
id: this.contribution.id || null, id: this.contribution.id || null,
image, image,
groupId: this.groupId,
}, },
}) })
.then(({ data }) => { .then(({ data }) => {

View File

@ -3,8 +3,20 @@ import gql from 'graphql-tag'
export default () => { export default () => {
return { return {
CreatePost: gql` CreatePost: gql`
mutation ($title: String!, $content: String!, $categoryIds: [ID], $image: ImageInput) { mutation (
CreatePost(title: $title, content: $content, categoryIds: $categoryIds, image: $image) { $title: String!
$content: String!
$categoryIds: [ID]
$image: ImageInput
$groupId: ID
) {
CreatePost(
title: $title
content: $content
categoryIds: $categoryIds
image: $image
groupId: $groupId
) {
title title
slug slug
content content
@ -23,14 +35,14 @@ export default () => {
$title: String! $title: String!
$content: String! $content: String!
$image: ImageInput $image: ImageInput
$categoryIds: [ID] $categoryIds: [ID] # Wolle: $groupId: ID
) { ) {
UpdatePost( UpdatePost(
id: $id id: $id
title: $title title: $title
content: $content content: $content
image: $image image: $image
categoryIds: $categoryIds categoryIds: $categoryIds # Wolle: groupId: $groupId
) { ) {
id id
title title

View File

@ -605,6 +605,12 @@
"submitted": "Kommentar gesendet", "submitted": "Kommentar gesendet",
"updated": "Änderungen gespeichert" "updated": "Änderungen gespeichert"
}, },
"createNewPost": {
"forGroup": {
"title": "Für die Gruppe „{name}“"
},
"title": "Erstelle einen neuen Beitrag"
},
"edited": "bearbeitet", "edited": "bearbeitet",
"menu": { "menu": {
"delete": "Beitrag löschen", "delete": "Beitrag löschen",

View File

@ -605,6 +605,12 @@
"submitted": "Comment submitted!", "submitted": "Comment submitted!",
"updated": "Changes saved!" "updated": "Changes saved!"
}, },
"createNewPost": {
"forGroup": {
"title": "For The Group “{name}”"
},
"title": "Create A New Post"
},
"edited": "edited", "edited": "edited",
"menu": { "menu": {
"delete": "Delete post", "delete": "Delete post",

View File

@ -249,10 +249,9 @@
</base-card> </base-card>
</ds-space> </ds-space>
<ds-space v-if="isGroupMemberNonePending" centered> <ds-space v-if="isGroupMemberNonePending" centered>
<nuxt-link :to="{ name: 'post-create' }"> <nuxt-link :to="{ name: 'post-create', query: { groupId: group.id } }">
<base-button <base-button
class="profile-post-add-button" class="profile-post-add-button"
:path="{ name: 'post-create' }"
icon="plus" icon="plus"
circle circle
filled filled
@ -370,8 +369,6 @@ export default {
// const filter = tabToFilterMapping({ tab: 'post', id: this.$route.params.id }) // const filter = tabToFilterMapping({ tab: 'post', id: this.$route.params.id })
return { return {
categoriesActive: this.$env.CATEGORIES_ACTIVE, categoriesActive: this.$env.CATEGORIES_ACTIVE,
Group: [],
GroupMembers: [],
loadGroupMembers: false, loadGroupMembers: false,
posts: [], posts: [],
// hasMore: true, // hasMore: true,

View File

@ -1,18 +1,62 @@
<template> <template>
<ds-flex :width="{ base: '100%' }" gutter="base"> <div>
<ds-flex-item :width="{ base: '100%', md: 5 }"> <ds-space margin="small">
<hc-contribution-form /> <ds-heading tag="h1">{{ $t('post.createNewPost.title') }}</ds-heading>
</ds-flex-item> <ds-heading v-if="group" tag="h2">
<ds-flex-item :width="{ base: '100%', md: 1 }">&nbsp;</ds-flex-item> {{ $t('post.createNewPost.forGroup.title', { name: group.name }) }}
</ds-flex> </ds-heading>
</ds-space>
<ds-space margin="large" />
<ds-flex :width="{ base: '100%' }" gutter="base">
<ds-flex-item :width="{ base: '100%', md: 5 }">
<contribution-form :groupId="groupId" />
</ds-flex-item>
<ds-flex-item :width="{ base: '100%', md: 1 }">&nbsp;</ds-flex-item>
</ds-flex>
</div>
</template> </template>
<script> <script>
import HcContributionForm from '~/components/ContributionForm/ContributionForm' import { groupQuery } from '~/graphql/groups'
import ContributionForm from '~/components/ContributionForm/ContributionForm'
export default { export default {
components: { components: {
HcContributionForm, ContributionForm,
},
data() {
const { groupId = null } = this.$route.query
// Wolle: console.log('groupId: ', groupId)
// Wolle: check if the user can post in this group. if not ?
return {
groupId,
}
},
computed: {
group() {
return this.Group && this.Group[0] ? this.Group[0] : null
},
},
apollo: {
Group: {
query() {
return groupQuery(this.$i18n)
},
variables() {
return {
id: this.groupId,
// followedByCount: this.followedByCount,
// followingCount: this.followingCount,
}
},
skip() {
return !this.groupId
},
error(error) {
this.$toast.error(error.message)
},
fetchPolicy: 'cache-and-network',
},
}, },
} }
</script> </script>