|
1 | | -import {React, useEffect, useRef, useState} from "react"; |
| 1 | +import { React, useEffect, useRef, useState } from "react"; |
2 | 2 | import PropTypes from "prop-types"; |
3 | 3 | import { useTranslation } from "react-i18next"; |
4 | 4 | import { Row, Spinner } from "react-bootstrap"; |
5 | 5 | import AsyncSelect from "react-select/async"; |
6 | 6 | import Col from "react-bootstrap/Col"; |
7 | | -import {formatDate, getHeaders, loadDropdownOptions, loadDropdownOptionsPromise} from "./poster-helper"; |
| 7 | +import { |
| 8 | + formatDate, |
| 9 | + getHeaders, |
| 10 | + loadDropdownOptionsPromise, |
| 11 | +} from "./poster-helper"; |
8 | 12 |
|
9 | 13 | /** |
10 | 14 | * @param {object} props Props. |
@@ -38,7 +42,7 @@ function PosterSubscription({ |
38 | 42 |
|
39 | 43 | const [loadingResults, setLoadingResults] = useState(false); |
40 | 44 |
|
41 | | - const searchEndpoint = feedSource.admin[0].endpointSearch ?? null; |
| 45 | + const optionsEndpoint = feedSource.admin[0].endpointOption ?? null; |
42 | 46 |
|
43 | 47 | const numberOptions = Array.from(Array(10).keys()); |
44 | 48 |
|
@@ -133,18 +137,36 @@ function PosterSubscription({ |
133 | 137 | subscriptionNumberValue, |
134 | 138 | ]); |
135 | 139 |
|
136 | | - const timeoutRef = useRef(null); |
| 140 | + const locationTimeoutRef = useRef(null); |
| 141 | + const organizationTimeoutRef = useRef(null); |
| 142 | + const tagTimeoutRef = useRef(null); |
137 | 143 |
|
138 | 144 | const debounceOptions = (inputValue, type) => { |
139 | 145 | // Debounce promise. |
140 | 146 | return new Promise((resolve, reject) => { |
| 147 | + let timeoutRef = null; |
| 148 | + |
| 149 | + switch (type) { |
| 150 | + case "locations": |
| 151 | + timeoutRef = locationTimeoutRef; |
| 152 | + break; |
| 153 | + case "organizations": |
| 154 | + timeoutRef = organizationTimeoutRef; |
| 155 | + break; |
| 156 | + case "tags": |
| 157 | + timeoutRef = tagTimeoutRef; |
| 158 | + break; |
| 159 | + default: |
| 160 | + return; |
| 161 | + } |
| 162 | + |
141 | 163 | if (timeoutRef.current) { |
142 | 164 | clearTimeout(timeoutRef.current); |
143 | 165 | } |
144 | 166 |
|
145 | 167 | timeoutRef.current = setTimeout(() => { |
146 | 168 | loadDropdownOptionsPromise( |
147 | | - searchEndpoint, |
| 169 | + optionsEndpoint, |
148 | 170 | getHeaders(), |
149 | 171 | inputValue, |
150 | 172 | type |
@@ -214,7 +236,7 @@ function PosterSubscription({ |
214 | 236 | {t("filters-tag")} |
215 | 237 | </label> |
216 | 238 | <AsyncSelect |
217 | | - id="subscription-search-place" |
| 239 | + id="subscription-search-tag" |
218 | 240 | isClearable |
219 | 241 | isSearchable |
220 | 242 | defaultOptions |
@@ -287,12 +309,12 @@ function PosterSubscription({ |
287 | 309 | /> |
288 | 310 | </td> |
289 | 311 | <td> |
290 | | - <strong>{event.name}</strong> |
| 312 | + <strong>{event.title}</strong> |
291 | 313 | <br /> |
292 | 314 | {event?.organizer?.name} |
293 | 315 | </td> |
294 | 316 | <td> |
295 | | - {firstOccurrence && firstOccurrence.place?.name} |
| 317 | + {firstOccurrence && firstOccurrence?.place?.name} |
296 | 318 | </td> |
297 | 319 | <td> |
298 | 320 | {firstOccurrence && ( |
@@ -324,6 +346,7 @@ PosterSubscription.propTypes = { |
324 | 346 | admin: PropTypes.arrayOf( |
325 | 347 | PropTypes.shape({ |
326 | 348 | endpointEntity: PropTypes.string, |
| 349 | + endpointOption: PropTypes.string, |
327 | 350 | endpointSearch: PropTypes.string, |
328 | 351 | }) |
329 | 352 | ), |
|
0 commit comments