11import AsyncSelect from "react-select/async" ;
2- import { React , useRef } from "react" ;
2+ import { React , useEffect , useRef , useState } from "react" ;
33import { useTranslation } from "react-i18next" ;
44import PropTypes from "prop-types" ;
55import { getHeaders , loadDropdownOptionsPromise } from "./poster-helper" ;
6+ import { MultiSelect } from "react-multi-select-component" ;
67
78/**
89 * @param {object } props The props.
@@ -27,47 +28,35 @@ function PosterSubscriptionCriteria({
2728} ) {
2829 const { t } = useTranslation ( "common" , { keyPrefix : "poster-selector-v2" } ) ;
2930
30- const locationTimeoutRef = useRef ( null ) ;
31- const organizationTimeoutRef = useRef ( null ) ;
32- const tagTimeoutRef = useRef ( null ) ;
33-
3431 // The user can choose between 1-10 entries to display.
3532 const numberOptions = Array . from ( Array ( 10 ) . keys ( ) ) ;
3633
37- const debounceOptions = ( inputValue , type ) => {
38- // Debounce promise.
39- return new Promise ( ( resolve , reject ) => {
40- let timeoutRef = null ;
34+ const [ locations , setLocations ] = useState ( [ ] ) ;
35+ const [ tags , setTags ] = useState ( [ ] ) ;
36+ const [ organizations , setOrganizations ] = useState ( [ ] ) ;
37+
38+ useEffect ( ( ) => {
39+ loadDropdownOptionsPromise ( optionsEndpoint , getHeaders ( ) , "" , "tags" ) . then (
40+ ( r ) => setTags ( r )
41+ ) ;
4142
42- switch ( type ) {
43- case "locations" :
44- timeoutRef = locationTimeoutRef ;
45- break ;
46- case "organizations" :
47- timeoutRef = organizationTimeoutRef ;
48- break ;
49- case "tags" :
50- timeoutRef = tagTimeoutRef ;
51- break ;
52- default :
53- return ;
54- }
43+ loadDropdownOptionsPromise (
44+ optionsEndpoint ,
45+ getHeaders ( ) ,
46+ "" ,
47+ "locations"
48+ ) . then ( ( r ) => setLocations ( r ) ) ;
5549
56- if ( timeoutRef . current ) {
57- clearTimeout ( timeoutRef . current ) ;
58- }
50+ loadDropdownOptionsPromise (
51+ optionsEndpoint ,
52+ getHeaders ( ) ,
53+ "" ,
54+ "organizations"
55+ ) . then ( ( r ) => setOrganizations ( r ) ) ;
56+ } , [ ] ) ;
5957
60- timeoutRef . current = setTimeout ( ( ) => {
61- loadDropdownOptionsPromise (
62- optionsEndpoint ,
63- getHeaders ( ) ,
64- inputValue ,
65- type
66- )
67- . then ( ( data ) => resolve ( data ) )
68- . catch ( ( reason ) => reject ( reason ) ) ;
69- } , 500 ) ;
70- } ) ;
58+ const changeData = ( field , newValue ) => {
59+ handleSelect ( field , newValue ) ;
7160 } ;
7261
7362 return (
@@ -76,25 +65,22 @@ function PosterSubscriptionCriteria({
7665 < div className = "mb-2" >
7766 < div className = "form-group" >
7867 < label
79- htmlFor = "os2display-poster-- select-subscription-places"
68+ htmlFor = "select-subscription-places"
8069 className = "form-label"
8170 >
8271 { t ( "filters-place" ) }
8372 </ label >
84- < AsyncSelect
73+ < MultiSelect
74+ isCreatable = { false }
8575 id = "subscription-search-place"
86- isClearable
87- isSearchable
88- defaultOptions
89- isMulti
90- placeholder = { t ( "single-search-placeholder" ) }
91- loadOptions = { ( inputValue ) =>
92- debounceOptions ( inputValue , "locations" )
93- }
94- value = { subscriptionPlaceValue }
95- onChange = { ( newValue ) => {
96- handleSelect ( "subscriptionPlaceValue" , newValue ) ;
97- } }
76+ label = { t ( "subscription-search-select" ) }
77+ name = "subscriptionPlaceValue"
78+ options = { locations }
79+ hasSelectAll = { false }
80+ onChange = { ( newValue ) => handleSelect ( 'subscriptionPlaceValue' , newValue ) }
81+ value = { subscriptionPlaceValue ?? [ ] }
82+ placeholder = { t ( "subscription-search-placeholder" ) }
83+ labelledBy = "select-subscription-places"
9884 />
9985 </ div >
10086 </ div >
@@ -107,20 +93,17 @@ function PosterSubscriptionCriteria({
10793 >
10894 { t ( "filters-organizer" ) }
10995 </ label >
110- < AsyncSelect
111- id = "subscription-search-place"
112- isClearable
113- isSearchable
114- defaultOptions
115- isMulti
116- placeholder = { t ( "single-search-placeholder" ) }
117- loadOptions = { ( inputValue ) =>
118- debounceOptions ( inputValue , "organizations" )
119- }
120- value = { subscriptionOrganizerValue }
121- onChange = { ( newValue ) => {
122- handleSelect ( "subscriptionOrganizerValue" , newValue ) ;
123- } }
96+ < MultiSelect
97+ isCreatable = { false }
98+ id = "subscription-search-organizer"
99+ label = { t ( "subscription-search-select" ) }
100+ name = "subscriptionOrganizerValue"
101+ options = { organizations }
102+ hasSelectAll = { false }
103+ onChange = { ( newValue ) => handleSelect ( 'subscriptionOrganizerValue' , newValue [ 0 ] ) }
104+ value = { subscriptionOrganizerValue ?? [ ] }
105+ placeholder = { t ( "subscription-search-placeholder" ) }
106+ labelledBy = "select-subscription-organizers"
124107 />
125108 </ div >
126109 </ div >
@@ -133,18 +116,17 @@ function PosterSubscriptionCriteria({
133116 >
134117 { t ( "filters-tag" ) }
135118 </ label >
136- < AsyncSelect
137- id = "subscription-search-tag"
138- isClearable
139- isSearchable
140- defaultOptions
141- isMulti
142- placeholder = { t ( "single-search-placeholder" ) }
143- loadOptions = { ( inputValue ) => debounceOptions ( inputValue , "tags" ) }
144- value = { subscriptionTagValue }
145- onChange = { ( newValue ) => {
146- handleSelect ( "subscriptionTagValue" , newValue ) ;
147- } }
119+ < MultiSelect
120+ isCreatable = { false }
121+ id = "subscription-search-tags"
122+ label = { t ( "subscription-search-select" ) }
123+ name = "subscriptionTagValue"
124+ options = { tags }
125+ hasSelectAll = { false }
126+ onChange = { ( newValue ) => handleSelect ( 'subscriptionTagValue' , newValue ) }
127+ value = { subscriptionTagValue ?? [ ] }
128+ placeholder = { t ( "subscription-search-placeholder" ) }
129+ labelledBy = "select-subscription-tags"
148130 />
149131 </ div >
150132 </ div >
0 commit comments