             search += (' ' + user.first_name + ' ' + user.last_name + ' ').toLowerCase()
     return search
 
-
+# Returns true if the project should be visible with the given filters selected
+project_is_in_filter = (project, hidden, deleted) ->
+    account_id = require('flux').flux.getStore('account').state.account_id
+    !!project.deleted == deleted and !!project.users[account_id].hide == hidden
 
 ProjectSelector = rclass
     getDefaultProps: ->
-        project_list      : undefined    # an array of projects (or undefined = loading...)
+        project_map       : undefined
         hidden            : false
         deleted           : false
         search            : ''

        </Grid>


ProjectController = rclass
    getDefaultProps: ->
        project_map : undefined    # an array of projects (or undefined = loading...)

    componentWillReceiveProps: (props) ->
        @update_project_list(props.project_map)

    update_project_list: (project_map) ->
        @project_list = (project for project_id, project of project_map)
        for p in @project_list
            p.hashtags = parse_project_tags(p)
            # also search string
            # and only do this to the projects that change -- use immutable js to know
        @project_list.sort (p0, p1) -> -misc.cmp(p0.last_edited, p1.last_edited)

    render: ->
        if not @props.project_map?
            # TODO
            return <div>Loading...</div>
        else
            if not @project_list?
                @update_project_list(@props.project_map)
            return <ProjectSelector project_list={@project_list} />

ProjectsPage = rclass
    render: ->
        <FluxComponent flux={flux} connectToStores = {'projects'}>
            <ProjectController />
        </FluxComponent>

React.render(<ProjectsPage />, document.getElementById("projects"))

        return true

    visible_projects: ->
        words = misc.split(@props.search.toLowerCase()).concat(k for k of @props.selected_hashtags[@filter()])
        return (project for project in @project_list() when project_is_in_filter(project, @props.hidden, @props.deleted) and @matches(project, words))

    toggle_hashtag: (tag) ->
        selected_hashtags = JSON.parse(JSON.stringify(@props.selected_hashtags))
