From 6283780a17faa60603816f4ea8a4b50b1cf643d7 Mon Sep 17 00:00:00 2001 From: KianBaghai Date: Wed, 3 Dec 2025 17:05:59 -0800 Subject: [PATCH] escape to leave post modal --- .../[username]/components/PostDetailModal.jsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/app/[username]/components/PostDetailModal.jsx b/client/app/[username]/components/PostDetailModal.jsx index 1727a9c..adbbdbd 100644 --- a/client/app/[username]/components/PostDetailModal.jsx +++ b/client/app/[username]/components/PostDetailModal.jsx @@ -1,15 +1,28 @@ "use client"; +import { useEffect } from "react"; import styles from "./PostDetailModal.module.css"; import PostImage from "../../feed/components/postImage"; import { useUser } from "@/context/UserContext"; // Lightweight modal to show a single post's details export default function PostDetailModal({ post, onClose }) { - if (!post) return null; - // check if this is own post const { user } = useUser(); + + useEffect(() => { + const handleEscape = (e) => { + if (e.key === "Escape") { + onClose(); + } + }; + + document.addEventListener("keydown", handleEscape); + return () => document.removeEventListener("keydown", handleEscape); + }, [onClose]); + + if (!post) return null; + const isOwnPost = post.author?._id === user?.id; const API_BASE = process.env.NEXT_PUBLIC_API_URL;