1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-22 07:52:43 +00:00

Fix lasts events published order on the homepage

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-16 19:08:00 +01:00
parent c8e39313ef
commit 4ff00e92b6
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
5 changed files with 42 additions and 5 deletions

View file

@ -193,8 +193,8 @@ export const FETCH_EVENT_BASIC = gql`
`;
export const FETCH_EVENTS = gql`
query {
events {
query FetchEvents($orderBy: EventOrderBy, $direction: SortDirection) {
events(orderBy: $orderBy, direction: $direction) {
total
elements {
id

View file

@ -239,3 +239,14 @@ export enum ActivityGroupSubject {
GROUP_CREATED = "group_created",
GROUP_UPDATED = "group_updated",
}
export enum EventSortField {
BEGINS_ON = "BEGINS_ON",
INSERTED_AT = "INSERTED_AT",
UPDATED_AT = "UPDATED_AT",
}
export enum SortDirection {
ASC = "ASC",
DESC = "DESC",
}

View file

@ -320,7 +320,7 @@
<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
import { ParticipantRole } from "@/types/enums";
import { EventSortField, ParticipantRole, SortDirection } from "@/types/enums";
import { Paginate } from "@/types/paginate";
import { supportsWebPFormat } from "@/utils/support";
import { IParticipant, Participant } from "../types/participant.model";
@ -347,6 +347,10 @@ import Subtitle from "../components/Utils/Subtitle.vue";
events: {
query: FETCH_EVENTS,
fetchPolicy: "no-cache", // Debug me: https://github.com/apollographql/apollo-client/issues/3030
variables: {
orderBy: EventSortField.INSERTED_AT,
direction: SortDirection.DESC,
},
},
currentActor: {
query: CURRENT_ACTOR_CLIENT,

View file

@ -59,9 +59,13 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
end
end
def list_events(_parent, %{page: page, limit: limit}, _resolution)
def list_events(
_parent,
%{page: page, limit: limit, order_by: order_by, direction: direction},
_resolution
)
when limit < @event_max_limit do
{:ok, Events.list_events(page, limit)}
{:ok, Events.list_events(page, limit, order_by, direction)}
end
def list_events(_parent, %{page: _page, limit: _limit}, _resolution) do

View file

@ -297,11 +297,29 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
field(:id, :string, description: "The Contact Actor ID")
end
@desc "Available event sort fields"
enum :event_order_by do
value(:begins_on, description: "Sort by the date the event starts")
value(:inserted_at, description: "Sort by the date the event was created")
value(:updated_at, description: "Sort by the date the event was updated")
end
object :event_queries do
@desc "Get all events"
field :events, :paginated_event_list do
arg(:page, :integer, default_value: 1, description: "The page in the paginated event list")
arg(:limit, :integer, default_value: 10, description: "The limit of events per page")
arg(:order_by, :event_order_by,
default_value: :begins_on,
description: "Order the list of events by field"
)
arg(:direction, :sort_direction,
default_value: :asc,
description: "Direction for the sort"
)
resolve(&Event.list_events/3)
end