diff --git a/frontend/src/pages/organizations/[id]/discussion/[local_id].tsx b/frontend/src/pages/organizations/[id]/discussion/[local_id].tsx index db86281..6386992 100644 --- a/frontend/src/pages/organizations/[id]/discussion/[local_id].tsx +++ b/frontend/src/pages/organizations/[id]/discussion/[local_id].tsx @@ -22,6 +22,8 @@ import { useTranslation } from "react-i18next"; import { FaReply } from "react-icons/fa"; import { LuArrowUpToLine } from "react-icons/lu"; import { FiShare2 } from "react-icons/fi"; +import { BeatLoader } from 'react-spinners'; +import InfiniteScroll from "react-infinite-scroller"; import NewDiscussionDrawer from "@/components/new-discussion-drawer"; import CommentList from "@/components/comment-list"; import OrganizationContext from "@/contexts/organization"; @@ -36,7 +38,6 @@ import { editComment } from "@/services/discussion"; import { shareContent } from "@/utils/share"; -import InfiniteScroll from "react-infinite-scroller"; const DiscussionTopicPage = () => { const router = useRouter(); @@ -54,7 +55,9 @@ const DiscussionTopicPage = () => { const [hasMore, setHasMore] = useState(true); const [isLoading, setIsLoading] = useState(false); const [isTitleVisible, setIsTitleVisible] = useState(true); + const [mainAreaHeight, setMainAreaHeight] = useState("80vh"); const titleRef = useRef(null); + const mainAreaBoxRef = useRef(null); const { isOpen, onOpen, onClose } = useDisclosure(); @@ -65,14 +68,27 @@ const DiscussionTopicPage = () => { }, { threshold: 0.1 } ); - if (titleRef.current) { - observer.observe(titleRef.current); - } + if (titleRef.current) { observer.observe(titleRef.current); } return () => { - if (titleRef.current) { - observer.unobserve(titleRef.current); + if (titleRef.current) { observer.unobserve(titleRef.current); } + }; + }, []); + + useEffect(() => { + const updateMainAreaHeight = () => { + if (mainAreaBoxRef.current) { + const topOffset = mainAreaBoxRef.current.getBoundingClientRect().top; + const newHeight = `calc(100vh - ${topOffset}px - 24px)`; // 24px for py={6} as parent Flex in MainLayout + setMainAreaHeight(newHeight); } }; + updateMainAreaHeight(); // Initial height + + const resizeObserver = new ResizeObserver(() => { updateMainAreaHeight();}); + if (mainAreaBoxRef.current) { + resizeObserver.observe(document.body); + } + return () => { resizeObserver.disconnect(); } }, []); const breadcrumbs = [ @@ -255,7 +271,12 @@ const DiscussionTopicPage = () => { } setComments( comments.map((c) => - c.local_id === comment.local_id ? { ...c, content: newContent } : c + c.local_id === comment.local_id + ? { + ...c, + content: newContent, + edited: true + } : c ) ); }; @@ -266,12 +287,22 @@ const DiscussionTopicPage = () => { - + - + {topic?.title} { hasMore={hasMore} useWindow={false} initialLoad={false} - getScrollParent={() => document.getElementById('scrollableDiv')} + getScrollParent={() => document.getElementById('mainAreaBox')} loader={ - - {t("DiscussionTopicPage.loading")} - } - > + + + }> { colSpan={{ base: 0, md: 1 }} display={{ base: "none", md: "block" }} > - +