forked from potsda.mn/mobilizon
Extracting sorting modes into its own model
(cherry picked from commit da2ae333c9310645f2e8a08532ba032c00ed25c2) upstream PR is https://framagit.org/framasoft/mobilizon/-/merge_requests/1236
This commit is contained in:
parent
8e5093ab41
commit
03b2e1f634
19
js/src/types/sorting.model.ts
Normal file
19
js/src/types/sorting.model.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { EventSortField, SortDirection } from "./enums";
|
||||
|
||||
export interface ISorting {
|
||||
title: string;
|
||||
orderBy: EventSortField;
|
||||
direction: SortDirection;
|
||||
}
|
||||
|
||||
export class SortingUpcoming implements ISorting {
|
||||
title = "Upcoming Events";
|
||||
orderBy = EventSortField.BEGINS_ON;
|
||||
direction = SortDirection.ASC;
|
||||
}
|
||||
|
||||
export class SortingCreated implements ISorting {
|
||||
title = "Recently created Events";
|
||||
orderBy = EventSortField.INSERTED_AT;
|
||||
direction = SortDirection.DESC;
|
||||
}
|
|
@ -43,15 +43,7 @@
|
|||
>
|
||||
<section class="events-recent">
|
||||
<h2 class="title">
|
||||
{{
|
||||
$t(
|
||||
config &&
|
||||
config.instanceHomepageSorting ===
|
||||
InstanceHomepageSorting.UPCOMING
|
||||
? "Upcoming Events"
|
||||
: "Last published events"
|
||||
)
|
||||
}}
|
||||
{{ $t(this.sorting.title) }}
|
||||
</h2>
|
||||
<p>
|
||||
<i18n tag="span" path="On {instance} and other federated instances">
|
||||
|
@ -234,15 +226,7 @@
|
|||
/>
|
||||
<section class="events-recent">
|
||||
<h2 class="title">
|
||||
{{
|
||||
$t(
|
||||
config &&
|
||||
config.instanceHomepageSorting ===
|
||||
InstanceHomepageSorting.UPCOMING
|
||||
? "Upcoming Events"
|
||||
: "Last published events"
|
||||
)
|
||||
}}
|
||||
{{ $t(this.sorting.title) }}
|
||||
</h2>
|
||||
<p>
|
||||
<i18n tag="span" path="On {instance} and other federated instances">
|
||||
|
@ -274,12 +258,7 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Watch } from "vue-property-decorator";
|
||||
import {
|
||||
EventSortField,
|
||||
InstanceHomepageSorting,
|
||||
ParticipantRole,
|
||||
SortDirection,
|
||||
} from "@/types/enums";
|
||||
import { InstanceHomepageSorting, ParticipantRole } from "@/types/enums";
|
||||
import { Paginate } from "@/types/paginate";
|
||||
import { supportsWebPFormat } from "@/utils/support";
|
||||
import { IParticipant, Participant } from "../types/participant.model";
|
||||
|
@ -299,6 +278,11 @@ import RouteName from "../router/name";
|
|||
import { IEvent } from "../types/event.model";
|
||||
import DateComponent from "../components/Event/DateCalendarIcon.vue";
|
||||
import { CONFIG } from "../graphql/config";
|
||||
import {
|
||||
ISorting,
|
||||
SortingCreated,
|
||||
SortingUpcoming,
|
||||
} from "../types/sorting.model";
|
||||
import { IConfig } from "../types/config.model";
|
||||
import { IFollowedGroupEvent } from "../types/followedGroupEvent.model";
|
||||
import Subtitle from "../components/Utils/Subtitle.vue";
|
||||
|
@ -308,16 +292,7 @@ import Subtitle from "../components/Utils/Subtitle.vue";
|
|||
events: {
|
||||
query: FETCH_EVENTS,
|
||||
variables() {
|
||||
return this.config?.instanceHomepageSorting ===
|
||||
InstanceHomepageSorting.UPCOMING
|
||||
? {
|
||||
orderBy: EventSortField.BEGINS_ON,
|
||||
direction: SortDirection.ASC,
|
||||
}
|
||||
: {
|
||||
orderBy: EventSortField.INSERTED_AT,
|
||||
direction: SortDirection.DESC,
|
||||
};
|
||||
return this.sorting;
|
||||
},
|
||||
},
|
||||
currentActor: {
|
||||
|
@ -486,6 +461,15 @@ export default class Home extends Vue {
|
|||
);
|
||||
}
|
||||
|
||||
get sorting(): ISorting {
|
||||
switch (this.config?.instanceHomepageSorting) {
|
||||
case InstanceHomepageSorting.UPCOMING:
|
||||
return new SortingUpcoming();
|
||||
default:
|
||||
return new SortingCreated();
|
||||
}
|
||||
}
|
||||
|
||||
get thisWeekGoingToEvents(): IParticipant[] {
|
||||
const res = this.currentUserParticipations.filter(
|
||||
({ event, role }) =>
|
||||
|
|
Loading…
Reference in a new issue