Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 38 additions & 69 deletions app/articles/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,75 +71,44 @@ const ArticlePage = async ({ params }: Props) => {

return (
<>
<Head>
{/* @TODO confirm metadata is correct and remove <Head> */}
<title>{post.title}</title>
{post.canonicalUrl && <link rel="canonical" href={post.canonicalUrl} />}
<meta name="author" content={post.user.name}></meta>
<meta key="og:title" property="og:title" content={post.title} />
<meta
key="og:description"
property="og:description"
content={post.excerpt}
/>
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="browserconfig.xml" />
<meta name="theme-color" content="#000" />
<meta property="og:type" content="article" />
<meta
property="og:url"
content={`https://${host}/articles/${post.slug}`}
/>
<meta
name="image"
property="og:image"
content={`https://${host}/api/og?title=${encodeURIComponent(
post.title,
)}`}
/>
<meta name="twitter:card" content="summary_large_image" />
</Head>
<>
<ArticleMenu
session={session}
postId={post.id}
postTitle={post.title}
postUsername={post?.user.username || ""}
postUrl={`https://${host}/articles/${post.slug}`}
/>
<div className="mx-auto pb-4 md:max-w-3xl px-2 sm:px-4 break-words">
<article className="prose dark:prose-invert lg:prose-lg mx-auto max-w-3xl">
<h1>{post.title}</h1>
{Markdoc.renderers.react(content, React, {
components: markdocComponents,
})}
</article>
{post.tags.length > 0 && (
<section className="flex flex-wrap gap-3">
{post.tags.map(({ tag }) => (
<Link
href={`/articles?tag=${tag.title.toLowerCase()}`}
key={tag.title}
className="bg-gradient-to-r from-orange-400 to-pink-600 hover:bg-pink-700 text-white py-1 px-3 rounded-full text-xs font-bold"
>
{tag.title}
</Link>
))}
</section>
)}
</div>
<div className="mx-auto pb-4 max-w-3xl px-2 sm:px-4">
<BioBar author={post.user} />
{post.showComments ? (
<CommentsArea postId={post.id} postOwnerId={post.userId} />
) : (
<h3 className="py-10 italic text-lg">
Comments are disabled for this post
</h3>
)}
</div>
</>

<ArticleMenu
session={session}
postId={post.id}
postTitle={post.title}
postUsername={post?.user.username || ""}
postUrl={`https://${host}/articles/${post.slug}`}
/>
<div className="mx-auto pb-4 md:max-w-3xl px-2 sm:px-4 break-words">
<article className="prose dark:prose-invert lg:prose-lg mx-auto max-w-3xl">
<h1>{post.title}</h1>
{Markdoc.renderers.react(content, React, {
components: markdocComponents,
})}
</article>
{post.tags.length > 0 && (
<section className="flex flex-wrap gap-3">
{post.tags.map(({ tag }) => (
<Link
href={`/articles?tag=${tag.title.toLowerCase()}`}
key={tag.title}
className="bg-gradient-to-r from-orange-400 to-pink-600 hover:bg-pink-700 text-white py-1 px-3 rounded-full text-xs font-bold"
>
{tag.title}
</Link>
))}
</section>
)}
</div>
<div className="mx-auto pb-4 max-w-3xl px-2 sm:px-4">
<BioBar author={post.user} />
{post.showComments ? (
<CommentsArea postId={post.id} postOwnerId={post.userId} />
) : (
<h3 className="py-10 italic text-lg">
Comments are disabled for this post
</h3>
)}
</div>
{session && session?.user?.role === "ADMIN" && (
<ArticleAdminPanel session={session} postId={post.id} />
)}
Expand Down
24 changes: 3 additions & 21 deletions app/create/[[...paramsArr]]/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ const Create = () => {

const [viewPreview, setViewPreview] = useState<boolean>(false);
const [tags, setTags] = useState<string[]>([]);
const [showComments, setShowComments] = useState<boolean>(true);
const [tagValue, setTagValue] = useState<string>("");
const [savedTime, setSavedTime] = useState<string>("");
const [open, setOpen] = useState<boolean>(false);
const [shouldRefetch, setShouldRefetch] = useState<boolean>(true);
const [unsavedChanges, setUnsavedChanges] = useState<boolean>(false);
const [delayDebounce, setDelayDebounce] = useState<boolean>(false);
const allowUpdate = unsavedChanges && !delayDebounce;

const allowUpdate = unsavedChanges;
const textareaRef = useRef<HTMLTextAreaElement>(null);

useMarkdownHotkeys(textareaRef);
Expand All @@ -54,7 +53,6 @@ const Create = () => {
defaultValues: {
title: "",
body: "",
showComments: true,
},
});

Expand Down Expand Up @@ -206,9 +204,8 @@ const Create = () => {

useEffect(() => {
if (!data) return;
const { body, excerpt, title, id, tags, showComments } = data;
const { body, excerpt, title, id, tags } = data;
setTags(tags.map(({ tag }) => tag.title));
setShowComments(showComments);
reset({ body, excerpt, title, id });
}, [data]);

Expand Down Expand Up @@ -339,21 +336,6 @@ const Create = () => {
original source.
</p>
</Disclosure.Panel>
<Disclosure.Panel className="pt-4 pb-2">
<label htmlFor="canonicalUrl">
Show comments on your post
</label>
<input
id="showComments"
type="checkbox"
checked={showComments}
{...register("showComments", {
onChange: (e) =>
setShowComments(e.target.checked),
value: showComments,
})}
/>
</Disclosure.Panel>
</>
)}
</Disclosure>
Expand Down
1 change: 0 additions & 1 deletion schema/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const SavePostSchema = z.object({
),
canonicalUrl: z.optional(z.string().trim().url()),
tags: z.string().array().max(5).optional(),
showComments: z.boolean().optional(),
});

export const PublishPostSchema = z.object({
Expand Down
11 changes: 1 addition & 10 deletions server/api/router/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ export const postRouter = createTRPCRouter({
update: protectedProcedure
.input(SavePostSchema)
.mutation(async ({ input, ctx }) => {
const {
id,
body,
title,
excerpt,
canonicalUrl,
tags = [],
showComments,
} = input;
const { id, body, title, excerpt, canonicalUrl, tags = [] } = input;

const currentPost = await ctx.db.post.findUnique({
where: { id },
Expand Down Expand Up @@ -105,7 +97,6 @@ export const postRouter = createTRPCRouter({
excerpt: getExcerptValue() || "",
readTimeMins: readingTime(body),
canonicalUrl,
showComments,
},
});
return post;
Expand Down