Skip to content

Commit

Permalink
feat(r&w): add hide authors
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbrgl committed Mar 15, 2024
1 parent 451c52e commit 2e9fee4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/model/Gdoc/enrichedToRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export function enrichedBlockToRawBlock(
type: b.type,
value: {
heading: b.heading,
"hide-authors": b["hide-authors"].toString(),
primary: b.primary.map((enriched) =>
enrichedLinkToRawLink(enriched)
),
Expand Down
1 change: 1 addition & 0 deletions db/model/Gdoc/exampleEnrichedBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export const enrichedBlockExamples: Record<
type: "research-and-writing",
parseErrors: [],
heading: "Featured Work",
"hide-authors": true,
primary: [
{
value: {
Expand Down
1 change: 1 addition & 0 deletions db/model/Gdoc/rawToArchie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ function* rawResearchAndWritingToArchieMLString(
}
yield "{.research-and-writing}"
yield* propertyToArchieMLString("heading", block.value)
yield* propertyToArchieMLString("hide-authors", block.value)
if (primary) {
yield "[.primary]"
if (isArray(primary)) {
Expand Down
12 changes: 12 additions & 0 deletions db/model/Gdoc/rawToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ function parseResearchAndWritingBlock(
const createError = (
error: ParseError,
heading = "",
hideAuthors = false,
primary = [
{
value: { url: "" },
Expand All @@ -1662,6 +1663,7 @@ function parseResearchAndWritingBlock(
): EnrichedBlockResearchAndWriting => ({
type: "research-and-writing",
heading,
"hide-authors": hideAuthors,
primary,
secondary,
more,
Expand Down Expand Up @@ -1719,6 +1721,15 @@ function parseResearchAndWritingBlock(
} else return createLinkError(`Malformed link data: ${typeof rawLink}`)
}

if (
raw.value["hide-authors"] &&
!["true", "false"].includes(raw.value["hide-authors"])
) {
parseErrors.push({
message: `"hide-authors" must be true or false if present`,
})
}

if (!raw.value.primary)
return createError({ message: "Missing primary link" })
const primary: EnrichedBlockResearchAndWritingLink[] = []
Expand Down Expand Up @@ -1778,6 +1789,7 @@ function parseResearchAndWritingBlock(
return {
type: "research-and-writing",
heading: raw.value.heading,
"hide-authors": raw.value["hide-authors"] === "true",
primary,
secondary,
more,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export type RawBlockResearchAndWriting = {
type: "research-and-writing"
value: {
heading?: string
"hide-authors"?: string
// We're migrating these to be arrays, but have to support the old use-case until it's done
primary?:
| RawBlockResearchAndWritingLink
Expand Down Expand Up @@ -581,6 +582,7 @@ export type EnrichedBlockLatestWork = {
export type EnrichedBlockResearchAndWriting = {
type: "research-and-writing"
heading?: string
"hide-authors": boolean
primary: EnrichedBlockResearchAndWritingLink[]
secondary: EnrichedBlockResearchAndWritingLink[]
more?: EnrichedBlockResearchAndWritingRow
Expand Down
20 changes: 18 additions & 2 deletions site/gdocs/components/ResearchAndWriting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function ResearchAndWritingLink(
shouldHideThumbnail?: boolean
shouldHideThumbnailSm?: boolean
shouldHideSubtitle?: boolean
shouldHideAuthors?: boolean
}
) {
let {
Expand All @@ -43,6 +44,7 @@ function ResearchAndWritingLink(
shouldHideThumbnailSm = false,
isSmall = false,
shouldHideSubtitle = false,
shouldHideAuthors = false,
className,
} = props
const { linkedDocument, errorMessage } = useLinkedDocument(url)
Expand Down Expand Up @@ -110,7 +112,7 @@ function ResearchAndWritingLink(
{subtitle}
</p>
) : null}
{authors ? (
{authors && !shouldHideAuthors ? (
<p className="research-and-writing-link__authors body-3-medium-italic">
{formatAuthors({ authors })}
</p>
Expand All @@ -134,7 +136,16 @@ const parseLatestWorkToResearchAndWritingLink = (
}

export function ResearchAndWriting(props: ResearchAndWritingProps) {
const { heading, primary, secondary, more, rows, latest, className } = props
const {
heading,
"hide-authors": hideAuthors,
primary,
secondary,
more,
rows,
latest,
className,
} = props

const slug = heading ? slugify(heading) : RESEARCH_AND_WRITING_ID

Expand Down Expand Up @@ -176,6 +187,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
<ResearchAndWritingLink
className="span-cols-6 span-sm-cols-12"
key={i}
shouldHideAuthors={hideAuthors}
{...link}
/>
))}
Expand All @@ -184,6 +196,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
key={i}
className="span-cols-3 span-md-cols-6 span-sm-cols-12"
isSmall
shouldHideAuthors={hideAuthors}
{...link}
/>
))}
Expand All @@ -198,6 +211,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
{row.articles.map((link, i) => (
<ResearchAndWritingLink
shouldHideSubtitle
shouldHideAuthors={hideAuthors}
isSmall
className="span-cols-1"
key={i}
Expand All @@ -217,6 +231,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
<ResearchAndWritingLink
shouldHideThumbnail
shouldHideSubtitle
shouldHideAuthors={hideAuthors}
isSmall
className="span-cols-1"
key={i}
Expand All @@ -236,6 +251,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
<ResearchAndWritingLink
isSmall
shouldHideThumbnailSm
shouldHideAuthors={hideAuthors}
className="span-cols-1"
key={i}
{...link}
Expand Down

0 comments on commit 2e9fee4

Please sign in to comment.