From aced4d039b5921bbae4ffe0786d95536edd6d363 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 1 Oct 2020 15:07:15 +0200 Subject: [PATCH] Fix posts and rework graphql errors Signed-off-by: Thomas Citharel --- js/src/components/Event/DateTimePicker.vue | 7 +- js/src/components/Post/PostElementItem.vue | 107 +++++ js/src/filters/datetime.ts | 14 +- js/src/graphql/post.ts | 17 + js/src/i18n/en_US.json | 5 +- js/src/i18n/fr_FR.json | 5 +- js/src/utils/image.ts | 2 +- js/src/views/Event/Edit.vue | 2 +- js/src/views/Event/Event.vue | 8 +- js/src/views/Posts/Edit.vue | 119 ++++- js/src/views/Posts/List.vue | 102 ++++- js/src/views/Posts/Post.vue | 48 +- js/src/views/User/Register.vue | 2 +- js/src/vue-apollo.ts | 1 + .../activity_stream/converter/post.ex | 5 +- lib/graphql/error.ex | 90 ++++ lib/graphql/helpers/error.ex | 45 -- lib/graphql/middleware/error_handler.ex | 21 + lib/graphql/resolvers/event.ex | 8 +- lib/graphql/resolvers/post.ex | 34 +- lib/graphql/resolvers/user.ex | 4 +- lib/graphql/schema.ex | 9 + lib/graphql/schema/actors/person.ex | 9 +- lib/graphql/schema/event.ex | 5 +- lib/graphql/schema/post.ex | 19 +- lib/graphql/schema/user.ex | 3 +- lib/mobilizon/posts/post.ex | 37 +- lib/mobilizon/posts/posts.ex | 9 +- priv/gettext/ar/LC_MESSAGES/default.po | 14 +- priv/gettext/ar/LC_MESSAGES/errors.po | 72 ++- priv/gettext/be/LC_MESSAGES/default.po | 14 +- priv/gettext/be/LC_MESSAGES/errors.po | 72 ++- priv/gettext/ca/LC_MESSAGES/default.po | 14 +- priv/gettext/ca/LC_MESSAGES/errors.po | 72 ++- priv/gettext/cs/LC_MESSAGES/default.po | 14 +- priv/gettext/cs/LC_MESSAGES/errors.po | 72 ++- priv/gettext/de/LC_MESSAGES/default.po | 14 +- priv/gettext/de/LC_MESSAGES/errors.po | 72 ++- priv/gettext/default.pot | 10 + priv/gettext/en/LC_MESSAGES/default.po | 14 +- priv/gettext/en/LC_MESSAGES/errors.po | 72 ++- priv/gettext/errors.pot | 72 ++- priv/gettext/es/LC_MESSAGES/default.po | 14 +- priv/gettext/es/LC_MESSAGES/errors.po | 72 ++- priv/gettext/fi/LC_MESSAGES/default.po | 14 +- priv/gettext/fi/LC_MESSAGES/errors.po | 72 ++- priv/gettext/fr/LC_MESSAGES/default.po | 412 +++++++++++++++--- priv/gettext/fr/LC_MESSAGES/errors.po | 74 ++-- priv/gettext/it/LC_MESSAGES/default.po | 14 +- priv/gettext/it/LC_MESSAGES/errors.po | 72 ++- priv/gettext/ja/LC_MESSAGES/default.po | 14 +- priv/gettext/ja/LC_MESSAGES/errors.po | 72 ++- priv/gettext/nl/LC_MESSAGES/default.po | 14 +- priv/gettext/nl/LC_MESSAGES/errors.po | 72 ++- priv/gettext/oc/LC_MESSAGES/default.po | 14 +- priv/gettext/oc/LC_MESSAGES/errors.po | 72 ++- priv/gettext/pl/LC_MESSAGES/default.po | 14 +- priv/gettext/pl/LC_MESSAGES/errors.po | 72 ++- priv/gettext/pt/LC_MESSAGES/default.po | 14 +- priv/gettext/pt/LC_MESSAGES/errors.po | 72 ++- priv/gettext/pt_BR/LC_MESSAGES/default.po | 14 +- priv/gettext/pt_BR/LC_MESSAGES/errors.po | 72 ++- priv/gettext/ru/LC_MESSAGES/default.po | 14 +- priv/gettext/ru/LC_MESSAGES/errors.po | 72 ++- priv/gettext/sv/LC_MESSAGES/default.po | 14 +- priv/gettext/sv/LC_MESSAGES/errors.po | 72 ++- test/graphql/resolvers/event_test.exs | 11 +- test/graphql/resolvers/post_test.exs | 12 +- test/graphql/resolvers/user_test.exs | 4 +- 69 files changed, 1795 insertions(+), 999 deletions(-) create mode 100644 js/src/components/Post/PostElementItem.vue create mode 100644 lib/graphql/error.ex delete mode 100644 lib/graphql/helpers/error.ex create mode 100644 lib/graphql/middleware/error_handler.ex diff --git a/js/src/components/Event/DateTimePicker.vue b/js/src/components/Event/DateTimePicker.vue index d20fac8eb..94cab473b 100644 --- a/js/src/components/Event/DateTimePicker.vue +++ b/js/src/components/Event/DateTimePicker.vue @@ -83,16 +83,16 @@ export default class DateTimePicker extends Vue { localeMonthNamesProxy = localeMonthNames(); @Watch("value") - updateValue() { + updateValue(): void { this.dateWithTime = this.value; } @Watch("dateWithTime") - updateDateWithTimeWatcher() { + updateDateWithTimeWatcher(): void { this.updateDateTime(); } - updateDateTime() { + updateDateTime(): void { /** * Returns the updated date * @@ -115,6 +115,7 @@ export default class DateTimePicker extends Vue { return null; } + // eslint-disable-next-line class-methods-use-this private datesAreOnSameDay(first: Date, second: Date): boolean { return ( first.getFullYear() === second.getFullYear() && diff --git a/js/src/components/Post/PostElementItem.vue b/js/src/components/Post/PostElementItem.vue new file mode 100644 index 000000000..6a76998c7 --- /dev/null +++ b/js/src/components/Post/PostElementItem.vue @@ -0,0 +1,107 @@ + + + diff --git a/js/src/filters/datetime.ts b/js/src/filters/datetime.ts index e470d21ee..b8056b44c 100644 --- a/js/src/filters/datetime.ts +++ b/js/src/filters/datetime.ts @@ -1,3 +1,5 @@ +import { DateTimeFormatOptions } from "vue-i18n"; + function parseDateTime(value: string): Date { return new Date(value); } @@ -16,19 +18,21 @@ function formatTimeString(value: string): string { } function formatDateTimeString(value: string, showTime = true): string { - const options = { - weekday: "long", + const options: DateTimeFormatOptions = { + weekday: undefined, year: "numeric", month: "long", day: "numeric", - hour: "numeric", - minute: "numeric", + hour: undefined, + minute: undefined, }; if (showTime) { + options.weekday = "long"; options.hour = "numeric"; options.minute = "numeric"; } - return parseDateTime(value).toLocaleTimeString(undefined, options); + const format = new Intl.DateTimeFormat(undefined, options); + return format.format(parseDateTime(value)); } export { formatDateString, formatTimeString, formatDateTimeString }; diff --git a/js/src/graphql/post.ts b/js/src/graphql/post.ts index 5f81570ff..5155eb9c8 100644 --- a/js/src/graphql/post.ts +++ b/js/src/graphql/post.ts @@ -34,6 +34,11 @@ export const POST_FRAGMENT = gql` tags { ...TagFragment } + picture { + id + url + name + } } ${TAG_FRAGMENT} `; @@ -48,6 +53,7 @@ export const POST_BASIC_FIELDS = gql` id preferredUsername name + domain avatar { url } @@ -56,6 +62,7 @@ export const POST_BASIC_FIELDS = gql` id preferredUsername name + domain avatar { url } @@ -64,6 +71,12 @@ export const POST_BASIC_FIELDS = gql` updatedAt publishAt draft + visibility + picture { + id + url + name + } } `; @@ -102,6 +115,7 @@ export const CREATE_POST = gql` $visibility: PostVisibility $draft: Boolean $tags: [String] + $picture: PictureInput ) { createPost( title: $title @@ -110,6 +124,7 @@ export const CREATE_POST = gql` visibility: $visibility draft: $draft tags: $tags + picture: $picture ) { ...PostFragment } @@ -126,6 +141,7 @@ export const UPDATE_POST = gql` $visibility: PostVisibility $draft: Boolean $tags: [String] + $picture: PictureInput ) { updatePost( id: $id @@ -135,6 +151,7 @@ export const UPDATE_POST = gql` visibility: $visibility draft: $draft tags: $tags + picture: $picture ) { ...PostFragment } diff --git a/js/src/i18n/en_US.json b/js/src/i18n/en_US.json index a379b32ee..2d74e9cee 100644 --- a/js/src/i18n/en_US.json +++ b/js/src/i18n/en_US.json @@ -779,5 +779,8 @@ "Error while reporting group {groupTitle}": "Error while reporting group {groupTitle}", "Reported group": "Reported group", "You can only get invited to groups right now.": "You can only get invited to groups right now.", - "Join group": "Join group" + "Join group": "Join group", + "Created by {username}": "Created by {username}", + "Accessible through link": "Accessible through link", + "Accessible only to members": "Accessible only to members" } diff --git a/js/src/i18n/fr_FR.json b/js/src/i18n/fr_FR.json index 3cd54e786..89b27dcf1 100644 --- a/js/src/i18n/fr_FR.json +++ b/js/src/i18n/fr_FR.json @@ -816,5 +816,8 @@ "Error while reporting group {groupTitle}": "Erreur lors du signalement du groupe {groupTitle}", "Reported group": "Groupe signalé", "You can only get invited to groups right now.": "Vous pouvez uniquement être invité aux groupes pour le moment.", - "Join group": "Rejoindre le groupe" + "Join group": "Rejoindre le groupe", + "Created by {username}": "Créé par {username}", + "Accessible through link": "Accessible uniquement par lien", + "Accessible only to members": "Accessible uniquement aux membres" } diff --git a/js/src/utils/image.ts b/js/src/utils/image.ts index dfbdfdd4d..3bbe5593f 100644 --- a/js/src/utils/image.ts +++ b/js/src/utils/image.ts @@ -1,6 +1,6 @@ import { IPicture } from "@/types/picture.model"; -export async function buildFileFromIPicture(obj: IPicture | null) { +export async function buildFileFromIPicture(obj: IPicture | null | undefined) { if (!obj) return null; const response = await fetch(obj.url); diff --git a/js/src/views/Event/Edit.vue b/js/src/views/Event/Edit.vue index 6dba218da..d55791315 100644 --- a/js/src/views/Event/Edit.vue +++ b/js/src/views/Event/Edit.vue @@ -335,6 +335,7 @@ section { diff --git a/js/src/views/Posts/Post.vue b/js/src/views/Posts/Post.vue index 04221e094..50663a539 100644 --- a/js/src/views/Posts/Post.vue +++ b/js/src/views/Posts/Post.vue @@ -14,6 +14,10 @@ >

{{ post.publishAt | formatDateTimeString }}

+ + + {{ $t("Accessible only to members", { group: post.attributedTo.name }) }} +

{{ $t("Draft") }} {{ $t("Edit") }}

+
@@ -41,12 +46,11 @@