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

본문과 내용에 사진을 추가할 때 안될 때가 있다 #398

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions frontend/src/api/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@utils/fetch';

const BASE_URL = process.env.VOTOGETHER_BASE_URL ?? '';
const MOCK_URL = process.env.VOTOGETHER_MOCKING_URL;

export const transformPostResponse = (post: PostInfoResponse): PostInfo => {
return {
Expand Down Expand Up @@ -75,7 +74,7 @@ export const editPost = async (postId: number, updatedPost: FormData) => {
};

export const deletePost = async (postId: number) => {
return await deleteFetch(`${MOCK_URL}/posts/${postId}`);
return await deleteFetch(`${BASE_URL}/posts/${postId}`);
};

export const setEarlyClosePost = async (postId: number) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReportRequest } from '@type/report';

import { postFetch } from '@utils/fetch';

const BASE_URL = process.env.VOTOGETHER_MOCKING_URL;
const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const reportContent = async (reportData: ReportRequest) => {
return await postFetch(`${BASE_URL}/report`, reportData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent } from 'react';
import { ChangeEvent, MutableRefObject } from 'react';

import { Size } from '@type/style';

Expand All @@ -10,12 +10,13 @@ interface ContentImageSectionProps {
size: Size;
contentImageHook: {
contentImage: string;
contentInputRef: MutableRefObject<HTMLInputElement | null>;
removeImage: () => void;
handleUploadImage: (event: ChangeEvent<HTMLInputElement>) => void;
};
}
export default function ContentImageSection({ contentImageHook, size }: ContentImageSectionProps) {
const { contentImage, removeImage, handleUploadImage } = contentImageHook;
const { contentImage, contentInputRef, removeImage, handleUploadImage } = contentImageHook;

return (
<>
Expand All @@ -39,6 +40,7 @@ export default function ContentImageSection({ contentImageHook, size }: ContentI
</S.Label>
<S.FileInput
id="content-image-upload"
ref={contentInputRef}
type="file"
accept="image/*"
onChange={handleUploadImage}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/hooks/useContentImage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ChangeEvent, useState } from 'react';
import { ChangeEvent, useRef, useState } from 'react';

import { MAX_FILE_SIZE } from '@components/PostForm/constants';

export const useContentImage = (imageUrl: string = '') => {
const [contentImage, setContentImage] = useState(imageUrl);
const contentInputRef = useRef<HTMLInputElement | null>(null);

const removeImage = () => {
setContentImage('');
if (contentInputRef.current) contentInputRef.current.value = '';
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 바꾸면 본문 사진에서는 해결이 됩니다 🔥🔥🔥

  const removeImage = () => {
    setContentImage('');
    if (contentInputRef.current) {
      contentInputRef.current.value = ''; // 파일 선택 창을 초기화하는 부분
      contentInputRef.current.files = null; // 파일 정보를 초기화하는 부분
    }
  };


const handleUploadImage = (event: ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -34,5 +36,5 @@ export const useContentImage = (imageUrl: string = '') => {
};
};

return { contentImage, removeImage, handleUploadImage };
return { contentImage, contentInputRef, removeImage, handleUploadImage };
};
Loading