import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; import { defineMessages, intlShape } from 'react-intl'; import { Link } from 'react-router'; import SearchInput from '../../ui/SearchInput'; import Infobox from '../../ui/Infobox'; import RecipeItem from './RecipeItem'; import Loader from '../../ui/Loader'; import Appear from '../../ui/effects/Appear'; const messages = defineMessages({ headline: { id: 'settings.recipes.headline', defaultMessage: '!!!Available Services', }, mostPopularRecipes: { id: 'settings.recipes.mostPopular', defaultMessage: '!!!Most popular', }, allRecipes: { id: 'settings.recipes.all', defaultMessage: '!!!All services', }, devRecipes: { id: 'settings.recipes.dev', defaultMessage: '!!!Development', }, nothingFound: { id: 'settings.recipes.nothingFound', defaultMessage: '!!!Sorry, but no service matched your search term.', }, servicesSuccessfulAddedInfo: { id: 'settings.recipes.servicesSuccessfulAddedInfo', defaultMessage: '!!!Service successfully added', }, }); @observer export default class RecipesDashboard extends Component { static propTypes = { recipes: MobxPropTypes.arrayOrObservableArray.isRequired, isLoading: PropTypes.bool.isRequired, hasLoadedRecipes: PropTypes.bool.isRequired, showAddServiceInterface: PropTypes.func.isRequired, searchRecipes: PropTypes.func.isRequired, resetSearch: PropTypes.func.isRequired, serviceStatus: MobxPropTypes.arrayOrObservableArray.isRequired, devRecipesCount: PropTypes.number.isRequired, searchNeedle: PropTypes.string, }; static defaultProps = { searchNeedle: '', } static contextTypes = { intl: intlShape, }; render() { const { recipes, isLoading, hasLoadedRecipes, showAddServiceInterface, searchRecipes, resetSearch, serviceStatus, devRecipesCount, searchNeedle, } = this.props; const { intl } = this.context; return (
searchRecipes(e)} onReset={() => resetSearch()} throttle />
{serviceStatus.length > 0 && serviceStatus.includes('created') && ( {intl.formatMessage(messages.servicesSuccessfulAddedInfo)} )} {!searchNeedle && (
{intl.formatMessage(messages.mostPopularRecipes)} {intl.formatMessage(messages.allRecipes)} {devRecipesCount > 0 && ( {intl.formatMessage(messages.devRecipes)} ({devRecipesCount}) )}
)} {isLoading ? ( ) : (
{hasLoadedRecipes && recipes.length === 0 && (

{intl.formatMessage(messages.nothingFound)}

)} {recipes.map(recipe => ( showAddServiceInterface({ recipeId: recipe.id })} /> ))}
)}
); } }