Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: postDetail에서의 이미지뷰어 추가 #20

Open
wants to merge 1 commit into
base: dev_webview
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/pages/board/postDetail/PostDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from 'mobx-react-lite';
import { useEffect, useRef } from 'react';
import { useEffect, useRef, useState } from 'react';
import { Route, Switch, useParams } from 'react-router-dom';
import ImageViewer from 'react-simple-image-viewer';

import {
CommentInput,
Expand Down Expand Up @@ -31,6 +32,14 @@ const PostDetailPage: React.FC = observer(() => {
const { fetch, reset, setScreenRef, boardName, post } = usePageUiStore<PageUiStore.PostDetail>();
const ref = useRef<HTMLDivElement | null>(null);

const [visible, setVisible] = useState(false);
function openImageViewer() {
setVisible(true);
}
function closeImageViewer() {
setVisible(false);
}

useEffect(() => {
fetch(postId);
return () => reset();
Expand All @@ -55,6 +64,7 @@ const PostDetailPage: React.FC = observer(() => {
<PostAuthor model={post.author} date={post.formatedCreatedAt} />
<div className="ql-snow">
<PostContent
onClick={openImageViewer}
className="ql-editor"
dangerouslySetInnerHTML={{ __html: post.content }}
/>
Expand All @@ -67,6 +77,22 @@ const PostDetailPage: React.FC = observer(() => {
</BodyScreen>
</PageBody>
<CommentInput />

{console.log(post.content)}

{visible ? (
<ImageViewer
backgroundStyle={{ zIndex: 10001 }}
src={[
`${(document.querySelector('.ql-editor p img') as HTMLImageElement | null)?.src}`,
// TODO : post.content에서 가져와야됨
]}
currentIndex={0}
disableScroll={false}
closeOnClickOutside={false}
onClose={closeImageViewer}
/>
) : null}
</>
) : (
<>{/* TODO: 페이지 스켈레톤 */}</>
Expand Down