Skip to content

Commit 5e29ed5

Browse files
Ahtesham QuraishAhtesham Quraish
authored andcommitted
address the feedback
1 parent 454936e commit 5e29ed5

10 files changed

Lines changed: 39 additions & 44 deletions

File tree

frontends/main/src/app-pages/Articles/ArticleListingPage.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ import { useWebsiteContentList } from "api/hooks/website_content"
1717
import type { WebsiteContent } from "api/v1"
1818
import { LocalDate } from "ol-utilities"
1919
import { RiArrowLeftLine, RiArrowRightLine } from "@remixicon/react"
20-
import { extractFirstImageFromArticle } from "@/common/articleUtils"
21-
import {
22-
userArticlesView,
23-
USER_ARTICLES_CREATE,
24-
USER_ARTICLES_LISTING,
25-
} from "@/common/urls"
20+
import { extractFirstImage } from "@/common/websiteContentUtils"
21+
import { articleView, ARTICLES_CREATE, ARTICLES_LISTING } from "@/common/urls"
2622

2723
const PAGE_SIZE = 20
2824
const MAX_PAGE = 50
@@ -71,14 +67,12 @@ const EmptyState = styled.div`
7167
gap: 16px;
7268
`
7369

74-
const UserArticleCard: React.FC<{ article: WebsiteContent }> = ({
75-
article,
76-
}) => {
70+
const ArticleCard: React.FC<{ article: WebsiteContent }> = ({ article }) => {
7771
const articleUrl = article.is_published
78-
? userArticlesView(article.slug || String(article.id))
79-
: `${USER_ARTICLES_LISTING}${article.id}/draft`
72+
? articleView(article.slug || String(article.id))
73+
: `${ARTICLES_LISTING}${article.id}/draft`
8074

81-
const imageUrl = extractFirstImageFromArticle(article.content)
75+
const imageUrl = extractFirstImage(article.content)
8276

8377
return (
8478
<ArticleCardWrapper forwardClicksToLink>
@@ -103,6 +97,7 @@ const ArticleListingPage: React.FC = () => {
10397
const { data: articles, isLoading } = useWebsiteContentList({
10498
limit: PAGE_SIZE,
10599
offset: (page - 1) * PAGE_SIZE,
100+
content_type: "article",
106101
})
107102

108103
useEffect(() => {
@@ -119,7 +114,7 @@ const ArticleListingPage: React.FC = () => {
119114
<Container>
120115
<PageHeader>
121116
<Typography variant="h3">Articles</Typography>
122-
<ButtonLink variant="primary" href={USER_ARTICLES_CREATE}>
117+
<ButtonLink variant="primary" href={ARTICLES_CREATE}>
123118
New Article
124119
</ButtonLink>
125120
</PageHeader>
@@ -134,7 +129,7 @@ const ArticleListingPage: React.FC = () => {
134129
key={article.id}
135130
size={{ xs: 12, sm: 6, md: 4, lg: 3, xl: 3 }}
136131
>
137-
<UserArticleCard article={article} />
132+
<ArticleCard article={article} />
138133
</Grid2>
139134
))}
140135
</Grid2>
@@ -164,7 +159,7 @@ const ArticleListingPage: React.FC = () => {
164159
<Typography variant="body1" color="textSecondary">
165160
Get started by creating your first article.
166161
</Typography>
167-
<ButtonLink variant="primary" href={USER_ARTICLES_CREATE}>
162+
<ButtonLink variant="primary" href={ARTICLES_CREATE}>
168163
New Article
169164
</ButtonLink>
170165
</EmptyState>

frontends/main/src/app-pages/WebsiteContent/WebsiteContentDraftListingPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
} from "api/v1"
2121
import { LocalDate } from "ol-utilities"
2222
import { RiArrowLeftLine, RiArrowRightLine } from "@remixicon/react"
23-
import { extractFirstImageFromArticle } from "@/common/articleUtils"
23+
import { extractFirstImage } from "@/common/websiteContentUtils"
2424
import { websiteContentEditView, websiteContentCreateView } from "@/common/urls"
2525
import RestrictedRoute from "@/components/RestrictedRoute/RestrictedRoute"
2626
import { ButtonLink } from "@mitodl/smoot-design"
@@ -92,7 +92,7 @@ const DraftItem: React.FC<{ article: WebsiteContent; type: string }> = ({
9292
? `/${type === "article" ? "articles" : type}/${article.slug || article.id}`
9393
: websiteContentEditView(type, article.id)
9494

95-
const imageUrl = extractFirstImageFromArticle(article.content)
95+
const imageUrl = extractFirstImage(article.content)
9696

9797
return (
9898
<DraftArticleCard forwardClicksToLink>

frontends/main/src/app-pages/WebsiteContent/WebsiteContentEditPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import RestrictedRoute from "@/components/RestrictedRoute/RestrictedRoute"
99
import { styled, LoadingSpinner } from "ol-components"
1010
import { ArticleEditor } from "@/page-components/TiptapEditor/contentTypes/article/ArticleEditor"
1111
import { NewsEditor } from "@/page-components/TiptapEditor/contentTypes/news/NewsEditor"
12-
import { userArticlesView, websiteContentEditView } from "@/common/urls"
12+
import { articleView, websiteContentEditView } from "@/common/urls"
1313
import invariant from "tiny-invariant"
1414
import type { WebsiteContent } from "api/v1"
1515

@@ -28,7 +28,7 @@ const Spinner = styled(LoadingSpinner)({
2828
})
2929

3030
const PUBLISHED_VIEW_URL: Record<string, (slug: string) => string> = {
31-
article: (slug) => userArticlesView(slug),
31+
article: (slug) => articleView(slug),
3232
news: (slug) => `/news/${slug}`,
3333
}
3434

frontends/main/src/app-pages/WebsiteContent/WebsiteContentNewPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import RestrictedRoute from "@/components/RestrictedRoute/RestrictedRoute"
88
import { styled } from "ol-components"
99
import { ArticleEditor } from "@/page-components/TiptapEditor/contentTypes/article/ArticleEditor"
1010
import { NewsEditor } from "@/page-components/TiptapEditor/contentTypes/news/NewsEditor"
11-
import { userArticlesView, websiteContentEditView } from "@/common/urls"
11+
import { articleView, websiteContentEditView } from "@/common/urls"
1212
import invariant from "tiny-invariant"
1313
import type { WebsiteContent } from "api/v1"
1414

@@ -19,7 +19,7 @@ const PageContainer = styled.div(({ theme }) => ({
1919
}))
2020

2121
const PUBLISHED_VIEW_URL: Record<string, (slug: string) => string> = {
22-
article: (slug) => userArticlesView(slug),
22+
article: (slug) => articleView(slug),
2323
news: (slug) => `/news/${slug}`,
2424
}
2525

frontends/main/src/common/urls.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ export const newsDraftView = (id: string) =>
4848
export const newsEditView = (id: number) =>
4949
generatePath(NEWS_EDIT, { id: String(id) })
5050

51-
// User-created articles (served under /articles)
52-
export const USER_ARTICLES_LISTING = "/articles/"
53-
export const USER_ARTICLES_VIEW = "/articles/[id]"
54-
export const USER_ARTICLES_DRAFT_VIEW = "/articles/[id]/draft"
55-
export const USER_ARTICLES_EDIT = "/articles/[id]/edit"
56-
export const USER_ARTICLES_CREATE = "/articles/new"
57-
export const userArticlesView = (id: string) =>
58-
generatePath(USER_ARTICLES_VIEW, { id: String(id) })
59-
export const userArticlesDraftView = (id: string) =>
60-
generatePath(USER_ARTICLES_DRAFT_VIEW, { id: String(id) })
61-
export const userArticlesEditView = (id: number) =>
62-
generatePath(USER_ARTICLES_EDIT, { id: String(id) })
51+
// Articles (served under /articles)
52+
export const ARTICLES_LISTING = "/articles/"
53+
export const ARTICLES_VIEW = "/articles/[id]"
54+
export const ARTICLES_DRAFT_VIEW = "/articles/[id]/draft"
55+
export const ARTICLES_EDIT = "/articles/[id]/edit"
56+
export const ARTICLES_CREATE = "/articles/new"
57+
export const articleView = (id: string) =>
58+
generatePath(ARTICLES_VIEW, { id: String(id) })
59+
export const articleDraftView = (id: string) =>
60+
generatePath(ARTICLES_DRAFT_VIEW, { id: String(id) })
61+
export const articleEditView = (id: number) =>
62+
generatePath(ARTICLES_EDIT, { id: String(id) })
6363

6464
// Generic website content editing routes
6565
export const WEBSITE_CONTENT_CREATE = "/website_content/[type]/new"

frontends/main/src/common/articleUtils.ts renamed to frontends/main/src/common/websiteContentUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Recursively traverses a ProseMirror JSON content structure to find the first image.
33
*
4-
* @param content - The ProseMirror JSON content object from an article
4+
* @param content - The ProseMirror JSON content object
55
* @returns The URL of the first image found, or null if no image exists
66
*/
7-
export function extractFirstImageFromArticle(content: unknown): string | null {
7+
export function extractFirstImage(content: unknown): string | null {
88
if (!content || typeof content !== "object") return null
99

1010
const node = content as Record<string, unknown>
@@ -21,7 +21,7 @@ export function extractFirstImageFromArticle(content: unknown): string | null {
2121
// Recursively check content array
2222
if (Array.isArray(node.content)) {
2323
for (const childNode of node.content) {
24-
const imageUrl = extractFirstImageFromArticle(childNode)
24+
const imageUrl = extractFirstImage(childNode)
2525
if (imageUrl) {
2626
return imageUrl
2727
}

frontends/main/src/page-components/TiptapEditor/ArticleViewer.test.tsx renamed to frontends/main/src/page-components/TiptapEditor/NewsViewer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { screen, renderWithProviders, setMockResponse } from "@/test-utils"
33
import { factories, urls } from "api/test-utils"
44
import { NewsEditor } from "./contentTypes/news/NewsEditor"
55

6-
describe("ArticleViewer", () => {
7-
test("renders article content", async () => {
6+
describe("NewsViewer", () => {
7+
test("renders content", async () => {
88
const user = factories.user.user({
99
is_authenticated: true,
1010
is_article_editor: true,

frontends/main/src/page-components/TiptapEditor/TiptapEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const Container = styled.div<{
8282
},
8383
}
8484
: {}),
85-
"&& .tiptap.ProseMirror.abc > :nth-child(2)": {
85+
"&& .tiptap.ProseMirror.tiptap-viewer > :nth-child(2)": {
8686
paddingTop: "36px",
8787
},
8888
"&& .tiptap.ProseMirror, && .tiptap-viewer": {
@@ -299,11 +299,11 @@ const TipTapViewer = ({
299299
content: JSONContent
300300
extensions: Array<Extension | Node | Mark>
301301
bannerViewer?: typeof BannerViewer
302-
bylineViewer?: typeof BannerViewer
302+
bylineViewer?: typeof ByLineInfoBarViewer
303303
}) => {
304304
return (
305305
<Container readOnly data-testid="editor">
306-
<div className="tiptap ProseMirror tiptap-viewer abc">
306+
<div className="tiptap ProseMirror tiptap-viewer">
307307
{renderToReactElement({
308308
extensions,
309309
content,

frontends/main/src/page-components/TiptapEditor/core/WebsiteContentEditor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dynamic from "next/dynamic"
2020
import { Toolbar } from "../vendor/components/tiptap-ui-primitive/toolbar"
2121
import { TiptapEditor, MainToolbarContent, TipTapViewer } from "../TiptapEditor"
2222
import { BannerViewer } from "../extensions/node/Banner/BannerNode"
23+
import { ByLineInfoBarViewer } from "../extensions/node/ByLineInfoBar/ByLineInfoBarViewer"
2324
import { handleImageUpload } from "../vendor/lib/tiptap-utils"
2425
import { useSchema } from "../useSchema"
2526
import { WebsiteContentProvider } from "../WebsiteContentContext"
@@ -162,7 +163,7 @@ export interface WebsiteContentEditorProps {
162163
article?: WebsiteContent
163164
backgroundColor?: string
164165
bannerViewer?: typeof BannerViewer
165-
bylineViewer?: typeof BannerViewer
166+
bylineViewer?: typeof ByLineInfoBarViewer
166167
}
167168

168169
const WebsiteContentEditor = ({
@@ -454,7 +455,7 @@ const WebsiteContentEditor = ({
454455
content={content}
455456
extensions={extensions}
456457
bannerViewer={bannerViewer}
457-
bylineViewer={bylineViewer}
458+
bylineViewer={bylineViewer ?? ByLineInfoBarViewer}
458459
/>
459460
</>
460461
) : (

frontends/main/src/page-components/TiptapEditor/extensions/node/ByLineInfoBar/ByLineInfoBarNode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const ByLineInfoBarNode = Node.create({
3333
},
3434

3535
addNodeView() {
36-
// eslint-disable-next-line react-hooks/rules-of-hooks
3736
return ReactNodeViewRenderer(ByLineInfoBar)
3837
},
3938
})

0 commit comments

Comments
 (0)