-
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 blog page to ts #2676
Port blog page to ts #2676
Changes from 12 commits
dbc10cf
f3325e9
f90d8e6
f0b87af
fc2c0a9
9423e41
a37ae83
cc31ca7
f85725e
a6ef32a
e8ef08e
3deed37
fb5d7bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export type Category = { | ||
id: string; | ||
id: number; | ||
name: string; | ||
subjectIcon?: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function FormInput({label, longLabel, inputProps, suggestions}: | ||
{ | ||
label: string; | ||
longLabel?: string; | ||
inputProps: object; | ||
suggestions?: boolean; | ||
} | ||
): React.ReactNode; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,35 +2,53 @@ import React from 'react'; | |
import RawHTML from '~/components/jsx-helpers/raw-html'; | ||
import Byline from '~/components/byline/byline'; | ||
import ClippedImage from '~/components/clipped-image/clipped-image'; | ||
import type { | ||
ArticleSummary as BlurbDataBase, | ||
CollectionEntry, | ||
SubjectEntry | ||
} from '~/pages/blog/blog-context'; | ||
|
||
type Collection = { | ||
name?: string; | ||
value: {collection: Collection}[]; | ||
}; | ||
type CollectionVariant = | ||
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. These types were simply wrong. They shouldn't have been recursive, they just have an optional wrapping layer. |
||
| CollectionEntry | ||
| { | ||
value: {collection: CollectionEntry}[]; | ||
}; | ||
|
||
type ArticleSubjectVariant = | ||
| SubjectEntry | ||
| { | ||
value: {subject: SubjectEntry}[]; | ||
}; | ||
|
||
type BlurbData = | ||
| null | ||
| (Omit<BlurbDataBase, 'collections' | 'articleSubjects'> & { | ||
meta?: {slug: string}; | ||
collections: CollectionVariant[]; | ||
articleSubjects: ArticleSubjectVariant[]; | ||
}); | ||
|
||
type ArticleSubject = { | ||
name?: string; | ||
value: {subject: ArticleSubject}[]; | ||
}; | ||
|
||
type BlurbData = null | { | ||
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. BlurbData and ArticleSummaryData were defined independently, but BlurbData is really an extension of ArticleSummaryData. |
||
id: string; | ||
collections: Collection[]; | ||
articleSubjects: ArticleSubject[]; | ||
heading: string; | ||
export type ArticleSummaryData = { | ||
id?: number; | ||
articleSlug: string; | ||
image: string; | ||
altText?: string; | ||
headline: string; | ||
subheading: string; | ||
articleImage: string; | ||
articleImageAlt: string; | ||
bodyBlurb: string; | ||
author: string; | ||
body: string; | ||
date: string; | ||
slug?: string; | ||
meta: {slug: string}; | ||
author: string; | ||
collectionNames: string[]; | ||
articleSubjectNames: string[]; | ||
openInNewWindow?: boolean; | ||
HeadTag?: keyof JSX.IntrinsicElements; | ||
setPath?: (href: string) => void; | ||
}; | ||
|
||
export function blurbModel(data: BlurbData) { | ||
export function blurbModel(data: BlurbData): ArticleSummaryData | Record<string, never> { | ||
if (!data) { | ||
return {}; | ||
return {} as Record<string, never>; | ||
} | ||
|
||
return { | ||
|
@@ -56,24 +74,14 @@ export function blurbModel(data: BlurbData) { | |
body: data.bodyBlurb, | ||
author: data.author, | ||
date: data.date, | ||
articleSlug: data.slug || data.meta.slug | ||
articleSlug: data.slug || (data.meta?.slug as string) | ||
}; | ||
} | ||
|
||
export type ArticleSummaryData = { | ||
articleSlug: string; | ||
image: string; | ||
headline: string; | ||
subheading: string; | ||
body: string; | ||
date: string; | ||
author: string; | ||
collectionNames: string[]; | ||
articleSubjectNames: string[]; | ||
setPath: (href: string) => void; | ||
openInNewWindow: boolean; | ||
HeadTag?: keyof JSX.IntrinsicElements; | ||
}; | ||
export type PopulatedBlurbModel = Exclude< | ||
ReturnType<typeof blurbModel>, | ||
Record<string, never> | ||
>; | ||
|
||
export default function ArticleSummary({ | ||
articleSlug, | ||
|
@@ -100,8 +108,10 @@ export default function ArticleSummary({ | |
if (target.getAttribute('target') === '_blank') { | ||
return; | ||
} | ||
event.preventDefault(); | ||
setPath(target.href); | ||
if (setPath) { | ||
event.preventDefault(); | ||
setPath(target.href); | ||
} | ||
}, | ||
[setPath] | ||
); | ||
|
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.
This was an accessibility fix needed because the testing library identifies accessible objects and this wasn't one.