Skip to content

Commit

Permalink
feat(JournalData.tsx): display publication date using fp-ts Option
Browse files Browse the repository at this point in the history
The publication date is now displayed using fp-ts Option to handle
nullable values. The date-fns/fp library is used for curried
functions, which improves code readability. The "Published on" text
was changed to "Published" to improve the display of the publication
date.
  • Loading branch information
ktun95 committed Feb 26, 2025
1 parent 6de0e33 commit f4c4c88
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions apps/publication/src/components/JournalData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import Typography from "@material-ui/core/Typography"
import { pipe } from "fp-ts/function"
import { isEmpty as SisEmpty } from "fp-ts/string"
import {
map as Omap,
fromNullable as OfromNullable,
getOrElse as OgetOrElse,
} from "fp-ts/Option"
import { match as Bmatch } from "fp-ts/boolean"
import { makeStyles, Theme } from "@material-ui/core/styles"
import { addDays, format, parseISO } from "date-fns"
import { format, addDays, parseISO } from "date-fns/fp"
import { Publication } from "dicty-graphql-schema"
import { JournalDataItem } from "./JournalDataItem"

Expand Down Expand Up @@ -53,17 +54,29 @@ const JournalData = ({ data }: JournalDataProperties) => {
const doiURL = `https://doi.org/${doi}`
// convert ISO 8601 string to Date format
// otherwise the 00:00:00.000Z causes it to return the previous day
const day = addDays(parseISO(pub_date), 1)
// convert Date to desired display format
const date = format(day, "PPP")
return (
<Box mt={2}>
<Box pb={1}>
<Typography variant="h3" component="span" className={classes.text}>
{`Published on `}
{`Published `}
</Typography>
{pipe(
pub_date,
OfromNullable,
Omap((date) =>
pipe(date, parseISO, addDays(1), format("PPP"), (formattedDate) => (
<Typography
variant="h3"
component="span"
className={classes.text}>
{`on ${formattedDate} `}
</Typography>
)),
),
OgetOrElse(() => <></>),

Check warning on line 76 in apps/publication/src/components/JournalData.tsx

View check run for this annotation

Codecov / codecov/patch

apps/publication/src/components/JournalData.tsx#L76

Added line #L76 was not covered by tests
)}
<Typography variant="h3" component="span" className={classes.text}>
{`${date} in `}
{`in `}
</Typography>
<Typography variant="h3" component="span" className={classes.journal}>
{journal},
Expand Down

0 comments on commit f4c4c88

Please sign in to comment.