-
Notifications
You must be signed in to change notification settings - Fork 6
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
Port details page to ts 2 #2680
Changes from all commits
e2c2951
56ea53d
73a0f97
727da47
975d844
8d2feeb
a72bef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import {useIntl} from 'react-intl'; | ||
import groupBy from 'lodash/groupBy'; | ||
import useDetailsContext from '../context'; | ||
import $ from '~/helpers/$'; | ||
|
||
function Authors({ | ||
heading, | ||
className, | ||
authors = [] | ||
}: { | ||
heading: string; | ||
className: string; | ||
authors: ReturnType<typeof useDetailsContext>['authors']; | ||
}) { | ||
if (authors.length === 0) { | ||
return null; | ||
} | ||
return ( | ||
<div> | ||
<h3 className="author-heading">{heading}</h3> | ||
{authors.map((author) => ( | ||
<div className={className} key={author.name}> | ||
{author.name} | ||
{author.university ? `, ${author.university}` : ''} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default function AuthorsSection() { | ||
const {authors, title} = useDetailsContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had been passing |
||
const polish = $.isPolish(title); | ||
const intl = useIntl(); | ||
const headings = polish | ||
? ['Główni autorzy', 'Autorzy współpracujący'] | ||
: [ | ||
intl.formatMessage({id: 'authors.senior'}), | ||
intl.formatMessage({id: 'authors.contributing'}) | ||
]; | ||
const groupFn = (author: (typeof authors)[0]) => | ||
author.seniorAuthor ? 'senior' : 'regular'; | ||
const groupedAuthors = groupBy(authors, groupFn); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Authors | ||
heading={headings[0]} | ||
className="loc-senior-author" | ||
authors={groupedAuthors.senior} | ||
/> | ||
<Authors | ||
heading={headings[1]} | ||
className="loc-nonsenior-author" | ||
authors={groupedAuthors.regular} | ||
/> | ||
</React.Fragment> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,69 @@ | ||
import React from 'react'; | ||
import RawHTML from '~/components/jsx-helpers/raw-html'; | ||
import {FormattedMessage, useIntl} from 'react-intl'; | ||
import useDetailsContext from '../context'; | ||
import $ from '~/helpers/$'; | ||
|
||
function EnglishButtonGroup({title}) { | ||
function EnglishButtonGroup({title}: {title: string}) { | ||
return ( | ||
<div className="button-group"> | ||
<a | ||
href={`/errata/form?book=${encodeURIComponent(title)}`} | ||
className="btn secondary medium" | ||
> | ||
<FormattedMessage id="errata.suggest" defaultMessage="Suggest a correction" /> | ||
<FormattedMessage | ||
id="errata.suggest" | ||
defaultMessage="Suggest a correction" | ||
/> | ||
</a> | ||
<a | ||
href={`/errata/?book=${encodeURIComponent(title)}`} | ||
className="btn default medium" | ||
> | ||
<FormattedMessage id="errata.list" defaultMessage="Errata list" /> | ||
<FormattedMessage | ||
id="errata.list" | ||
defaultMessage="Errata list" | ||
/> | ||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
function ButtonGroup({polish, title}) { | ||
function ButtonGroup({title}: {title: string}) { | ||
const PolishButtonGroup = () => ( | ||
<div className="button-group"> | ||
<a | ||
href="https://openstax.pl/pl/errata" | ||
className="btn secondary medium">Zgłoś poprawkę</a> | ||
className="btn secondary medium" | ||
> | ||
Zgłoś poprawkę | ||
</a> | ||
</div> | ||
); | ||
|
||
return polish ? <PolishButtonGroup /> : <EnglishButtonGroup title={title} />; | ||
return $.isPolish(title) ? ( | ||
<PolishButtonGroup /> | ||
) : ( | ||
<EnglishButtonGroup title={title} /> | ||
); | ||
} | ||
|
||
export function ErrataContents({model, polish}) { | ||
const title = model.title; | ||
const blurb = model.errataContent; | ||
export function ErrataContents() { | ||
const {title, errataContent: blurb, bookState} = useDetailsContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, |
||
|
||
return ( | ||
<React.Fragment> | ||
<RawHTML Tag="p" html={blurb} /> | ||
{ | ||
model.bookState !== 'deprecated' && | ||
<ButtonGroup polish={polish} title={title} /> | ||
} | ||
{bookState !== 'deprecated' && <ButtonGroup title={title} />} | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default function ErrataSection({model, polish=false}) { | ||
export default function ErrataSection() { | ||
const intl = useIntl(); | ||
const {bookState} = useDetailsContext(); | ||
|
||
if (!['live', 'new_edition_available', 'deprecated'].includes(model.bookState)) { | ||
if (!['live', 'new_edition_available', 'deprecated'].includes(bookState)) { | ||
return null; | ||
} | ||
|
||
|
@@ -64,7 +76,7 @@ export default function ErrataSection({model, polish=false}) { | |
<h3> | ||
<FormattedMessage id="errata.header" defaultMessage="Errata" /> | ||
</h3> | ||
<ErrataContents model={model} polish={polish} /> | ||
<ErrataContents /> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All books are Rex now, so I removed the CNX fetching stuff.