Skip to content

Commit

Permalink
Revert "LocalDate and NoSSR components to render localized dates only…
Browse files Browse the repository at this point in the history
… on client"

This reverts commit b4ccd6d.
  • Loading branch information
jonkafton committed Nov 18, 2024
1 parent b4ccd6d commit ffa1098
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 72 deletions.
4 changes: 2 additions & 2 deletions frontends/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "PORT=${PORT:-8062} TZ=UTC next dev",
"dev": "PORT=${PORT:-8062} next dev",
"build": "next build",
"build:no-lint": "next build --no-lint",
"start": "TZ=UTC next start",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
Expand Down
20 changes: 10 additions & 10 deletions frontends/main/src/app-pages/HomePage/NewsEventsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
NewsEventsListFeedTypeEnum,
} from "api/hooks/newsEvents"
import type { NewsFeedItem, EventFeedItem } from "api/v0"
import { LocalDate } from "ol-utilities"
import { formatDate } from "ol-utilities"
import { RiArrowRightSLine } from "@remixicon/react"
import Link from "next/link"

Expand Down Expand Up @@ -196,7 +196,7 @@ const Story: React.FC<{ item: NewsFeedItem; mobile: boolean }> = ({
{item.title}
</Card.Title>
<Card.Footer>
Published: <LocalDate date={item.news_details?.publish_date} />
Published: {formatDate(item.news_details?.publish_date)}
</Card.Footer>
</StoryCard>
)
Expand Down Expand Up @@ -226,16 +226,16 @@ const NewsEventsSection: React.FC = () => {
<Card.Content>
<EventDate>
<EventDay>
<LocalDate
date={(item as EventFeedItem).event_details?.event_datetime}
format="D"
/>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"D",
)}
</EventDay>
<EventMonth>
<LocalDate
date={(item as EventFeedItem).event_details?.event_datetime}
format="MMM"
/>
{formatDate(
(item as EventFeedItem).event_details?.event_datetime,
"MMM",
)}
</EventMonth>
</EventDate>
<Link href={item.url} data-card-link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@remixicon/react"
import { LearningResource } from "api"
import {
LocalDate,
formatDate,
getReadableResourceType,
DEFAULT_RESOURCE_IMG,
getLearningResourcePrices,
Expand Down Expand Up @@ -149,8 +149,7 @@ const StartDate: React.FC<{ resource: LearningResource; size?: Size }> = ({
const format = size === "small" ? "MMM DD, YYYY" : "MMMM DD, YYYY"
const formatted = anytime
? "Anytime"
: startDate && <LocalDate date={startDate} format={format} />

: startDate && formatDate(startDate, format)
if (!formatted) return null

const showLabel = size !== "small" || anytime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@remixicon/react"
import { ResourceTypeEnum, LearningResource } from "api"
import {
LocalDate,
formatDate,
getReadableResourceType,
DEFAULT_RESOURCE_IMG,
pluralize,
Expand Down Expand Up @@ -151,7 +151,7 @@ export const StartDate: React.FC<{ resource: LearningResource }> = ({
const startDate = getResourceDate(resource)
const formatted = anytime
? "Anytime"
: startDate && <LocalDate date={startDate} format="MMMM DD, YYYY" />
: startDate && formatDate(startDate, "MMMM DD, YYYY")
if (!formatted) return null

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
getDisplayPrice,
getRunPrices,
showStartAnytime,
NoSSR,
} from "ol-utilities"

const DifferingRuns = styled.div({
Expand Down Expand Up @@ -104,9 +103,7 @@ const DifferingRunsTable: React.FC<{ resource: LearningResource }> = ({
</DifferingRunHeader>
{resource.runs?.map((run, index) => (
<DifferingRun key={index}>
<DateData>
<NoSSR>{formatRunDate(run, asTaughtIn)}</NoSSR>
</DateData>
<DateData>{formatRunDate(run, asTaughtIn)}</DateData>
{run.resource_prices && (
<PriceData>
<span>{getDisplayPrice(getRunPrices(run)["course"])}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
formatRunDate,
getLearningResourcePrices,
showStartAnytime,
NoSSR,
} from "ol-utilities"
import { theme } from "../ThemeProvider/ThemeProvider"
import DifferingRunsTable from "./DifferingRunsTable"
Expand Down Expand Up @@ -256,11 +255,7 @@ const INFO_ITEMS: InfoItemConfig = [
const totalDatesWithRuns =
resource.runs?.filter((run) => run.start_date !== null).length || 0
if (allRunsAreIdentical(resource) && totalDatesWithRuns > 0) {
return (
<NoSSR>
<RunDates resource={resource} />
</NoSSR>
)
return <RunDates resource={resource} />
} else return null
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ButtonLink } from "../Button/Button"
import type { LearningResource, LearningResourceRun } from "api"
import { ResourceTypeEnum, PlatformEnum } from "api"
import {
NoSSR,
formatDate,
capitalize,
DEFAULT_RESOURCE_IMG,
Expand Down Expand Up @@ -300,7 +299,7 @@ const ResourceDescription = ({ resource }: { resource?: LearningResource }) => {
return (
<Description
/**
* Resource descriptions can contain HTML. They are sanitized on the
* Resource descriptions can contain HTML. They are santiized on the
* backend during ETL. This is safe to render.
*/
dangerouslySetInnerHTML={{ __html: resource.description || "" }}
Expand Down Expand Up @@ -385,7 +384,7 @@ const LearningResourceExpandedV1: React.FC<LearningResourceExpandedV1Props> = ({
.map((run) => {
return {
value: run.id.toString(),
label: <NoSSR>{formatRunDate(run, asTaughtIn)}</NoSSR>,
label: formatRunDate(run, asTaughtIn),
}
}) ?? []

Expand Down Expand Up @@ -416,7 +415,7 @@ const LearningResourceExpandedV1: React.FC<LearningResourceExpandedV1Props> = ({
return (
<DateSingle>
<DateLabel>{label}</DateLabel>
<NoSSR>{formatted ?? ""}</NoSSR>
{formatted ?? ""}
</DateSingle>
)
}
Expand Down
20 changes: 0 additions & 20 deletions frontends/ol-utilities/src/date/LocalDate.tsx

This file was deleted.

4 changes: 1 addition & 3 deletions frontends/ol-utilities/src/date/format.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import moment from "moment"

/* Instances must be wrapped in <NoSSR> to avoid SSR hydration mismatches.
*/
export const formatDate = (
/**
* Date string or date.
*/
date: string | Date,
/**
* A Moment.js format string. See https://momentjs.com/docs/#/displaying/format/
* A momentjs format string. See https://momentjs.com/docs/#/displaying/format/
*/
format = "MMM D, YYYY",
) => {
Expand Down
2 changes: 0 additions & 2 deletions frontends/ol-utilities/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
export * from "./styles"

export * from "./date/format"
export * from "./date/LocalDate"
export * from "./learning-resources/learning-resources"
export * from "./learning-resources/pricing"
export * from "./strings/html"
Expand All @@ -15,4 +14,3 @@ export * from "./hooks"
export * from "./querystrings"
export * from "./lib"
export * from "./images/backgroundImages"
export * from "./ssr/NoSSR"
16 changes: 0 additions & 16 deletions frontends/ol-utilities/src/ssr/NoSSR.tsx

This file was deleted.

0 comments on commit ffa1098

Please sign in to comment.