Skip to content

Commit

Permalink
✨ enhance search for proposal by title and speaker (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
corinnekrych authored and bpetetot committed Feb 14, 2019
1 parent 5cf2d95 commit 3add185
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 1 addition & 9 deletions src/firebase/proposals.js
@@ -1,7 +1,5 @@
import firebase from 'firebase/app'
import omit from 'lodash/omit'
import toLower from 'lodash/toLower'
import deburr from 'lodash/deburr'

/**
* Return the proposal with the given id
Expand All @@ -25,7 +23,7 @@ export const fetchEventProposals = async (
eventId,
uid,
{
categories, formats, state, sortOrder, ratings, search,
categories, formats, state, sortOrder, ratings,
} = {},
) => {
let query = firebase
Expand Down Expand Up @@ -60,12 +58,6 @@ export const fetchEventProposals = async (
const result = await query.get()
let proposals = result.docs.map(ref => ({ id: ref.id, ...ref.data() }))

// add search by title (client filter)
if (search) {
const searchQuery = deburr(toLower(search))
proposals = proposals.filter(proposal => deburr(toLower(proposal.title)).includes(searchQuery))
}

// add ratings filter (client filter)
if (ratings === 'rated') {
proposals = proposals.filter(proposal => proposal.usersRatings && !!proposal.usersRatings[uid])
Expand Down
11 changes: 10 additions & 1 deletion src/screens/organizer/proposals/proposals.reactions.js
Expand Up @@ -5,6 +5,8 @@ import over from 'lodash/fp/over'
import pick from 'lodash/fp/pick'
import update from 'lodash/fp/update'
import pickBy from 'lodash/fp/pickBy'
import toLower from 'lodash/toLower'
import deburr from 'lodash/deburr'

import * as firebase from 'firebase/proposals'
import userCrud from 'firebase/user'
Expand Down Expand Up @@ -48,7 +50,7 @@ export const loadProposals = async (action, store, { router }) => {

const filters = store.ui.organizer.proposals.get()
const proposals = await firebase.fetchEventProposals(eventId, uid, filters)
const props = await Promise.all(proposals.map(async (proposal) => {
let props = await Promise.all(proposals.map(async (proposal) => {
const prop = { ...proposal }
const speakerList = Object.keys(prop.speakers)
const speakerNameList = await Promise.all(speakerList.map(async (speakerUid) => {
Expand All @@ -63,6 +65,13 @@ export const loadProposals = async (action, store, { router }) => {
prop.speakerName = speakerNameList.join(' & ')
return prop
}))
// Cross-fields search better handled in UI than firebase
const { search } = filters
if (search) {
const searchQuery = deburr(toLower(search))
props = props.filter(proposal => deburr(toLower(proposal.title)).includes(searchQuery)
|| deburr(toLower(proposal.speakerName)).includes(searchQuery))
}
store.data.proposals.set(props)
}

Expand Down
Expand Up @@ -59,7 +59,7 @@ class ProposalToolbar extends Component {
<input
id="search"
type="search"
placeholder="Search by proposal title"
placeholder="Search by title or speaker"
onChange={this.debounceOnChange}
defaultValue={filters.search}
/>
Expand Down

0 comments on commit 3add185

Please sign in to comment.