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
112 changes: 55 additions & 57 deletions pages/[username].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,65 +43,63 @@ const Profile: NextPage = ({
<meta property="og:type" content="website" />
</Head>
<Layout>
<div className="border-t-2">
<div className="max-w-2xl px-4 mx-auto text-white">
<main className="flex pt-6">
<div className="mr-4 flex-shrink-0 self-center">
{image && (
<img
className="rounded-full object-cover h-32 w-32"
alt={`Avatar for ${name}`}
src={image}
/>
)}
</div>
<div className="flex flex-col justify-center">
<h1 className="text-lg md:text-xl font-bold mb-0">{name}</h1>
<h2 className="text-neutral-400 font-bold text-sm">
@{username}
</h2>
<p className="mt-1">{bio}</p>
</div>
</main>
<div className="max-w-2xl px-4 mx-auto text-white">
<main className="flex pt-6">
<div className="mr-4 flex-shrink-0 self-center">
{image && (
<img
className="rounded-full object-cover h-32 w-32"
alt={`Avatar for ${name}`}
src={image}
/>
)}
</div>
<div className="flex flex-col justify-center">
<h1 className="text-lg md:text-xl font-bold mb-0">{name}</h1>
<h2 className="text-neutral-400 font-bold text-sm">
@{username}
</h2>
<p className="mt-1">{bio}</p>
</div>
</main>

<PageHeading>Published articles</PageHeading>
<PageHeading>Published articles</PageHeading>

{posts.length ? (
posts.map(
({ slug, title, excerpt, readTimeMins, published, id }) => {
if (!published) return;
return (
<ArticlePreview
key={slug}
slug={slug}
title={title}
excerpt={excerpt}
name={name}
username={username || ""}
image={image}
date={published}
readTime={readTimeMins}
menuOptions={
isOwner
? [
{
label: "Edit",
href: `/create/${id}`,
postId: id,
},
]
: undefined
}
showBookmark={!isOwner}
id={id}
/>
);
}
)
) : (
<p className="font-medium py-4">Nothing published yet... 🥲</p>
)}
</div>
{posts.length ? (
posts.map(
({ slug, title, excerpt, readTimeMins, published, id }) => {
if (!published) return;
return (
<ArticlePreview
key={slug}
slug={slug}
title={title}
excerpt={excerpt}
name={name}
username={username || ""}
image={image}
date={published}
readTime={readTimeMins}
menuOptions={
isOwner
? [
{
label: "Edit",
href: `/create/${id}`,
postId: id,
},
]
: undefined
}
showBookmark={!isOwner}
id={id}
/>
);
}
)
) : (
<p className="font-medium py-4">Nothing published yet... 🥲</p>
)}
</div>
</Layout>
</>
Expand Down
50 changes: 24 additions & 26 deletions pages/articles/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,30 @@ const ArticlePage: NextPage = ({
</Transition>

<Layout>
<div className="border-t-2">
<div className="mx-auto pb-4 max-w-3xl px-2 sm:px-4 break-words">
<article className="prose prose-invert lg:prose-lg">
<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} />
<CommentsArea postId={post.id} postOwnerId={post.userId} />
</div>
<div className="mx-auto pb-4 max-w-3xl px-2 sm:px-4 break-words">
<article className="prose prose-invert lg:prose-lg">
<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} />
<CommentsArea postId={post.id} postOwnerId={post.userId} />
</div>
</Layout>
</>
Expand Down
168 changes: 83 additions & 85 deletions pages/articles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,94 +69,92 @@ const ArticlesPage = () => {
<meta property="og:url" content="https://codu.co/articles" />
</Head>
<Layout>
<div className="border-t border-white">
<div className="relative sm:mx-auto max-w-2xl mx-2">
<div className="my-8 border-b-2 pb-4 flex justify-between items-center">
<h1 className="text-3xl tracking-tight font-extrabold text-neutral-50 sm:text-4xl ">
{typeof tag === "string" ? (
<div className="flex justify-center items-center">
<TagIcon className="text-neutral-200 h-6 w-6 mr-3" />
{capitalize(tag)}
</div>
) : (
"Articles"
)}
</h1>
<div>
<label htmlFor="filter" className="sr-only">
Location
</label>
<select
id="filter"
name="filter"
className="capitalize mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 ring-1 ring-inset ring-neutral-300 focus:ring-2 focus:ring-pink-600 sm:text-sm sm:leading-6 "
onChange={(e) => {
router.push(
`/articles?filter=${e.target.value}${
tag ? `&tag=${tag}` : ""
}`
);
}}
value={selectedSortFilter}
>
<option>newest</option>
<option>oldest</option>
<option>top</option>
</select>
</div>
</div>
<section>
{status === "error" && (
<div>Something went wrong... Please refresh your page.</div>
<div className="relative sm:mx-auto max-w-2xl mx-2">
<div className="my-8 border-b-2 pb-4 flex justify-between items-center">
<h1 className="text-3xl tracking-tight font-extrabold text-neutral-50 sm:text-4xl ">
{typeof tag === "string" ? (
<div className="flex justify-center items-center">
<TagIcon className="text-neutral-200 h-6 w-6 mr-3" />
{capitalize(tag)}
</div>
) : (
"Articles"
)}
{status === "loading" &&
Children.toArray(
Array.from({ length: 7 }, () => {
return <ArticleLoading />;
})
)}
{status === "success" &&
data.pages.map((page) => {
return (
<Fragment key={page.nextCursor ?? "lastPage"}>
{page.posts.map(
({
slug,
title,
excerpt,
user: { name, image, username },
updatedAt,
readTimeMins,
id,
currentUserLikesPost,
}) => (
<ArticlePreview
key={title}
id={id}
slug={slug}
title={title}
excerpt={excerpt}
name={name}
username={username || ""}
image={image}
date={updatedAt.toISOString()}
readTime={readTimeMins}
bookmarkedInitialState={currentUserLikesPost}
/>
)
)}
</Fragment>
</h1>
<div>
<label htmlFor="filter" className="sr-only">
Location
</label>
<select
id="filter"
name="filter"
className="capitalize mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 ring-1 ring-inset ring-neutral-300 focus:ring-2 focus:ring-pink-600 sm:text-sm sm:leading-6 "
onChange={(e) => {
router.push(
`/articles?filter=${e.target.value}${
tag ? `&tag=${tag}` : ""
}`
);
})}
{status === "success" && !data.pages[0].posts.length && (
<h2 className="text-lg">No results founds</h2>
)}
{isFetchingNextPage ? <ArticleLoading /> : null}
<span className="invisible" ref={ref}>
intersection observer marker
</span>
</section>
}}
value={selectedSortFilter}
>
<option>newest</option>
<option>oldest</option>
<option>top</option>
</select>
</div>
</div>
<section>
{status === "error" && (
<div>Something went wrong... Please refresh your page.</div>
)}
{status === "loading" &&
Children.toArray(
Array.from({ length: 7 }, () => {
return <ArticleLoading />;
})
)}
{status === "success" &&
data.pages.map((page) => {
return (
<Fragment key={page.nextCursor ?? "lastPage"}>
{page.posts.map(
({
slug,
title,
excerpt,
user: { name, image, username },
updatedAt,
readTimeMins,
id,
currentUserLikesPost,
}) => (
<ArticlePreview
key={title}
id={id}
slug={slug}
title={title}
excerpt={excerpt}
name={name}
username={username || ""}
image={image}
date={updatedAt.toISOString()}
readTime={readTimeMins}
bookmarkedInitialState={currentUserLikesPost}
/>
)
)}
</Fragment>
);
})}
{status === "success" && !data.pages[0].posts.length && (
<h2 className="text-lg">No results founds</h2>
)}
{isFetchingNextPage ? <ArticleLoading /> : null}
<span className="invisible" ref={ref}>
intersection observer marker
</span>
</section>
</div>
</Layout>
</>
Expand Down
Loading