From dcfe87116e65152436539decdad0ba7b6609e1ef Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 2 Nov 2022 11:38:14 +0100 Subject: [PATCH] Allow to view more than 10 drafts events on my events view Closes #993 Signed-off-by: Thomas Citharel --- js/src/graphql/actor.ts | 51 +++++----- js/src/types/current-user.model.ts | 2 +- js/src/views/Event/MyEventsView.vue | 146 +++++++++------------------- lib/graphql/schema/user.ex | 4 +- lib/mobilizon/events/events.ex | 6 +- 5 files changed, 78 insertions(+), 131 deletions(-) diff --git a/js/src/graphql/actor.ts b/js/src/graphql/actor.ts index de899ef21..3a1ec38d9 100644 --- a/js/src/graphql/actor.ts +++ b/js/src/graphql/actor.ts @@ -205,31 +205,34 @@ export const LOGGED_USER_DRAFTS = gql` loggedUser { id drafts(page: $page, limit: $limit) { - id - uuid - title - draft - picture { + total + elements { id - url - alt - } - beginsOn - status - visibility - attributedTo { - ...ActorFragment - } - organizerActor { - ...ActorFragment - } - participantStats { - going - notApproved - } - options { - maximumAttendeeCapacity - remainingAttendeeCapacity + uuid + title + draft + picture { + id + url + alt + } + beginsOn + status + visibility + attributedTo { + ...ActorFragment + } + organizerActor { + ...ActorFragment + } + participantStats { + going + notApproved + } + options { + maximumAttendeeCapacity + remainingAttendeeCapacity + } } } } diff --git a/js/src/types/current-user.model.ts b/js/src/types/current-user.model.ts index f2dda9ad2..4c4e57cd9 100644 --- a/js/src/types/current-user.model.ts +++ b/js/src/types/current-user.model.ts @@ -54,7 +54,7 @@ export interface IUser extends ICurrentUser { disabled: boolean; participations: Paginate; mediaSize: number; - drafts: IEvent[]; + drafts: Paginate; settings: IUserSettings; activitySettings: IActivitySetting[]; followedGroupEvents: Paginate; diff --git a/js/src/views/Event/MyEventsView.vue b/js/src/views/Event/MyEventsView.vue index ef1ab3295..286e73090 100644 --- a/js/src/views/Event/MyEventsView.vue +++ b/js/src/views/Event/MyEventsView.vue @@ -19,9 +19,9 @@ > -
+
{{ @@ -73,15 +73,31 @@ />
-
+
- +

{{ t("Drafts") }}

+ + +
- {{ month[0] }} +

{{ month[0] }}

@@ -209,10 +225,15 @@ import { import { useQuery } from "@vue/apollo-composable"; import { computed, inject, ref, defineAsyncComponent } from "vue"; import { IUser } from "@/types/current-user.model"; -import { booleanTransformer, useRouteQuery } from "vue-use-route-query"; +import { + booleanTransformer, + integerTransformer, + useRouteQuery, +} from "vue-use-route-query"; import { Locale } from "date-fns"; import { useI18n } from "vue-i18n"; import { useRestrictions } from "@/composition/apollo/config"; +import { useHead } from "@vueuse/head"; const EventParticipationCard = defineAsyncComponent( () => import("@/components/Event/EventParticipationCard.vue") @@ -253,8 +274,6 @@ const dateFilter = useRouteQuery("dateFilter", new Date(), { const hasMoreFutureParticipations = ref(true); const hasMorePastParticipations = ref(true); -// config: CONFIG - const { result: loggedUserUpcomingEventsResult, fetchMore: fetchMoreUpcomingEvents, @@ -277,10 +296,17 @@ const groupEvents = computed( .elements ?? [] ); +const LOGGED_USER_DRAFTS_LIMIT = 10; +const draftsPage = useRouteQuery("draftsPage", 1, integerTransformer); + const { result: draftsResult } = useQuery<{ loggedUser: Pick; -}>(LOGGED_USER_DRAFTS, () => ({ page: 1, limit: 10 })); -const drafts = computed(() => draftsResult.value?.loggedUser.drafts ?? []); +}>( + LOGGED_USER_DRAFTS, + () => ({ page: draftsPage.value, limit: LOGGED_USER_DRAFTS_LIMIT }), + () => ({ fetchPolicy: "cache-and-network" }) +); +const drafts = computed(() => draftsResult.value?.loggedUser.drafts); const { result: participationsResult, fetchMore: fetchMoreParticipations } = useQuery<{ @@ -294,12 +320,6 @@ const pastParticipations = computed( } ); -// metaInfo() { -// return { -// title: this.t("My events") as string, -// }; -// }, - const monthlyEvents = ( elements: Eventable[], revertSort = false @@ -413,86 +433,8 @@ const dateFnsLocale = inject("dateFnsLocale"); const firstDayOfWeek = computed((): number => { return dateFnsLocale?.options?.weekStartsOn ?? 0; }); + +useHead({ + title: computed(() => t("My events")), +}); - - diff --git a/lib/graphql/schema/user.ex b/lib/graphql/schema/user.ex index 5a3aff7bd..ce139cf97 100644 --- a/lib/graphql/schema/user.ex +++ b/lib/graphql/schema/user.ex @@ -96,7 +96,9 @@ defmodule Mobilizon.GraphQL.Schema.UserType do resolve(&User.user_memberships/3) end - field(:drafts, list_of(:event), description: "The list of draft events this user has created") do + field(:drafts, :paginated_event_list, + description: "The list of draft events this user has created" + ) do arg(:page, :integer, default_value: 1, description: "The page in the paginated drafts events list" diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 95234053b..aedc9d394 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -465,13 +465,13 @@ defmodule Mobilizon.Events do |> Page.build_page(page, limit) end - @spec list_drafts_for_user(integer, integer | nil, integer | nil) :: [Event.t()] + @spec list_drafts_for_user(integer, integer | nil, integer | nil) :: Page.t(Event.t()) def list_drafts_for_user(user_id, page \\ nil, limit \\ nil) do Event |> user_events_query(user_id) |> filter_draft(true) - |> Page.paginate(page, limit) - |> Repo.all() + |> order_by(desc: :updated_at) + |> Page.build_page(page, limit) end @spec is_user_moderator_for_event?(integer | String.t(), integer | String.t()) :: boolean