2015-06-03 10:04:21 +08:00
|
|
|
React = require 'react'
|
|
|
|
_ = require "underscore"
|
|
|
|
PackageSet = require './package-set'
|
2015-10-04 09:11:29 +08:00
|
|
|
PackagesStore = require './packages-store'
|
|
|
|
PluginsActions = require './plugins-actions'
|
2015-06-03 10:04:21 +08:00
|
|
|
{Spinner, EventedIFrame, Flexbox} = require 'nylas-component-kit'
|
|
|
|
classNames = require 'classnames'
|
|
|
|
|
|
|
|
class TabExplore extends React.Component
|
|
|
|
@displayName: 'TabExplore'
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
if @state.search.length
|
|
|
|
collectionPrefix = "Matching "
|
|
|
|
if @state.searchResults
|
|
|
|
collection = @state.searchResults
|
|
|
|
emptyText = "No results found."
|
|
|
|
else
|
|
|
|
collection = {packages: [], themes: []}
|
|
|
|
emptyText = "Loading results..."
|
|
|
|
else
|
|
|
|
collection = @state.featured
|
|
|
|
collectionPrefix = "Featured "
|
|
|
|
emptyText = null
|
|
|
|
|
|
|
|
<div className="explore">
|
|
|
|
<div className="inner">
|
|
|
|
<input
|
|
|
|
type="search"
|
|
|
|
value={@state.search}
|
|
|
|
onChange={@_onSearchChange }
|
|
|
|
placeholder="Search Packages and Themes"/>
|
|
|
|
<PackageSet
|
|
|
|
title="#{collectionPrefix} Themes"
|
|
|
|
emptyText={emptyText ? "There are no featured themes yet."}
|
|
|
|
packages={collection.themes} />
|
|
|
|
<PackageSet
|
|
|
|
title="#{collectionPrefix} Packages"
|
|
|
|
emptyText={emptyText ? "There are no featured packages yet."}
|
|
|
|
packages={collection.packages} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@_unsubscribers = []
|
2015-10-04 09:11:29 +08:00
|
|
|
@_unsubscribers.push PackagesStore.listen(@_onChange)
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
# Trigger a refresh of the featured packages
|
2015-10-04 09:11:29 +08:00
|
|
|
PluginsActions.refreshFeaturedPackages()
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
unsubscribe() for unsubscribe in @_unsubscribers
|
|
|
|
|
|
|
|
_getStateFromStores: =>
|
2015-10-04 09:11:29 +08:00
|
|
|
featured: PackagesStore.featured()
|
|
|
|
search: PackagesStore.globalSearchValue()
|
|
|
|
searchResults: PackagesStore.searchResults()
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
_onChange: =>
|
|
|
|
@setState(@_getStateFromStores())
|
|
|
|
|
|
|
|
_onSearchChange: (event) =>
|
2015-10-04 09:11:29 +08:00
|
|
|
PluginsActions.setGlobalSearchValue(event.target.value)
|
2015-06-03 10:04:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = TabExplore
|