                     filename    : filename
                     description : context
 
-            if num_results >= max_output
+            if num_results >= max_results
                 break
 
-        flux.getActions('project_search').setTo(search_results : search_results)
+        project_store.getActions(@props.project_id, flux).setTo
+            too_many_results : too_many_results
+            search_results   : search_results
 
 
 
     output_heading : ->
-        switch @state.state
-            when 'loading', 'display'
-                <ProjectSearchOutputHeading
-                    path         = {@props.current_path}
-                    show_command = {@props.show_command}}
-                    command      = {@props.command}
-                    user_input   = {@props.user_input} />
+        if @props.most_recent_search? and @props.most_recent_path?
+            <ProjectSearchOutputHeading
+                most_recent_path   = {@props.most_recent_path}
+                command            = {@props.command}
+                most_recent_search = {@props.most_recent_search}
+                search_results     = {@props.search_results}
+                search_error       = {@props.search_error} />
 
     output : ->
-        switch @state.state
-            when 'display'
-                console.log(@props.search_results)
-                <ProjectSearchOutput
-                    results   = {@props.search_results}
-                    too_many_results = {@props.too_many_results} />
-            when 'loading'
-                <Loading />
+        if @props.search_results? or @props.search_error?
+            <ProjectSearchOutput
+                project_id       = {@props.project_id}
+                results          = {@props.search_results}
+                too_many_results = {@props.too_many_results}
+                search_error     = {@props.search_error} />
+        else if @props.most_recent_search?
+            # a search has been made but the search_results or search_error hasn't come in yet
+            <Loading />
 
     render : ->
         <Well>
             <Row>
                 <Col sm=8>
-                    <ProjectSearchInput search_cb={@search} />
+                    <ProjectSearchInput search_cb={@search} project_id={@props.project_id} />
                     {@output_heading()}
                 </Col>
 
                 <Col sm=4>
                     <ProjectSearchSettings
+                        project_id     = {@props.project_id}
                         checkboxes     = {@settings_checkboxes}
                         case_sensitive = {@props.case_sensitive}
                         subdirectories = {@props.subdirectories}
-                        show_command   = {@props.show_command}
                         hidden_files   = {@props.hidden_files} />
                 </Col>
             </Row>

diffsync        = require('diffsync')
misc_page       = require('misc_page')
{salvus_client} = require('salvus_client')


# Define project search actions
class ProjectSearchActions extends Actions
    # NOTE: Can test causing this action by typing this in the Javascript console:
    #    require('flux').flux.getActions('project_search').setTo({search_query : "foo"})
    setTo: (settings) ->
        settings : settings

# Register project search actions
flux.createActions('project_search', ProjectSearchActions)

# Define project search store
class ProjectSearchStore extends Store
    constructor: (flux) ->
        super()
        ActionIds = flux.getActionIds('project_search')
        @register(ActionIds.setTo, @setTo)
        @state = {}

    setTo: (message) ->
        @setState(message.settings)

# Register project_search store
flux.createStore('project_search', ProjectSearchStore, flux)

ProjectSearchInput = rclass


        description : rtypes.string


    click_filename : (e) ->
        project_store.getActions(@props.project_id, flux).open_file(path:@props.filename, foreground:misc_page.open_in_foreground(e))

    render : ->
        <div style={wordWrap:'break-word'}>
            <NativeListener onClick={@click_filename}>
                <a href=""><strong>{@props.filename}</strong></a>
            </NativeListener>
            <span style={color:"#666"}> {@props.description}</span>
        </div>


render = (project_id, flux) ->
    store = project_store.getStore(project_id, flux)
    <div>
        <Row>
            <Col sm=12>
