Skip to content

Commit 91da90c

Browse files
committed
chore: remove useless extra code
1 parent df6b218 commit 91da90c

File tree

2 files changed

+38
-166
lines changed

2 files changed

+38
-166
lines changed

src/components/light-search-bar.js

Lines changed: 29 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -208,100 +208,36 @@ const LightSearchBar = () => {
208208
}
209209
const onChange = itemID => setValue(itemID)
210210

211-
if ((writing || itemSearchQuery.loading) && !empty)
212-
return (
213-
<StyledSelect
214-
id="items-search-bar"
215-
showSearch
216-
value={value}
217-
defaultActiveFirstOption={false}
218-
showArrow={false}
219-
filterOption={false}
220-
onSearch={onSearch}
221-
onChange={onChange}
222-
optionLabelProp="label"
223-
notFoundContent={null}
224-
placeholder={
225-
<>
226-
<FontAwesomeIcon icon="search" /> Search...
227-
</>
228-
}
229-
>
230-
<Select.Option key="1" label="Loading...">
231-
Loading...
232-
</Select.Option>
233-
</StyledSelect>
234-
)
235-
236-
if (!writing && options.length === 0 && !empty)
237-
return (
238-
<StyledSelect
239-
id="items-search-bar"
240-
showSearch
241-
value={value}
242-
defaultActiveFirstOption={false}
243-
showArrow={false}
244-
filterOption={false}
245-
onSearch={onSearch}
246-
onChange={onChange}
247-
optionLabelProp="label"
248-
notFoundContent={null}
249-
placeholder={
250-
<>
251-
<FontAwesomeIcon icon="search" /> Search...
252-
</>
253-
}
254-
>
255-
<Select.Option key="2" label="No results">
256-
No results
257-
</Select.Option>
258-
</StyledSelect>
259-
)
211+
const shownOptions = () => {
212+
if ((writing || itemSearchQuery.loading) && !empty)
213+
return <Select.Option key="Loading">Loading...</Select.Option>
214+
if (!writing && options.length === 0 && !empty)
215+
return <Select.Option key="NoResult">No results</Select.Option>
216+
if (empty) return []
217+
else return options
218+
}
260219

261-
if (!writing && options.length > 0)
262-
return (
263-
<StyledSelect
264-
id="items-search-bar"
265-
showSearch
266-
value={value}
267-
defaultActiveFirstOption={false}
268-
showArrow={false}
269-
filterOption={false}
270-
onSearch={onSearch}
271-
onChange={onChange}
272-
optionLabelProp="label"
273-
notFoundContent={null}
274-
placeholder={
275-
<>
276-
<FontAwesomeIcon icon="search" /> Search...
277-
</>
278-
}
279-
>
280-
{options}
281-
</StyledSelect>
282-
)
283-
else
284-
return (
285-
<StyledSelect
286-
id="items-search-bar"
287-
showSearch
288-
value={value}
289-
defaultActiveFirstOption={false}
290-
showArrow={false}
291-
filterOption={false}
292-
onSearch={onSearch}
293-
onChange={onChange}
294-
optionLabelProp="label"
295-
notFoundContent={null}
296-
placeholder={
297-
<>
298-
<FontAwesomeIcon icon="search" /> Search...
299-
</>
300-
}
301-
>
302-
{options}
303-
</StyledSelect>
304-
)
220+
return (
221+
<StyledSelect
222+
id="items-search-bar"
223+
showSearch
224+
value={value}
225+
defaultActiveFirstOption={false}
226+
showArrow={false}
227+
filterOption={false}
228+
onSearch={onSearch}
229+
onChange={onChange}
230+
optionLabelProp="label"
231+
notFoundContent={null}
232+
placeholder={
233+
<>
234+
<FontAwesomeIcon icon="search" /> Search...
235+
</>
236+
}
237+
>
238+
{shownOptions()}
239+
</StyledSelect>
240+
)
305241
}
306242

307243
export default LightSearchBar

src/components/search-bar.js

Lines changed: 9 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -300,78 +300,14 @@ const SearchBar = () => {
300300

301301
const onChange = useCallback(itemID => setValue(itemID), [])
302302

303-
if (writing && !empty)
304-
return (
305-
<StyledSelect
306-
id="items-search-bar"
307-
showSearch
308-
value={value}
309-
defaultActiveFirstOption={false}
310-
showArrow={false}
311-
filterOption={false}
312-
onSearch={onSearch}
313-
onChange={onChange}
314-
optionLabelProp="label"
315-
notFoundContent={null}
316-
placeholder={
317-
<>
318-
<FontAwesomeIcon icon="search" /> Search...
319-
</>
320-
}
321-
>
322-
<Select.Option key="1" label="Loading...">
323-
Loading...
324-
</Select.Option>
325-
</StyledSelect>
326-
)
327-
328-
if (!writing && options.length === 0 && !empty)
329-
return (
330-
<StyledSelect
331-
id="items-search-bar"
332-
showSearch
333-
value={value}
334-
defaultActiveFirstOption={false}
335-
showArrow={false}
336-
filterOption={false}
337-
onSearch={onSearch}
338-
onChange={onChange}
339-
optionLabelProp="label"
340-
notFoundContent={null}
341-
placeholder={
342-
<>
343-
<FontAwesomeIcon icon="search" /> Search...
344-
</>
345-
}
346-
>
347-
<Select.Option key="2" label="No results">
348-
No results
349-
</Select.Option>
350-
</StyledSelect>
351-
)
352-
353-
if (!writing && options.length > 0)
354-
return (
355-
<StyledSelect
356-
id="items-search-bar"
357-
showSearch
358-
value={value}
359-
defaultActiveFirstOption={false}
360-
showArrow={false}
361-
filterOption={false}
362-
onSearch={onSearch}
363-
onChange={onChange}
364-
optionLabelProp="label"
365-
notFoundContent={null}
366-
placeholder={
367-
<>
368-
<FontAwesomeIcon icon="search" /> Search...
369-
</>
370-
}
371-
>
372-
{options}
373-
</StyledSelect>
374-
)
303+
const shownOptions = () => {
304+
if (writing && !empty)
305+
return <Select.Option key="Loading">Loading...</Select.Option>
306+
if (!writing && options.length === 0 && !empty)
307+
return <Select.Option key="NoResult">No results</Select.Option>
308+
if (empty) return []
309+
else return options
310+
}
375311

376312
return (
377313
<StyledSelect
@@ -391,7 +327,7 @@ const SearchBar = () => {
391327
</>
392328
}
393329
>
394-
{options}
330+
{shownOptions()}
395331
</StyledSelect>
396332
)
397333
}

0 commit comments

Comments
 (0)