Content.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use client';
  2. import './style.scss';
  3. import { useEffect } from 'react';
  4. import boardMeta from '@/types/forum/boardMeta';
  5. type Props = {
  6. boardMeta: boardMeta;
  7. content: string;
  8. }
  9. export default function Content({ boardMeta, content }: Props)
  10. {
  11. useEffect(() => {
  12. const handler = async (e: MouseEvent) => {
  13. const target = e.target as HTMLElement;
  14. // 파일 다운로드
  15. const file = target.closest('section.file-embed') as HTMLElement;
  16. if (file && file.dataset.uuid) {
  17. window.location.href = process.env.NEXT_PUBLIC_API_URL + `/api/forum/post/file/${file.dataset.uuid}`;
  18. }
  19. // 링크 클릭
  20. const anchor = target.closest('a[data-uuid]') as HTMLAnchorElement;
  21. if (anchor && anchor.dataset.uuid) {
  22. e.preventDefault();
  23. // 무조건 URL 새창 열림이라면 _blank 속성 강제 적용
  24. window.open((process.env.NEXT_PUBLIC_API_URL + `/api/forum/post/link/${anchor.dataset.uuid}`), boardMeta.view.allowContentLinkTargetBlank ? '_blank' : '_self');
  25. }
  26. }
  27. document.addEventListener('click', handler);
  28. return () => {
  29. document.removeEventListener('click', handler);
  30. }
  31. }, []);
  32. return (
  33. <article dangerouslySetInnerHTML={{ __html: content }} className='whitespace-normal break-words'></article>
  34. );
  35. }