-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1576 from guardian/db/add-chef
Add Chef card type to the Feast Platform
- Loading branch information
Showing
14 changed files
with
265 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import createAsyncResourceBundle from '../lib/createAsyncResourceBundle'; | ||
import { Chef } from '../types/Chef'; | ||
import chefOttolenghi from './fixtures/chef-ottolenghi.json'; | ||
import chefStein from './fixtures/chef-stein.json'; | ||
import chefCloake from './fixtures/chef-cloake.json'; | ||
|
||
export const { actions, reducer, selectors } = createAsyncResourceBundle<Chef>( | ||
'chefs', | ||
{ | ||
indexById: true, | ||
initialData: { | ||
// Add stub data in the absence of proper search data. | ||
[chefOttolenghi.id]: chefOttolenghi, | ||
[chefStein.id]: chefStein, | ||
[chefCloake.id]: chefCloake, | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "profile/felicity-cloake", | ||
"type": "contributor", | ||
"webTitle": "Felicity Cloake", | ||
"webUrl": "https://www.theguardian.com/profile/felicity-cloake", | ||
"apiUrl": "https://content.guardianapis.com/profile/felicity-cloake", | ||
"bio": "<p>Award-winning food writer Felicity Cloake has written five cookbooks, two food travelogues and is the author of the Guardian's <a href=\"https://www.theguardian.com/food/series/how-to-cook-the-perfect----\">How to Cook the Perfect ...</a> recipe series</p>", | ||
"bylineImageUrl": "https://uploads.guim.co.uk/2018/01/29/Felicity-Cloake.jpg", | ||
"bylineLargeImageUrl": "https://uploads.guim.co.uk/2018/01/29/Felicity_Cloake,_L.png", | ||
"firstName": "Felicity", | ||
"lastName": "Cloake" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "profile/yotamottolenghi", | ||
"type": "contributor", | ||
"sectionId": "lifeandstyle", | ||
"sectionName": "Life and style", | ||
"webTitle": "Yotam Ottolenghi", | ||
"webUrl": "https://www.theguardian.com/profile/yotamottolenghi", | ||
"apiUrl": "https://content.guardianapis.com/profile/yotamottolenghi", | ||
"bio": "<p>Yotam Ottolenghi is chef-patron of the <a href=\"https://ottolenghi.co.uk/\">Ottolenghi</a> delis and the Nopi and Rovi restaurants. He has published 10 bestselling cookbooks</p>", | ||
"bylineImageUrl": "https://uploads.guim.co.uk/2023/10/10/yotam_ottolenghi.jpg", | ||
"bylineLargeImageUrl": "https://uploads.guim.co.uk/2023/10/10/yotam_ottolenghi.png", | ||
"firstName": "Yotam", | ||
"lastName": "Ottolenghi", | ||
"twitterHandle": "ottolenghi" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "profile/rick-stein", | ||
"type": "contributor", | ||
"webTitle": "Rick Stein", | ||
"webUrl": "https://www.theguardian.com/profile/rick-stein", | ||
"apiUrl": "https://content.guardianapis.com/profile/rick-stein", | ||
"firstName": "stein", | ||
"lastName": "rick" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import { Card, CardSizes } from '../../../types/Collection'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectCard } from '../../../selectors/shared'; | ||
import { State } from '../../../types/State'; | ||
import { selectors as chefsSelectors } from 'bundles/chefsBundle'; | ||
import CardContainer from '../CardContainer'; | ||
import CardBody from '../CardBody'; | ||
import CardMetaHeading from '../CardMetaHeading'; | ||
import CardMetaContainer from '../CardMetaContainer'; | ||
import CardMetaContent from '../CardMetaContent'; | ||
import upperFirst from 'lodash/upperFirst'; | ||
import CardContent from '../CardContent'; | ||
import CardSettingsDisplay from '../CardSettingsDisplay'; | ||
import CardHeadingContainer from '../CardHeadingContainer'; | ||
import CardHeading from '../CardHeading'; | ||
import ImageAndGraphWrapper from '../../image/ImageAndGraphWrapper'; | ||
import { ThumbnailSmall } from '../../image/Thumbnail'; | ||
|
||
interface Props { | ||
onDragStart?: (d: React.DragEvent<HTMLElement>) => void; | ||
onDrop?: (d: React.DragEvent<HTMLElement>) => void; | ||
onDelete?: (uuid: string) => void; | ||
onAddToClipboard?: (uuid: string) => void; | ||
onClick?: () => void; | ||
id: string; | ||
collectionId?: string; | ||
frontId: string; | ||
draggable?: boolean; | ||
size?: CardSizes; | ||
textSize?: CardSizes; | ||
fade?: boolean; | ||
children?: React.ReactNode; | ||
isUneditable?: boolean; | ||
showMeta?: boolean; | ||
} | ||
|
||
export const ChefCard = ({ | ||
id, | ||
fade, | ||
size = 'default', | ||
textSize = 'default', | ||
onDelete, | ||
onAddToClipboard, | ||
children, | ||
isUneditable, | ||
collectionId, | ||
frontId, | ||
showMeta = true, | ||
...rest | ||
}: Props) => { | ||
const card = useSelector<State, Card>((state) => selectCard(state, id)); | ||
const chef = useSelector((state) => | ||
chefsSelectors.selectById(state, card.id) | ||
); | ||
return ( | ||
<CardContainer {...rest}> | ||
<CardBody data-testid="snap" size={size} fade={fade}> | ||
{showMeta && ( | ||
<CardMetaContainer size={size}> | ||
<CardMetaHeading>Chef</CardMetaHeading> | ||
<CardMetaContent>{upperFirst(chef?.type)}</CardMetaContent> | ||
</CardMetaContainer> | ||
)} | ||
<CardContent textSize={textSize}> | ||
<CardSettingsDisplay | ||
isBreaking={card.meta?.isBreaking} | ||
showByline={card.meta?.showByline} | ||
showQuotedHeadline={card.meta?.showQuotedHeadline} | ||
showLargeHeadline={card.meta?.showLargeHeadline} | ||
isBoosted={card.meta?.isBoosted} | ||
/> | ||
<CardHeadingContainer size={size}> | ||
<CardHeading data-testid="headline" html> | ||
{chef?.webTitle ?? 'No Chef found'} | ||
</CardHeading> | ||
</CardHeadingContainer> | ||
</CardContent> | ||
<ImageAndGraphWrapper size={size}> | ||
<ThumbnailSmall url={chef?.bylineLargeImageUrl} /> | ||
</ImageAndGraphWrapper> | ||
</CardBody> | ||
</CardContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Chef } from '../../types/Chef'; | ||
import React from 'react'; | ||
import { | ||
dragOffsetX, | ||
dragOffsetY, | ||
} from '../FrontsEdit/CollectionComponents/ArticleDrag'; | ||
import { FeedItem } from './FeedItem'; | ||
import { ContentInfo } from './ContentInfo'; | ||
import { selectFeatureValue } from '../../selectors/featureSwitchesSelectors'; | ||
import { State } from '../../types/State'; | ||
import { connect } from 'react-redux'; | ||
import noop from 'lodash/noop'; | ||
|
||
interface ComponentProps { | ||
chef: Chef; | ||
shouldObscureFeed: boolean; | ||
} | ||
|
||
export const ChefFeedItemComponent = ({ | ||
chef, | ||
shouldObscureFeed, | ||
}: ComponentProps) => { | ||
const handleDragStart = ( | ||
event: React.DragEvent<HTMLDivElement>, | ||
dragNode: HTMLDivElement | ||
) => { | ||
event.dataTransfer.setData('chef', JSON.stringify(chef)); | ||
if (dragNode) { | ||
event.dataTransfer.setDragImage(dragNode, dragOffsetX, dragOffsetY); | ||
} | ||
}; | ||
|
||
return ( | ||
<FeedItem | ||
id={chef.id} | ||
title={`${chef.firstName} ${chef.lastName}`} | ||
hasVideo={false} | ||
isLive={true} | ||
liveUrl={`https://theguardian.com/${chef.apiUrl}`} | ||
thumbnail={chef.bylineLargeImageUrl} | ||
onAddToClipboard={noop} | ||
handleDragStart={handleDragStart} | ||
shouldObscureFeed={shouldObscureFeed} | ||
metaContent={<ContentInfo>Chef</ContentInfo>} | ||
/> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state: State) => ({ | ||
shouldObscureFeed: selectFeatureValue(state, 'obscure-feed'), | ||
}); | ||
|
||
export const ChefFeedItem = connect(mapStateToProps)(ChefFeedItemComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface Chef { | ||
id: string; | ||
type: string; | ||
sectionId?: string; | ||
sectionName?: string; | ||
webTitle: string; | ||
webUrl: string; | ||
apiUrl: string; | ||
bio?: string; | ||
bylineImageUrl?: string; | ||
bylineLargeImageUrl?: string; | ||
firstName: string; | ||
lastName: string; | ||
twitterHandle?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.