Skip to content

Commit

Permalink
revert back to useState
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Aug 7, 2024
1 parent be09e4a commit 0863241
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Button, FormField, Grid, Select } from 'grommet'
import { observer } from 'mobx-react'
import PropTypes from 'prop-types'
import { useTranslation } from 'next-i18next'
import { useRef } from 'react'
import { useState } from 'react'

/*
Tune this value to determine when a search term
Expand All @@ -19,7 +19,7 @@ function SelectCollection ({
selected = {},
userID = ''
}) {
const searchText = useRef('')
const [searchText, setSearchText] = useState('')
const { t } = useTranslation('components')

const dropProps = {
Expand All @@ -31,19 +31,20 @@ function SelectCollection ({
For shorter strings, we request all your collections then filter the display names.
*/

function onTextChange(text) {
async function onTextChange(text) {
const search = text.trim()
onSearch({
await onSearch({
favorite: false,
current_user_roles: 'owner,collaborator,contributor',
search: search.length > MIN_SEARCH_LENGTH ? search : undefined
})
searchText.current = search
setSearchText(search)
}

function collectionNameFilter(collection) {
console.log(collection.display_name, searchText)
const displayNameLowerCase = collection.display_name.toLowerCase()
return displayNameLowerCase.includes(searchText.current.toLowerCase())
return displayNameLowerCase.includes(searchText.toLowerCase())
}

function collectionLabel(collection) {
Expand All @@ -56,7 +57,7 @@ function SelectCollection ({
/*
If the search text is long enough, use fuzzy full-text search. Otherwise, filter collections by display name.
*/
const options = searchText.current.length > MIN_SEARCH_LENGTH
const options = searchText.length > MIN_SEARCH_LENGTH
? collections
: collections.filter(collectionNameFilter)

Expand Down

0 comments on commit 0863241

Please sign in to comment.