Skip to content

Commit

Permalink
Add recipes search bundle, and wire into recipes search UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Apr 25, 2024
1 parent 621722f commit b652941
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
27 changes: 27 additions & 0 deletions fronts-client/src/bundles/recipesBundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import createAsyncResourceBundle from 'lib/createAsyncResourceBundle';
import { Recipe } from 'types/Recipe';

type RecipesState = Recipe[];

export const { actions, reducer, selectors } =
createAsyncResourceBundle<RecipesState>('recipes', {
indexById: true,
// Add stub data in the absence of proper search data.
initialData: [
{
id: 'example-recipe',
featuredImage: {
url: 'https://media.guim.co.uk/7f96c515c4e320b8ded848f23ffdef8bd311fcad/245_1381_2750_2751/2000.jpg',
mediaId: '7f96c515c4e320b8ded848f23ffdef8bd311fcad',
cropId: '',
source: 'The Guardian. Food stylist: Loic Parisot.',
photographer: 'Robert Billington',
caption:
'Felicity Cloake’s Thai green curry works with chicken, seafood, pork, beef or tofu.',
mediaApiUri: '',
width: 2000,
height: 2000,
},
},
],
});
19 changes: 18 additions & 1 deletion fronts-client/src/components/feast/FeastSearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import TextInput from 'components/inputs/TextInput';
import ShortVerticalPinline from 'components/layout/ShortVerticalPinline';
import { styled, theme } from 'constants/theme';
import React from 'react';
import { connect } from 'react-redux';
import { media } from 'util/mediaQueries';
import { selectors as recipeSelectors } from 'bundles/recipesBundle';
import { State } from 'types/State';
import { Recipe } from 'types/Recipe';

const InputContainer = styled.div`
margin-bottom: 10px;
Expand Down Expand Up @@ -47,9 +51,13 @@ const Title = styled.h1`

type Props = {
rightHandContainer?: React.ReactElement<any>;
recipes: Recipe[];
};

export const FeastSearchContainer = ({ rightHandContainer }: Props) => (
const FeastSearchContainerComponent = ({
rightHandContainer,
recipes,
}: Props) => (
<React.Fragment>
<InputContainer>
<TextInputContainer>
Expand All @@ -64,6 +72,15 @@ export const FeastSearchContainer = ({ rightHandContainer }: Props) => (
<ShortVerticalPinline />
</Title>
</ResultsHeadingContainer>
{recipes.map((recipe) => JSON.stringify(recipe))}
</FixedContentContainer>
</React.Fragment>
);

const mapStateToProps = (state: State) => ({
recipes: recipeSelectors.selectAll(state),
});

export const FeastSearchContainer = connect(mapStateToProps)(
FeastSearchContainerComponent
);
2 changes: 2 additions & 0 deletions fronts-client/src/reducers/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import groups from 'reducers/groupsReducer';
import { reducer as focusReducer } from 'bundles/focusBundle';
import { reducer as featureSwitches } from 'reducers/featureSwitchesReducer';
import { reducer as notificationsReducer } from 'bundles/notificationsBundle';
import { reducer as recipesReducer } from 'bundles/recipesBundle';

const rootReducer = (state: any = { feed: {} }, action: any) => ({
fronts: fronts(state.fronts, action),
Expand Down Expand Up @@ -53,6 +54,7 @@ const rootReducer = (state: any = { feed: {} }, action: any) => ({
externalArticles: externalArticles(state.externalArticles, action),
pageViewData: pageViewData(state.pageViewData, action),
notifications: notificationsReducer(state.notifications, action),
recipes: recipesReducer(state.recipes, action),
});

export default rootReducer;
21 changes: 21 additions & 0 deletions fronts-client/src/types/Recipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type RecipeImage = {
url: string;
mediaId?: string;
cropId?: string;
source?: string;
photographer?: string;
imageType?: string;
caption?: string;
mediaApiUri?: string;
displayCredit?: boolean;
width?: number;
height?: number;
};

// Incomplete – add as we need more properties. Eventually, this would
// be useful to derive from a package.
export type Recipe = {
id: string;
featuredImage: RecipeImage; // the latter is an old image format that appears in our test fixtures
previewImage?: RecipeImage;
};

0 comments on commit b652941

Please sign in to comment.