-
Notifications
You must be signed in to change notification settings - Fork 9
/
locations.ts
129 lines (110 loc) · 3.23 KB
/
locations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import API from "decentraland-gatsby/dist/utils/api/API"
import { EventTimeReference, EventType } from "../entities/Event/types"
import {
fromEventTime,
getEventTimeReference,
getEventType,
toEventTime,
} from "../entities/Event/utils"
import { ALL_EVENT_CATEGORY } from "../entities/EventCategory/types"
export enum EventView {
Attendees = "attendees",
}
export enum SubmitView {
Edit = "edit",
Clone = "clone",
}
export type EventFilters = {
search?: string | null
category?: string | null
type?: EventType
timeReference?: string | null
timeFrom?: number
timeTo?: number
}
export function toEventFilters(params: URLSearchParams): EventFilters {
const [timeFrom, timeTo] = fromEventTime(
params.get("time-from"),
params.get("time-to")
)
return {
search: params.get("search"),
category: params.get("category"),
type: getEventType(params.get("type")),
timeReference: getEventTimeReference(params.get("time-reference")),
timeFrom,
timeTo,
}
}
export function fromEventFilters(
filters: EventFilters,
params = new URLSearchParams()
): URLSearchParams {
if (filters.search) {
params.set("search", filters.search)
} else {
params.delete("search")
}
if (filters.category && filters.category != ALL_EVENT_CATEGORY) {
params.set("category", filters.category)
} else {
params.delete("category")
}
if (filters.type && filters.type !== EventType.All) {
params.set("type", filters.type)
} else {
params.delete("type")
}
if (
filters.timeReference &&
filters.timeReference !== EventTimeReference.ALL
) {
params.set("time-reference", filters.timeReference)
} else {
params.delete("time-reference")
}
if (Number.isFinite(filters.timeFrom) && Number.isFinite(filters.timeTo)) {
const [timeFrom, timeTo] = toEventTime(filters.timeFrom, filters.timeTo)
if (timeFrom !== "0000") {
params.set("time-from", timeFrom)
} else {
params.delete("time-from")
}
if (timeTo !== "2400") {
params.set("time-to", timeTo)
} else {
params.delete("time-to")
}
} else {
params.delete("time-from")
params.delete("time-to")
}
return params
}
export function url(
path: string,
query?: Record<string, string> | URLSearchParams
) {
return API.url("", path, query)
}
export default {
events: (filters: EventFilters = {}) => url("/", fromEventFilters(filters)),
event: (id: string) => url("/event/", { id }),
myEvents: () => url("/me/"),
pendingEvents: () => url("/pending/"),
schedule: (id: string) => url("/schedule/", { id }),
submitEvent: () => url("/submit/"),
editEvent: (event: string) =>
url("/submit/", { event, view: SubmitView.Edit }),
cloneEvent: (event: string) =>
url("/submit/", { event, view: SubmitView.Clone }),
schedules: () => url("/schedules/"),
submitSchedule: () => url("/submit/schedule/"),
editSchedule: (schedule: string) => url("/submit/schedule/", { schedule }),
// cloneSchedule: (shcedule: string) => url("/submit/", { shcedule, view: SubmitView.Clone }),
users: () => url("/users/"),
submitUser: () => url("/submit/user/"),
editUser: (user: string) => url("/submit/user/", { user }),
settings: () => url("/settings/"),
docs: () => url("/docs/"),
}