Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@kanaabe => [Publishing] Fix missing reduce start value #494

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 34 additions & 71 deletions src/Components/Publishing/Sections/ArtworkCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ interface StyledArtworkCaptionProps {
}

export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
joinParts(children, delimiter = ', ') {
const joined = _.compact(children)
.reduce((prev, curr) => {
return [
prev,
delimiter,
curr
]
})
joinParts(children, delimiter = ", ") {
const joined = _.compact(children).reduce((prev, curr) => {
return [prev, delimiter, curr]
}, [])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was missing [].

Copy link
Member Author

@damassi damassi Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is a bit stranger now that I'm looking at it closer. For some reason auto-infering a start value leads to correct test results, but compacting an end value with a start value errors out. Looking...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And arr.reduce(callback[, initialValue]) is the signature -- no starting value required

return joined
}

renderArtists() {
const {
artwork: { artist, artists }
} = this.props
const { artwork: { artist, artists } } = this.props

// Multiple artists
if (artists && artists.length > 0) {
Expand Down Expand Up @@ -72,29 +65,19 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
</span>
)
} else {
return (
<span className="name">
{name}
</span>
)
return <span className="name">{name}</span>
}
}

renderTitleDate() {
const children = [
this.renderTitle(),
this.renderDate()
]
const children = [this.renderTitle(), this.renderDate()]

const titleDate = this.joinParts(children)
return titleDate
}

renderTitle() {
const {
artwork: { slug, title },
linked
} = this.props
const { artwork: { slug, title }, linked } = this.props

if (title) {
if (linked) {
Expand All @@ -118,11 +101,7 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
}

renderDate() {
const {
artwork: {
date
}
} = this.props
const { artwork: { date } } = this.props

if (date && date.length) {
return (
Expand All @@ -134,12 +113,7 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
}

renderPartner() {
const {
artwork: {
partner: { name, slug }
},
linked
} = this.props
const { artwork: { partner: { name, slug } }, linked } = this.props

if (name) {
const createTextLink = Boolean(linked && slug)
Expand All @@ -159,11 +133,7 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
}

renderCredit() {
const {
artwork: {
credit
},
} = this.props
const { artwork: { credit } } = this.props

if (credit && credit.length) {
return (
Expand All @@ -175,10 +145,7 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
}

renderPartnerCredit = () => {
const children = [
this.renderPartner(),
this.renderCredit()
]
const children = [this.renderPartner(), this.renderCredit()]

const joined = this.joinParts(children, ". ")
return joined
Expand All @@ -192,29 +159,24 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
return (
<StyledFullscreenCaption layout={layout}>
<Line>
<ArtistName>
{this.renderArtists()}
</ArtistName>
<ArtistName>{this.renderArtists()}</ArtistName>
</Line>
<div>
<Line>
{this.renderTitleDate()}
</Line>
<Line>
{this.renderPartnerCredit()}
</Line>
<Line>{this.renderTitleDate()}</Line>
<Line>{this.renderPartnerCredit()}</Line>
</div>
</StyledFullscreenCaption>
)

// Classic Layout
} else if (layout === "classic") {
return (
<StyledClassicCaption layout={layout} className="display-artwork__caption">
<StyledClassicCaption
layout={layout}
className="display-artwork__caption"
>
<Truncator>
<ArtistName>
{this.renderArtists()}
</ArtistName>
<ArtistName>{this.renderArtists()}</ArtistName>

{this.renderTitleDate()}
{". "}
Expand All @@ -226,19 +188,17 @@ export class ArtworkCaption extends React.Component<ArtworkCaptionProps, null> {
// Default (Standard + Feature)
} else {
return (
<StyledArtworkCaption layout={layout} sectionLayout={sectionLayout} className="display-artwork__caption">
<ArtistName>
{this.renderArtists()}
</ArtistName>
<StyledArtworkCaption
layout={layout}
sectionLayout={sectionLayout}
className="display-artwork__caption"
>
<ArtistName>{this.renderArtists()}</ArtistName>

<div>
<Truncator>
{this.renderTitleDate()}
</Truncator>
<Truncator>{this.renderTitleDate()}</Truncator>

<Truncator>
{this.renderPartnerCredit()}
</Truncator>
<Truncator>{this.renderPartnerCredit()}</Truncator>
</div>
</StyledArtworkCaption>
)
Expand All @@ -254,10 +214,13 @@ const ArtistName = styled.span`
.artist-name {
margin-right: 30px;
}
`}
`};
`

const div: StyledFunction<StyledArtworkCaptionProps & React.HTMLProps<HTMLDivElement>> = styled.div
const div: StyledFunction<
StyledArtworkCaptionProps & React.HTMLProps<HTMLDivElement>
> =
styled.div

const StyledArtworkCaption = div`
padding: ${props => (props.sectionLayout === "fillwidth" ? "0 10px;" : "0;")}
Expand Down Expand Up @@ -318,5 +281,5 @@ const Line = styled.div`
&.artist-name {
margin-bottom: 5px;
}
`}
`};
`