import { Component } from 'react'; import { observer } from 'mobx-react'; import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; import { NavLink } from 'react-router-dom'; import withStyles, { WithStylesProps } from 'react-jss'; import { mdiOpenInNew } from '@mdi/js'; import Button from '../../ui/button'; import Input from '../../ui/input/index'; import { H1, H2, H3 } from '../../ui/headline'; 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'; import { FERDIUM_SERVICE_REQUEST } from '../../../config'; import RecipePreview from '../../../models/RecipePreview'; import Icon from '../../ui/icon'; const messages = defineMessages({ headline: { id: 'settings.recipes.headline', defaultMessage: 'Available services', }, searchService: { id: 'settings.searchService', defaultMessage: 'Search service', }, ferdiumPicksRecipes: { id: 'settings.recipes.ferdiumPicks', defaultMessage: 'Ferdium Picks', }, allRecipes: { id: 'settings.recipes.all', defaultMessage: 'All services', }, customRecipes: { id: 'settings.recipes.custom', defaultMessage: 'Custom Services', }, nothingFound: { id: 'settings.recipes.nothingFound', defaultMessage: 'Sorry, but no service matched your search term - but you can still probably add it using the "Custom Website" option. Please note that the website might show more services that have been added to Ferdium since the version that you are currently on. To get those new services, please consider upgrading to a newer version of Ferdium.', }, servicesSuccessfulAddedInfo: { id: 'settings.recipes.servicesSuccessfulAddedInfo', defaultMessage: 'Service successfully added', }, missingService: { id: 'settings.recipes.missingService', defaultMessage: 'Missing a service?', }, customRecipeIntro: { id: 'settings.recipes.customService.intro', defaultMessage: 'To add a custom service, copy the service recipe folder inside:', }, openFolder: { id: 'settings.recipes.customService.openFolder', defaultMessage: 'Open folder', }, openDevDocs: { id: 'settings.recipes.customService.openDevDocs', defaultMessage: 'Developer Documentation', }, headlineCustomRecipes: { id: 'settings.recipes.customService.headline.customRecipes', defaultMessage: 'Custom 3rd Party Recipes', }, headlineCommunityRecipes: { id: 'settings.recipes.customService.headline.communityRecipes', defaultMessage: 'Community 3rd Party Recipes', }, headlineDevRecipes: { id: 'settings.recipes.customService.headline.devRecipes', defaultMessage: 'Your Development Service Recipes', }, }); const styles = { devRecipeIntroContainer: { textAlign: 'center', width: '100%', height: 'auto', margin: [40, 0], }, path: { marginTop: 20, '& > div': { fontFamily: 'SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace', }, }, actionContainer: { '& button': { margin: [0, 10], }, }, devRecipeList: { marginTop: 20, height: 'auto', }, proBadge: { marginLeft: '10px !important', }, }; interface IProps extends WithStylesProps, WrappedComponentProps { recipes: RecipePreview[]; customWebsiteRecipe?: RecipePreview; isLoading: boolean; hasLoadedRecipes: boolean; showAddServiceInterface: (...args: any[]) => void; searchRecipes: (e: string | null) => void; resetSearch: () => void; serviceStatus: string[]; searchNeedle: string | null; recipeFilter?: string; recipeDirectory: string; openRecipeDirectory: () => void; openDevDocs: () => void; } interface IState { searchNeedle: string | null; recipeFilter: string; } @observer class RecipesDashboard extends Component { constructor(props: IProps) { super(props); } render() { const { recipes, customWebsiteRecipe, isLoading, hasLoadedRecipes, showAddServiceInterface, searchRecipes, resetSearch, serviceStatus = 'all', searchNeedle = '', recipeFilter, recipeDirectory, openRecipeDirectory, openDevDocs, classes, intl, } = this.props; const communityRecipes = recipes.filter(r => !r.isDevRecipe); const devRecipes = recipes.filter(r => r.isDevRecipe); return (

{intl.formatMessage(messages.headline)}

{serviceStatus.length > 0 && serviceStatus.includes('created') && ( {intl.formatMessage(messages.servicesSuccessfulAddedInfo)} )} searchRecipes(e)} onReset={() => resetSearch()} autoFocus throttle />
recipeFilter === 'featured' ? 'badge badge--primary' : 'badge' } onClick={() => resetSearch()} > {intl.formatMessage(messages.ferdiumPicksRecipes)} isActive && recipeFilter === 'all' ? 'badge badge--primary' : 'badge' } onClick={() => resetSearch()} > {intl.formatMessage(messages.allRecipes)} isActive && !searchNeedle ? 'badge badge--primary' : 'badge' } onClick={() => resetSearch()} > {intl.formatMessage(messages.customRecipes)} {intl.formatMessage(messages.missingService)}{' '}
{/* )} */} {isLoading ? ( ) : ( <> {recipeFilter === 'dev' && ( <>

{intl.formatMessage(messages.headlineCustomRecipes)}

{intl.formatMessage(messages.customRecipeIntro)}

)} {recipeFilter === 'dev' && communityRecipes.length > 0 && (

{intl.formatMessage(messages.headlineCommunityRecipes)}

)}
{communityRecipes.map(recipe => ( showAddServiceInterface({ recipeId: recipe.id }) } /> ))}
{hasLoadedRecipes && recipes.length === 0 && recipeFilter !== 'dev' && (
{customWebsiteRecipe && customWebsiteRecipe.id && ( showAddServiceInterface({ recipeId: customWebsiteRecipe.id, }) } /> )}

{intl.formatMessage(messages.nothingFound)}

)} {recipeFilter === 'dev' && devRecipes.length > 0 && (

{intl.formatMessage(messages.headlineDevRecipes)}

{devRecipes.map(recipe => ( showAddServiceInterface({ recipeId: recipe.id }) } /> ))}
)} )}
); } } export default injectIntl( withStyles(styles, { injectTheme: true })(RecipesDashboard), );