Compare commits

..

No commits in common. "4d5b1692c4840629ca905f947c7e6fffc4348c34" and "35efde0db979a4cbaa609d8729694b2acf9ef541" have entirely different histories.

5 changed files with 166 additions and 355 deletions

View File

@ -26,7 +26,6 @@ export default function PostSummary({
};
return (
<>
<div
key={metadata.slug}
style={{
@ -191,36 +190,5 @@ export default function PostSummary({
</span>
</div>
</div>
{loggedIn ? (
<div
style={{
marginTop: "2rem",
padding: "0.5rem 1rem",
backgroundColor: "#333",
width: "fit-content",
userSelect: "none",
cursor: "pointer",
}}
onClick={() => router.push("/blog/write")}
>
write a post
</div>
) : (
<div
style={{
marginTop: "2rem",
padding: "0.3rem 0.5rem",
backgroundColor: "#333",
width: "fit-content",
userSelect: "none",
cursor: "pointer",
fontSize: "0.8rem",
}}
onClick={() => router.push("/blog/login")}
>
login
</div>
)}
</>
);
}

View File

@ -57,7 +57,7 @@ export async function getSummaries(
...filter,
omit: { contentMarkdown: true, contentRendered: true },
include: { tags: { select: { name: true } } },
orderBy: { publishedDate: "desc" },
orderBy: { publishedDate: "asc" },
skip: PAGE_SIZE * (pageNumber - 1),
take: PAGE_SIZE,
})
@ -79,19 +79,3 @@ export async function unpublishArticle(slug: string) {
const prisma = new PrismaClient();
await prisma.post.update({ where: { slug }, data: { is_draft: true } });
}
export async function deleteArticle(slug: string) {
const prisma = new PrismaClient();
const post = await prisma.post.delete({
where: { slug },
include: { tags: true },
});
for (const tag of post.tags) {
const postsWithTag = await prisma.post.count({
where: { tags: { some: { id: tag.id } } },
});
if (postsWithTag == 0) {
await prisma.tag.delete({ where: { id: tag.id } });
}
}
}

View File

@ -3,8 +3,7 @@
import { useRouter } from "next/navigation";
import * as Types from "../../types";
import "highlight.js/styles/github-dark.css";
import { deleteArticle, publishArticle, unpublishArticle } from "../../action";
import { useState } from "react";
import { publishArticle, unpublishArticle } from "../../action";
export default function PostDisplay({
post,
@ -14,9 +13,6 @@ export default function PostDisplay({
loggedIn: boolean;
}) {
const router = useRouter();
const [confirmDelete, setConfirmDelete] = useState(false);
return (
<>
<div
@ -155,27 +151,6 @@ export default function PostDisplay({
}}
>
{loggedIn ? (
<div style={{ display: "flex", gap: "1rem" }}>
<div
style={{
backgroundColor: "#6a6",
color: "#111",
fontSize: "0.8rem",
padding: "0.5rem",
transition: "background-color 0.3s linear",
userSelect: "none",
cursor: "pointer",
}}
onMouseOver={(e) => {
e.currentTarget.style.backgroundColor = "#8c8";
}}
onMouseOut={(e) => {
e.currentTarget.style.backgroundColor = "#6a6";
}}
onClick={() => router.push(`/blog/write/${post.slug}`)}
>
edit
</div>
<div
style={{
backgroundColor: "#a66",
@ -192,18 +167,9 @@ export default function PostDisplay({
onMouseOut={(e) => {
e.currentTarget.style.backgroundColor = "#a66";
}}
onClick={() => setConfirmDelete(true)}
onClick={() => router.push(`/blog/write/${post.slug}`)}
>
delete
</div>
<DeleteModal
open={confirmDelete}
onCancel={() => setConfirmDelete(false)}
onConfirm={async () => {
await deleteArticle(post.slug);
router.push("/blog");
}}
/>
edit
</div>
) : (
<div></div>
@ -232,96 +198,3 @@ export default function PostDisplay({
</>
);
}
function DeleteModal({
open,
onCancel,
onConfirm,
}: {
open: boolean;
onCancel: () => void;
onConfirm: () => void;
}) {
return (
<div
id="deleteModal"
style={{
display: open
? "flex"
: "none" /* Will be changed to "flex" when opened */,
position: "fixed",
top: 0,
left: 0,
width: "100%",
height: "100%",
backgroundColor: "rgba(0, 0, 0, 0.7)",
zIndex: 1000,
justifyContent: "center",
alignItems: "center",
}}
onClick={(e) => {
if (e.target == e.currentTarget) {
onCancel();
}
}}
>
<div
style={{
backgroundColor: "#222",
padding: "1.5rem",
borderRadius: "4px",
maxWidth: "400px",
width: "90%",
boxShadow: "0 0 10px rgba(0, 0, 0, 0.5)",
}}
onClick={(e) => e.stopPropagation()}
>
<h3 style={{ margin: "0 0 1rem 0", color: "#eee" }}>
Confirm Deletion
</h3>
<p style={{ marginBottom: "1.5rem", color: "#ccc" }}>
Are you sure you want to delete this post? This action cannot be
undone.
</p>
<div
style={{
display: "flex",
justifyContent: "flex-end",
gap: "0.75rem",
}}
>
<button
style={{
backgroundColor: "#a66",
color: "#fff",
border: "none",
padding: "0.5rem 1rem",
cursor: "pointer",
borderRadius: "2px",
}}
onClick={() => {
onConfirm();
}}
>
Yes, delete it
</button>
<button
style={{
backgroundColor: "#555",
color: "#fff",
border: "none",
padding: "0.5rem 1rem",
cursor: "pointer",
borderRadius: "2px",
}}
onClick={() => {
onCancel();
}}
>
Cancel
</button>
</div>
</div>
</div>
);
}

View File

@ -3,7 +3,6 @@ import "./globals.css";
import Title from "@/components/Title";
import Navbar from "@/components/Navbar";
import { bodyFont } from "@/components/fonts";
import Link from "next/link";
export const metadata: Metadata = {
title: "nrx.sh",
@ -38,28 +37,11 @@ export default function RootLayout({
maxWidth: "100vw",
padding: "2rem",
boxSizing: "border-box",
fontSize: "0.9rem",
fontSize: "1.1rem",
}}
>
{children}
</div>
<div
style={{
fontSize: "0.7rem",
marginTop: "2rem",
textAlign: "center",
color: "#888",
}}
className={bodyFont.className}
>
this site is built from scratch using <b>next.js</b> - it is&nbsp;
<Link
style={{ color: "#88f" }}
href={"https://git.nrx.sh/naresh/nrx.sh"}
>
completely open source
</Link>
</div>
</div>
</body>
</html>

View File

@ -1,6 +1,7 @@
"use client";
import { SiGitea } from "@icons-pack/react-simple-icons";
import { NotebookText } from "lucide-react";
import { SocialIcon } from "react-social-icons";
export default function Links() {
@ -16,6 +17,9 @@ export default function Links() {
gap: "1rem",
}}
>
<Link href="https://blog.nrx.sh">
<NotebookText size={26} style={{ padding: 10 }} /> My Blog {"<3"}
</Link>
<Link href="https://github.com/naresh97">
<SocialIcon network="github" bgColor="#111" /> GitHub
</Link>
@ -23,7 +27,7 @@ export default function Links() {
<SocialIcon network="linkedin" bgColor="#111" /> LinkedIn
</Link>
<Link href="https://git.nrx.sh">
<SiGitea size={40} /> Self-Hosted Git Repos
<SiGitea size={40} /> Private Git Repo
</Link>
</div>
</>