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

Byline improvements #193

Merged
merged 17 commits into from
Oct 15, 2018
Merged

Byline improvements #193

merged 17 commits into from
Oct 15, 2018

Conversation

philmcmahon
Copy link
Contributor

@philmcmahon philmcmahon commented Sep 27, 2018

What does this change?

Why?

Cos it looks better this way - before:
screen shot 2018-09-27 at 16 54 52
after:
screen shot 2018-09-27 at 16 54 58

#What's with that dangerouslysethtml?
I read all of this thread on replacing bits of string with react templates, and decided that this was the only way to make it work

@@ -259,14 +276,39 @@ const metaExtras = css`

const pillarColour = palette.lifestyle.main; // TODO make dynamic

const dtFormat = (date: Date) => dateformat(date, 'ddd d mmm yyyy HH:MM "GMT"');
const dtFormat = (date: Date) => dateformat(date, 'ddd d mmm yyyy HH:MM Z');
Copy link
Contributor

Choose a reason for hiding this comment

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

TypeScript question, do we need to define the return type of dtFormat or can TypeScript implicitly deduce it's type? I'm guessing in this case it's a string but I can't see any type definitions for dateformat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it compiled so...I guess it deduced the type? I've added the return type in, I find in scala it's generally better to define a return type

paidContentType?: string
}

interface TagType {
Copy link
Contributor

@GHaberis GHaberis Sep 27, 2018

Choose a reason for hiding this comment

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

Looks like we're going to have a conflict of sorts here as I've also defined a new TagType in my branch https://github.com/guardian/dotcom-rendering/pull/192/files#diff-978893e81256a8dbee76e6fe1045f2d7R28. I'm happy to hang on merging mine until this is in and I'll use this new type, as my TagType is pretty basic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if that's ok then great! happy to wait for you as well though

<div className={profile(pillarColour)}>
<span
className={byline}
dangerouslySetInnerHTML={{
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't use dangerouslySetInnerHTML with renderByline returning a string here, as this mixing markup in a string template with JSX markup. You could replace renderByline with a function that returns a stateless React component. If you call this function Byline for example you can then put <Byline byline={byline} tags={CAPI.tags} /> as a child of this span (not you can pass byline and tags as props.

Copy link
Contributor

Choose a reason for hiding this comment

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

👆

@philmcmahon I'd be happy to pair with you on this today if you like

Copy link
Contributor

@SiAdcock SiAdcock Sep 28, 2018

Choose a reason for hiding this comment

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

Gosh, this is more complicated than it looks. I'd say don't worry about this for now, it can be an interesting coding challenge for us one day!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a good case for turning this into an array of structured data and then mapping that.
[ 'Firstname Lastname', 'and', {?:'Other Name',url:'https://'} ]

</div>
{CAPI.author.twitterHandle && (
<div className={twitterHandle}>
<TwitterIcon />{' '}
Copy link
Contributor

@GHaberis GHaberis Sep 27, 2018

Choose a reason for hiding this comment

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

Is this {' '} required? If we're using it to put space between <TwitterIcon /> and the link then we should use css to achieve this affect.

author: getString(data, 'config.page.author'),
author: {
byline: getString(data, 'config.page.byline', ''),
twitterHandle: leadContributor.properties.twitterHandle,
Copy link
Contributor

@GHaberis GHaberis Sep 27, 2018

Choose a reason for hiding this comment

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

If there are no tags where tagType === 'Contributor' then leadContributor would be undefined, if it is looking up properties on it'll cause an error. You could add a ternary to check if it's defined and if not just assign undefined to twitterHandle. eg.

twitterHandle: leadContributor ? leadContributor.properties.twitterHandle : undefined,.

Same goes for email below...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

@philmcmahon philmcmahon force-pushed the pm-more-forgiving-validation branch from b8ee163 to 0814f68 Compare September 28, 2018 13:48
@philmcmahon
Copy link
Contributor Author

sorry I've been so slow finishing this off! I'm going to implement @AWare 's suggested change and then get this merged

@SiAdcock
Copy link
Contributor

Thanks @philmcmahon. Gizza wave if you want to pair 👋

@philmcmahon philmcmahon force-pushed the pm-more-forgiving-validation branch from 3e1f3c6 to 5fa4214 Compare October 15, 2018 10:55
@@ -278,17 +278,22 @@ export const extractArticleMeta = (data: {}): CAPIType => {
const webPublicationDate = new Date(
getNumber(data, 'config.page.webPublicationDate'),
);
const tags = getTags(data);
const tags = getArray<TagType>(data, 'tags.tags');
Copy link
Contributor

@GHaberis GHaberis Oct 15, 2018

Choose a reason for hiding this comment

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

If an article doesn't have tags.tags then we'll not get a 500, I don't think we should be so strict, previously getTags would've returned an empty array if no tags were available.

Copy link
Contributor

@SiAdcock SiAdcock left a comment

Choose a reason for hiding this comment

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

Thanks so much @philmcmahon!

@philmcmahon philmcmahon merged commit f50c709 into master Oct 15, 2018
@philmcmahon philmcmahon deleted the pm-more-forgiving-validation branch October 15, 2018 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants