a18hvcryt: Delete the signed-in person's own post from its menu
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { SESSION_COOKIE } from "@/lib/cookie";
|
||||
import { deletePost } from "@/lib/post-delete";
|
||||
|
||||
// DELETE /api/posts/:id -> feed DELETE /api/v1/posts/{id}
|
||||
// 401 { error: "sign_in" } without a session. Returns { ok: true } on success.
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
type Ctx = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function DELETE(req: NextRequest, ctx: Ctx) {
|
||||
const sessionId = req.cookies.get(SESSION_COOKIE)?.value;
|
||||
const { id } = await ctx.params;
|
||||
const result = await deletePost(sessionId, id);
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ error: result.error }, { status: result.status });
|
||||
}
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -88,6 +88,7 @@ export async function GET(req: NextRequest) {
|
||||
name: session.person.name,
|
||||
email: session.person.email,
|
||||
pictureUrl: session.person.pictureUrl,
|
||||
feedUserId: session.person.feedUserId ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -61,3 +61,11 @@ button:disabled { opacity: .5; cursor: not-allowed; }
|
||||
.comment-form button { margin: 0; }
|
||||
.link-btn { background: transparent; color: inherit; text-decoration: underline; padding: 0; margin: 0; font-size: inherit; width: auto; }
|
||||
.comments-toggle { background: transparent; color: var(--grey); padding: 4px 8px; margin: 0; font-size: 14px; font-weight: 400; width: auto; }
|
||||
|
||||
.post-menu { position: relative; margin-left: auto; }
|
||||
.menu-btn { margin: 0; padding: 2px 10px; background: transparent; color: var(--grey); border-radius: 8px; font-size: 18px; line-height: 1; letter-spacing: 1px; }
|
||||
.menu { position: absolute; right: 0; top: 100%; z-index: 5; display: flex; flex-direction: column; gap: 2px; min-width: 150px; padding: 6px; background: #fff; border: 1px solid #e3e3e3; border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
|
||||
.menu button { margin: 0; text-align: left; background: transparent; color: inherit; padding: 6px 8px; border-radius: 6px; font-size: 14px; font-weight: 400; }
|
||||
.menu button:hover { background: #f4f4f4; }
|
||||
.menu .menu-danger { color: #a8141b; }
|
||||
.menu-ask { font-size: 13px; color: var(--grey); padding: 4px 8px; }
|
||||
|
||||
Reference in New Issue
Block a user