mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Create Posts with a specified language, or fallback
This commit is contained in:
parent
14041ff396
commit
5986ab2070
@ -19,7 +19,7 @@ afterEach(async () => {
|
||||
describe('CreatePost', () => {
|
||||
const mutation = `
|
||||
mutation {
|
||||
CreatePost(title: "I am a title", content: "Some content") {
|
||||
CreatePost(title: "I am a title", content: "Some content", language: "en") {
|
||||
title
|
||||
content
|
||||
slug
|
||||
@ -74,6 +74,22 @@ describe('CreatePost', () => {
|
||||
await expect(client.request(mutation)).resolves.toMatchObject(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('language', () => {
|
||||
it('allows a user to set the language of the post', async () => {
|
||||
const createPostWithLanguageMutation = `
|
||||
mutation {
|
||||
CreatePost(title: "I am a title", content: "Some content", language: "en") {
|
||||
language
|
||||
}
|
||||
}
|
||||
`
|
||||
const expected = { CreatePost: { language: 'en' } }
|
||||
await expect(client.request(createPostWithLanguageMutation)).resolves.toEqual(
|
||||
expect.objectContaining(expected),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -15,29 +15,37 @@ type Post {
|
||||
disabledBy: User @relation(name: "DISABLED", direction: "IN")
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
|
||||
relatedContributions: [Post]! @cypher(
|
||||
statement: """
|
||||
language: String
|
||||
relatedContributions: [Post]!
|
||||
@cypher(
|
||||
statement: """
|
||||
MATCH (this)-[:TAGGED|CATEGORIZED]->(categoryOrTag)<-[:TAGGED|CATEGORIZED]-(post:Post)
|
||||
RETURN DISTINCT post
|
||||
LIMIT 10
|
||||
"""
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
tags: [Tag]! @relation(name: "TAGGED", direction: "OUT")
|
||||
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
|
||||
|
||||
comments: [Comment]! @relation(name: "COMMENTS", direction: "IN")
|
||||
commentsCount: Int! @cypher(statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)")
|
||||
commentsCount: Int!
|
||||
@cypher(
|
||||
statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)"
|
||||
)
|
||||
|
||||
shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN")
|
||||
shoutedCount: Int! @cypher(statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)")
|
||||
shoutedCount: Int!
|
||||
@cypher(
|
||||
statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)"
|
||||
)
|
||||
|
||||
# Has the currently logged in user shouted that post?
|
||||
shoutedByCurrentUser: Boolean! @cypher(
|
||||
statement: """
|
||||
shoutedByCurrentUser: Boolean!
|
||||
@cypher(
|
||||
statement: """
|
||||
MATCH (this)<-[:SHOUTED]-(u:User {id: $cypherParams.currentUserId})
|
||||
RETURN COUNT(u) >= 1
|
||||
"""
|
||||
)
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
@ -6,6 +6,12 @@
|
||||
<no-ssr>
|
||||
<hc-editor :users="users" :value="form.content" @input="updateEditorContent" />
|
||||
</no-ssr>
|
||||
<ds-select
|
||||
model="language"
|
||||
:options="form.languageOptions"
|
||||
icon="globe"
|
||||
:placeholder="locale"
|
||||
/>
|
||||
<div slot="footer" style="text-align: right">
|
||||
<ds-button :disabled="loading || disabled" ghost @click.prevent="$router.back()">
|
||||
{{ $t('actions.cancel') }}
|
||||
@ -28,6 +34,7 @@
|
||||
<script>
|
||||
import gql from 'graphql-tag'
|
||||
import HcEditor from '~/components/Editor'
|
||||
import orderBy from 'lodash/orderBy'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -41,6 +48,18 @@ export default {
|
||||
form: {
|
||||
title: '',
|
||||
content: '',
|
||||
language: null,
|
||||
locales: orderBy(process.env.locales, 'name'),
|
||||
languageOptions: [
|
||||
{
|
||||
label: 'Deutsch',
|
||||
value: 'de',
|
||||
},
|
||||
{
|
||||
label: 'English',
|
||||
value: 'en',
|
||||
},
|
||||
],
|
||||
},
|
||||
formSchema: {
|
||||
title: { required: true, min: 3, max: 64 },
|
||||
@ -67,11 +86,17 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
locale() {
|
||||
let locale
|
||||
locale = this.form.locales.find(this.returnLocaleName)
|
||||
return locale.name
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
const postMutations = require('~/graphql/PostMutations.js').default(this)
|
||||
this.loading = true
|
||||
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: this.id ? postMutations.UpdatePost : postMutations.CreatePost,
|
||||
@ -79,6 +104,7 @@ export default {
|
||||
id: this.id,
|
||||
title: this.form.title,
|
||||
content: this.form.content,
|
||||
language: this.form.language ? this.form.language.value : this.$i18n.locale(),
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
@ -103,6 +129,11 @@ export default {
|
||||
// this.form.content = value
|
||||
this.$refs.contributionForm.update('content', value)
|
||||
},
|
||||
returnLocaleName(locale) {
|
||||
if (this.$i18n.locale() === locale.code) {
|
||||
return locale
|
||||
}
|
||||
},
|
||||
},
|
||||
apollo: {
|
||||
User: {
|
||||
|
||||
@ -3,24 +3,26 @@ import gql from 'graphql-tag'
|
||||
export default app => {
|
||||
return {
|
||||
CreatePost: gql(`
|
||||
mutation($title: String!, $content: String!) {
|
||||
CreatePost(title: $title, content: $content) {
|
||||
mutation($title: String!, $content: String!, $language: String) {
|
||||
CreatePost(title: $title, content: $content, language: $language) {
|
||||
id
|
||||
title
|
||||
slug
|
||||
content
|
||||
contentExcerpt
|
||||
language
|
||||
}
|
||||
}
|
||||
`),
|
||||
UpdatePost: gql(`
|
||||
mutation($id: ID!, $title: String!, $content: String!) {
|
||||
UpdatePost(id: $id, title: $title, content: $content) {
|
||||
mutation($id: ID!, $title: String!, $content: String!, $language: String) {
|
||||
UpdatePost(id: $id, title: $title, content: $content, language: $language) {
|
||||
id
|
||||
title
|
||||
slug
|
||||
content
|
||||
contentExcerpt
|
||||
language
|
||||
}
|
||||
}
|
||||
`),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user