2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<section class="section container">
|
2020-06-26 12:08:07 +02:00
|
|
|
<h1>{{ $t("Create a discussion") }}</h1>
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
<form @submit.prevent="createDiscussion">
|
2021-03-24 15:47:03 +01:00
|
|
|
<b-field
|
|
|
|
:label="$t('Title')"
|
|
|
|
:message="errors.title"
|
|
|
|
:type="errors.title ? 'is-danger' : undefined"
|
|
|
|
>
|
2020-07-09 17:24:28 +02:00
|
|
|
<b-input aria-required="true" required v-model="discussion.title" />
|
2020-02-18 08:57:00 +01:00
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<b-field :label="$t('Text')">
|
2020-07-09 17:24:28 +02:00
|
|
|
<editor v-model="discussion.text" />
|
2020-02-18 08:57:00 +01:00
|
|
|
</b-field>
|
|
|
|
|
2020-11-30 10:24:11 +01:00
|
|
|
<button class="button is-primary" type="submit">
|
|
|
|
{{ $t("Create the discussion") }}
|
|
|
|
</button>
|
2020-02-18 08:57:00 +01:00
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
|
|
|
import { IGroup, IPerson } from "@/types/actor";
|
2020-08-14 11:32:23 +02:00
|
|
|
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
|
|
|
import { FETCH_GROUP } from "@/graphql/group";
|
2020-07-09 17:24:28 +02:00
|
|
|
import { CREATE_DISCUSSION } from "@/graphql/discussion";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../../router/name";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
2020-11-30 10:24:11 +01:00
|
|
|
editor: () =>
|
|
|
|
import(/* webpackChunkName: "editor" */ "@/components/Editor.vue"),
|
2020-02-18 08:57:00 +01:00
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
group: {
|
|
|
|
query: FETCH_GROUP,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
name: this.preferredUsername,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.preferredUsername;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-09 17:24:28 +02:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: this.$t("Create a discussion") as string,
|
|
|
|
};
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
})
|
2020-07-09 17:24:28 +02:00
|
|
|
export default class CreateDiscussion extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Prop({ type: String, required: true }) preferredUsername!: string;
|
|
|
|
|
|
|
|
group!: IGroup;
|
|
|
|
|
|
|
|
currentActor!: IPerson;
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
discussion = { title: "", text: "" };
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-03-24 15:47:03 +01:00
|
|
|
errors = { title: "" };
|
|
|
|
|
2020-10-22 08:40:17 +02:00
|
|
|
async createDiscussion(): Promise<void> {
|
2021-03-24 15:47:03 +01:00
|
|
|
this.errors = { title: "" };
|
2020-02-18 08:57:00 +01:00
|
|
|
try {
|
2020-11-06 11:34:32 +01:00
|
|
|
if (!this.group.id || !this.currentActor.id) return;
|
2020-02-18 08:57:00 +01:00
|
|
|
const { data } = await this.$apollo.mutate({
|
2020-07-09 17:24:28 +02:00
|
|
|
mutation: CREATE_DISCUSSION,
|
2020-02-18 08:57:00 +01:00
|
|
|
variables: {
|
2020-07-09 17:24:28 +02:00
|
|
|
title: this.discussion.title,
|
|
|
|
text: this.discussion.text,
|
2020-11-06 11:34:32 +01:00
|
|
|
actorId: parseInt(this.group.id, 10),
|
2020-02-18 08:57:00 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await this.$router.push({
|
2020-07-09 17:24:28 +02:00
|
|
|
name: RouteName.DISCUSSION,
|
2020-02-18 08:57:00 +01:00
|
|
|
params: {
|
2020-07-09 17:24:28 +02:00
|
|
|
id: data.createDiscussion.id,
|
|
|
|
slug: data.createDiscussion.slug,
|
2020-02-18 08:57:00 +01:00
|
|
|
},
|
|
|
|
});
|
2020-10-22 08:40:17 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
2021-03-24 15:47:03 +01:00
|
|
|
if (error.graphQLErrors[0].field == "title") {
|
|
|
|
this.errors.title = error.graphQLErrors[0].message;
|
|
|
|
} else {
|
|
|
|
this.$notifier.error(error.graphQLErrors[0].message);
|
|
|
|
}
|
2020-10-22 08:40:17 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.markdown-render h1 {
|
|
|
|
font-size: 2em;
|
|
|
|
}
|
|
|
|
</style>
|