2020-02-18 07:57:00 +00:00
|
|
|
<template>
|
|
|
|
<section class="section container">
|
2020-06-26 10:08:07 +00:00
|
|
|
<h1>{{ $t("Create a discussion") }}</h1>
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
<form @submit.prevent="createDiscussion">
|
2020-02-18 07:57:00 +00:00
|
|
|
<b-field :label="$t('Title')">
|
2020-07-09 15:24:28 +00:00
|
|
|
<b-input aria-required="true" required v-model="discussion.title" />
|
2020-02-18 07:57:00 +00:00
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<b-field :label="$t('Text')">
|
2020-07-09 15:24:28 +00:00
|
|
|
<editor v-model="discussion.text" />
|
2020-02-18 07:57:00 +00:00
|
|
|
</b-field>
|
|
|
|
|
2020-06-26 10:08:07 +00:00
|
|
|
<button class="button is-primary" type="submit">{{ $t("Create the discussion") }}</button>
|
2020-02-18 07:57:00 +00:00
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
|
|
|
import { IGroup, IPerson } from "@/types/actor";
|
2020-08-14 09:32:23 +00:00
|
|
|
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
|
|
|
import { FETCH_GROUP } from "@/graphql/group";
|
2020-07-09 15:24:28 +00:00
|
|
|
import { CREATE_DISCUSSION } from "@/graphql/discussion";
|
2020-02-18 07:57:00 +00:00
|
|
|
import RouteName from "../../router/name";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
editor: () => import(/* webpackChunkName: "editor" */ "@/components/Editor.vue"),
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
group: {
|
|
|
|
query: FETCH_GROUP,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
name: this.preferredUsername,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.preferredUsername;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-09 15:24:28 +00:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
title: this.$t("Create a discussion") as string,
|
|
|
|
// all titles will be injected into this template
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
|
|
|
};
|
|
|
|
},
|
2020-02-18 07:57:00 +00:00
|
|
|
})
|
2020-07-09 15:24:28 +00:00
|
|
|
export default class CreateDiscussion extends Vue {
|
2020-02-18 07:57:00 +00:00
|
|
|
@Prop({ type: String, required: true }) preferredUsername!: string;
|
|
|
|
|
|
|
|
group!: IGroup;
|
|
|
|
|
|
|
|
currentActor!: IPerson;
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
discussion = { title: "", text: "" };
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
async createDiscussion() {
|
2020-02-18 07:57:00 +00:00
|
|
|
try {
|
|
|
|
const { data } = await this.$apollo.mutate({
|
2020-07-09 15:24:28 +00:00
|
|
|
mutation: CREATE_DISCUSSION,
|
2020-02-18 07:57:00 +00:00
|
|
|
variables: {
|
2020-07-09 15:24:28 +00:00
|
|
|
title: this.discussion.title,
|
|
|
|
text: this.discussion.text,
|
2020-02-18 07:57:00 +00:00
|
|
|
actorId: this.group.id,
|
|
|
|
creatorId: this.currentActor.id,
|
|
|
|
},
|
2020-07-09 15:24:28 +00:00
|
|
|
// update: (store, { data: { createDiscussion } }) => {
|
2020-02-18 07:57:00 +00:00
|
|
|
// // TODO: update group list cache
|
|
|
|
// },
|
|
|
|
});
|
|
|
|
|
|
|
|
await this.$router.push({
|
2020-07-09 15:24:28 +00:00
|
|
|
name: RouteName.DISCUSSION,
|
2020-02-18 07:57:00 +00:00
|
|
|
params: {
|
2020-07-09 15:24:28 +00:00
|
|
|
id: data.createDiscussion.id,
|
|
|
|
slug: data.createDiscussion.slug,
|
2020-02-18 07:57:00 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.markdown-render h1 {
|
|
|
|
font-size: 2em;
|
|
|
|
}
|
|
|
|
</style>
|