diff --git a/frontends/main/src/app-pages/Articles/ArticleDetailPage.tsx b/frontends/main/src/app-pages/Articles/ArticleDetailPage.tsx index e8f73d53d8..950aeceba6 100644 --- a/frontends/main/src/app-pages/Articles/ArticleDetailPage.tsx +++ b/frontends/main/src/app-pages/Articles/ArticleDetailPage.tsx @@ -2,7 +2,13 @@ import React from "react" import { useArticleDetail } from "api/hooks/articles" -import { Container, LoadingSpinner, styled, Typography } from "ol-components" +import { + Container, + LoadingSpinner, + styled, + Typography, + TiptapEditorContainer, +} from "ol-components" import { ButtonLink } from "@mitodl/smoot-design" import { notFound } from "next/navigation" import { Permission } from "api/hooks/user" @@ -24,14 +30,6 @@ const WrapperContainer = styled.div({ paddingBottom: "10px", }) -const PreTag = styled.pre({ - background: "#f6f6f6", - padding: "16px", - borderRadius: "8px", - fontSize: "14px", - overflowX: "auto", -}) - export const ArticleDetailPage = ({ articleId }: { articleId: number }) => { const id = Number(articleId) const { data, isLoading } = useArticleDetail(id) @@ -58,7 +56,11 @@ export const ArticleDetailPage = ({ articleId }: { articleId: number }) => { - {JSON.stringify(data.content, null, 2)} + ) diff --git a/frontends/main/src/app-pages/Articles/ArticleEditPage.test.tsx b/frontends/main/src/app-pages/Articles/ArticleEditPage.test.tsx index 2f1bf9b013..e2d95495ab 100644 --- a/frontends/main/src/app-pages/Articles/ArticleEditPage.test.tsx +++ b/frontends/main/src/app-pages/Articles/ArticleEditPage.test.tsx @@ -24,7 +24,15 @@ describe("ArticleEditPage", () => { const article = factories.articles.article({ id: 42, title: "Existing Title", - content: { id: 1, content: "Existing content" }, + content: { + type: "doc", + content: [ + { + type: "paragraph", + content: [{ type: "text", text: "Existing Title" }], + }, + ], + }, }) setMockResponse.get(urls.articles.details(article.id), article) @@ -45,7 +53,15 @@ describe("ArticleEditPage", () => { const article = factories.articles.article({ id: 123, title: "Existing Title", - content: { id: 1, content: "Existing content" }, + content: { + type: "doc", + content: [ + { + type: "paragraph", + content: [{ type: "text", text: "Existing Title" }], + }, + ], + }, }) setMockResponse.get(urls.articles.details(article.id), article) @@ -77,7 +93,15 @@ describe("ArticleEditPage", () => { const article = factories.articles.article({ id: 7, title: "Old Title", - content: { id: 1, content: "Bad content" }, + content: { + type: "doc", + content: [ + { + type: "paragraph", + content: [{ type: "text", text: "Existing Title" }], + }, + ], + }, }) setMockResponse.get(urls.articles.details(article.id), article) diff --git a/frontends/main/src/app-pages/Articles/ArticleEditPage.tsx b/frontends/main/src/app-pages/Articles/ArticleEditPage.tsx index dc4c8a5a35..22cb88b48b 100644 --- a/frontends/main/src/app-pages/Articles/ArticleEditPage.tsx +++ b/frontends/main/src/app-pages/Articles/ArticleEditPage.tsx @@ -1,11 +1,19 @@ "use client" -import React, { useEffect, useState, ChangeEvent } from "react" +import React, { useEffect, useState } from "react" import { Permission } from "api/hooks/user" import { useRouter } from "next-nprogress-bar" import { useArticleDetail, useArticlePartialUpdate } from "api/hooks/articles" -import { Button, Input, Alert } from "@mitodl/smoot-design" +import { Button, Alert } from "@mitodl/smoot-design" import RestrictedRoute from "@/components/RestrictedRoute/RestrictedRoute" -import { Container, Typography, styled, LoadingSpinner } from "ol-components" +import { + Container, + Typography, + styled, + LoadingSpinner, + TiptapEditorContainer, + JSONContent, +} from "ol-components" + import { notFound } from "next/navigation" import { articlesView } from "@/common/urls" @@ -19,11 +27,6 @@ const ClientContainer = styled.div({ margin: "10px 0", }) -const TitleInput = styled(Input)({ - width: "100%", - margin: "10px 0", -}) - const ArticleEditPage = ({ articleId }: { articleId: string }) => { const router = useRouter() @@ -31,8 +34,10 @@ const ArticleEditPage = ({ articleId }: { articleId: string }) => { const { data: article, isLoading } = useArticleDetail(id) const [title, setTitle] = useState("") - const [text, setText] = useState("") - const [json, setJson] = useState({}) + const [json, setJson] = useState({ + type: "doc", + content: [{ type: "paragraph", content: [] }], + }) const [alertText, setAlertText] = useState("") const { mutate: updateArticle, isPending } = useArticlePartialUpdate() @@ -57,7 +62,6 @@ const ArticleEditPage = ({ articleId }: { articleId: string }) => { useEffect(() => { if (article && !title) { setTitle(article.title) - setText(article.content ? JSON.stringify(article.content, null, 2) : "") setJson(article.content) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -70,20 +74,13 @@ const ArticleEditPage = ({ articleId }: { articleId: string }) => { return notFound() } - const handleChange = (e: ChangeEvent) => { - const value = e.target.value - setText(value) - - try { - const parsed = JSON.parse(value) - setJson(parsed) - } catch { - setJson({}) - } + const handleChange = (json: object) => { + setJson(json) } + return ( - + Edit Article @@ -99,25 +96,17 @@ const ArticleEditPage = ({ articleId }: { articleId: string }) => { )} - { - console.log("Title input changed:", e.target.value) - setTitle(e.target.value) - setAlertText("") - }} - placeholder="Enter article title" - className="input-field" - /> - - -