Skip to content

Commit 4528d1a

Browse files
committed
feat: add unpublished article notice and draft byline support
- Integrated UnpublishedArticleNotice component to display a notice for unpublished articles. - Added ArticleDraftBylineLabel for drafts, enhancing user awareness of article status. - Updated Bengali translations for unpublished articles and related messages to improve localization.
1 parent eb652b2 commit 4528d1a

3 files changed

Lines changed: 88 additions & 10 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"use client";
2+
3+
import { Badge } from "@/components/ui/badge";
4+
import { useTranslation } from "@/i18n/use-translation";
5+
import { useSession } from "@/store/session.atom";
6+
import { FileWarning } from "lucide-react";
7+
8+
type Props = {
9+
publishedAt: Date | null | undefined;
10+
authorId: string;
11+
};
12+
13+
/** Inline label next to the byline date when the article has no `published_at`. */
14+
export function ArticleDraftBylineLabel() {
15+
const { _t } = useTranslation();
16+
return (
17+
<span className="font-medium text-amber-700 dark:text-amber-400">
18+
{_t("Draft")}
19+
</span>
20+
);
21+
}
22+
23+
export function UnpublishedArticleNotice({ publishedAt, authorId }: Props) {
24+
const { _t } = useTranslation();
25+
const session = useSession();
26+
27+
if (publishedAt) return null;
28+
29+
const viewerId = session?.session?.user_id;
30+
const isAuthor = Boolean(viewerId) && viewerId === authorId;
31+
32+
return (
33+
<div
34+
role="alert"
35+
className="mb-4 flex flex-col gap-2 rounded-lg border border-amber-500/45 bg-amber-500/12 px-4 py-3 text-sm dark:border-amber-400/40 dark:bg-amber-400/12"
36+
>
37+
<div className="flex flex-wrap items-center gap-2">
38+
<FileWarning
39+
className="size-4 shrink-0 text-amber-800 dark:text-amber-300"
40+
aria-hidden
41+
/>
42+
<Badge
43+
variant="outline"
44+
className="border-amber-700/45 text-amber-950 dark:border-amber-300/50 dark:text-amber-50"
45+
>
46+
{_t("Draft")}
47+
</Badge>
48+
<span className="font-semibold text-amber-950 dark:text-amber-50">
49+
{_t("Unpublished article")}
50+
</span>
51+
</div>
52+
<p className="text-pretty pl-6 text-amber-950/85 dark:text-amber-50/90">
53+
{isAuthor
54+
? _t(
55+
"This draft is not listed anywhere on the site. Only people with the link can open it. Publish from the editor when you want it on your profile and in feeds.",
56+
)
57+
: _t(
58+
"This article is unpublished. It is not listed on the site; only people with this link can view it.",
59+
)}
60+
</p>
61+
</div>
62+
);
63+
}

src/app/[username]/[articleHandle]/page.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import type { Article, WithContext } from "schema-dts";
2424
import { eq } from "sqlkit";
2525
import ArticleSidebar from "./_components/ArticleSidebar";
2626
import EditArticleButton from "./_components/EditArticleButton";
27+
import {
28+
ArticleDraftBylineLabel,
29+
UnpublishedArticleNotice,
30+
} from "./_components/UnpublishedArticleNotice";
2731

2832
interface ArticlePageProps {
2933
params: Promise<{
@@ -136,6 +140,10 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
136140
>
137141
{/* {!article && <div>Article not found</div>} */}
138142
<div className="px-4 my-2 md:m-0">
143+
<UnpublishedArticleNotice
144+
publishedAt={article.published_at}
145+
authorId={article.author_id}
146+
/>
139147
{article?.cover_image && (
140148
<div className="rounded-sm w-full overflow-hidden">
141149
<AppImage
@@ -173,16 +181,20 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
173181
{article?.user?.name}
174182
</Link>
175183
<div className="flex items-center text-xs text-muted-foreground">
176-
<time dateTime={article?.published_at?.toString()}>
177-
{new Date(article?.published_at!).toLocaleDateString(
178-
"bn-BD",
179-
{
180-
month: "long",
181-
day: "numeric",
182-
year: "numeric",
183-
},
184-
)}
185-
</time>
184+
{article?.published_at ? (
185+
<time dateTime={article.published_at.toISOString()}>
186+
{new Date(article.published_at).toLocaleDateString(
187+
"bn-BD",
188+
{
189+
month: "long",
190+
day: "numeric",
191+
year: "numeric",
192+
},
193+
)}
194+
</time>
195+
) : (
196+
<ArticleDraftBylineLabel />
197+
)}
186198
<span className="mx-1.5">·</span>
187199
<span>{readingTime(article?.body ?? "")} min read</span>
188200
</div>

src/i18n/bn.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"Total post comments": "সর্বমোট কমেন্ট",
5353
"Articles": "আর্টিক্যাল সমূহ",
5454
"Draft": "খসড়া",
55+
"Unpublished article": "অপ্রকাশিত লেখা",
56+
"This draft is not listed anywhere on the site. Only people with the link can open it. Publish from the editor when you want it on your profile and in feeds.": "এই খসড়া সাইটের কোথাও তালিকাভুক্ত নয়। লিংক যাদের আছে শুধু তারাই এটি খুলতে পারবে। প্রোফাইল ও ফিডতে দেখাতে চাইলে এডিটর থেকে প্রকাশ করুন।",
57+
"This article is unpublished. It is not listed on the site; only people with this link can view it.": "এই লেখাটি অপ্রকাশিত। সাইটে এটি তালিকাভুক্ত নয়; যাদের এই লিংক আছে শুধু তারাই দেখতে পারবে।",
5558
"Edit": "সম্পাদনা",
5659
"Sure to unpublish": "অপ্রকাশিত করতে চাচ্ছেন?",
5760
"If you unpublish the article, this will be excluded in home page and search results, however direct links to the article will still work": "আপনি যদি আর্টিকেলটি আনপাব্লিশ করেন তবে এটি হোম পেজে এবং সার্চ ফলাফলে দেখাবে না, তবে আর্টিকেলটির সরাসরি লিঙ্ক সব সময় কাজ করবে",

0 commit comments

Comments
 (0)