Skip to content

Commit

Permalink
Merge pull request #1588 from guardian/db/add-search-ui-for-recipe-chef
Browse files Browse the repository at this point in the history
Add ui to switch between recipes and chefs feeds
  • Loading branch information
Divs-B authored May 31, 2024
2 parents 4f11831 + 91c3256 commit a697c95
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 29 deletions.
91 changes: 62 additions & 29 deletions fronts-client/src/components/feed/RecipeSearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ClipboardHeader from 'components/ClipboardHeader';
import TextInput from 'components/inputs/TextInput';
import ShortVerticalPinline from 'components/layout/ShortVerticalPinline';
import { styled } from 'constants/theme';
import React from 'react';
import React, { useState } from 'react';
import { connect } from 'react-redux';
import { selectors as recipeSelectors } from 'bundles/recipesBundle';
import { selectors as chefSelectors } from 'bundles/chefsBundle';
Expand All @@ -13,6 +13,7 @@ import { SearchResultsHeadingContainer } from './SearchResultsHeadingContainer';
import { SearchTitle } from './SearchTitle';
import { RecipeFeedItem } from './RecipeFeedItem';
import { ChefFeedItem } from './ChefFeedItem';
import { RadioButton, RadioGroup } from '../inputs/RadioButtons';

const InputContainer = styled.div`
margin-bottom: 10px;
Expand All @@ -34,38 +35,70 @@ interface Props {
chefs: Record<string, Chef>;
}

enum FeedType {
recipes = 'recipeFeed',
chefs = 'chefFeed',
}

const FeastSearchContainerComponent = ({
rightHandContainer,
recipes,
chefs,
}: Props) => (
<React.Fragment>
<InputContainer>
<TextInputContainer>
<TextInput placeholder="Search recipes" displaySearchIcon />
</TextInputContainer>
<ClipboardHeader />
</InputContainer>
<FixedContentContainer>
<SearchResultsHeadingContainer>
<SearchTitle>
{'Results'}
<ShortVerticalPinline />
</SearchTitle>
</SearchResultsHeadingContainer>
{Object.values(recipes).map((recipe) => (
<RecipeFeedItem key={recipe.id} recipe={recipe} />
))}
{Object.values(chefs).map((chef) => (
<ChefFeedItem
key={chef.id}
chef={chef}
/> /*TODO: as of now, added rendering of chefs just after the recipes. Need
to change when "search-chefs" action gets finalised*/
))}
</FixedContentContainer>
</React.Fragment>
);
}: Props) => {
const [selectedOption, setSelectedOption] = useState(FeedType.recipes);
const handleOptionChange = (optionName: FeedType) => {
setSelectedOption(optionName);
};

const renderTheFeed = () => {
switch (selectedOption) {
case FeedType.recipes:
return Object.values(recipes).map((recipe) => (
<RecipeFeedItem key={recipe.id} recipe={recipe} />
));
case FeedType.chefs:
return Object.values(chefs).map((chef) => (
<ChefFeedItem key={chef.id} chef={chef} />
));
}
};

return (
<React.Fragment>
<InputContainer>
<TextInputContainer>
<TextInput placeholder="Search recipes" displaySearchIcon />
</TextInputContainer>
<ClipboardHeader />
</InputContainer>
<RadioGroup>
<RadioButton
checked={selectedOption === FeedType.recipes}
onChange={() => handleOptionChange(FeedType.recipes)}
label="Recipes"
inline
name="recipeFeed"
/>
<RadioButton
checked={selectedOption === FeedType.chefs}
onChange={() => handleOptionChange(FeedType.chefs)}
label="Chefs"
inline
name="chefFeed"
/>
</RadioGroup>
<FixedContentContainer>
<SearchResultsHeadingContainer>
<SearchTitle>
{'Results'}
<ShortVerticalPinline />
</SearchTitle>
</SearchResultsHeadingContainer>
{renderTheFeed()}
</FixedContentContainer>
</React.Fragment>
);
};

const mapStateToProps = (state: State) => ({
recipes: recipeSelectors.selectAll(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const SearchResultsHeadingContainer = styled.div`
border-top: 1px solid ${theme.colors.greyVeryLight};
align-items: baseline;
display: flex;
margin-top: 10px;
margin-bottom: 10px;
flex-direction: row;
`;

0 comments on commit a697c95

Please sign in to comment.