Skip to content

Commit 05038f0

Browse files
committed
모바일글쓰기 수정
1 parent 5636a66 commit 05038f0

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

src/domains/community/components/post-info/PostInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function PostInfo({
1717
}: Props) {
1818
return (
1919
<ul
20-
className="flex font-light sm:gap-3 gap-1 sm:text-sm text-xs text-gray"
20+
className="flex font-light sm:gap-3 gap-1 sm:text-sm text-[10px] text-gray"
2121
aria-label="게시글 정보"
2222
>
2323
{hasUserName && (

src/domains/community/write/CompleteBtn.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@ import Button from '@/shared/components/button/Button';
33
type Props = {
44
mode: 'edit' | 'create';
55
setEditDone: (value: boolean) => void;
6+
isLoading?: boolean;
67
};
78

8-
function CompleteBtn({ mode, setEditDone }: Props) {
9+
function CompleteBtn({ mode, setEditDone, isLoading = false }: Props) {
910
return (
1011
<div className="w-full flex items-center justify-end mt-10">
1112
<Button
1213
type={mode === 'create' ? 'submit' : 'button'}
1314
size="default"
1415
color="default"
16+
disabled={isLoading}
1517
onClick={async () => {
1618
setEditDone(true);
1719
}}
1820
>
19-
{mode === 'create' ? '올리기' : '수정하기'}
21+
{isLoading
22+
? mode === 'create'
23+
? '올리는 중...'
24+
: '수정 중...'
25+
: mode === 'create'
26+
? '올리기'
27+
: '수정하기'}
2028
</Button>
2129
</div>
2230
);

src/domains/community/write/WriteSection.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function WriteSection({ mode, postId }: Props) {
153153
payload.append('post', postBlob);
154154

155155
try {
156+
setIsLoading(true);
156157
const res = await fetch(`${getApi}/posts`, {
157158
method: 'POST',
158159
credentials: 'include',
@@ -161,10 +162,17 @@ function WriteSection({ mode, postId }: Props) {
161162

162163
if (res.ok) {
163164
router.push('/community');
165+
} else {
166+
// 서버 에러 응답 처리
167+
const errorData = await res.json().catch(() => ({}));
168+
const errorMessage = errorData.message || `서버 오류가 발생했습니다. (${res.status})`;
169+
toastError(errorMessage);
164170
}
165171
} catch (err) {
166172
console.error('글작성 폼 작성 에러', err);
167-
return;
173+
toastError('네트워크 오류가 발생했습니다. 다시 시도해주세요.');
174+
} finally {
175+
setIsLoading(false);
168176
}
169177
};
170178

@@ -275,14 +283,14 @@ function WriteSection({ mode, postId }: Props) {
275283
e.preventDefault();
276284
};
277285

278-
if (isEditLoading) <Spinner />;
286+
if (isEditLoading) return <Spinner />;
279287

280-
if (isLoading) <DetailSkeleton />;
288+
if (isLoading) return <DetailSkeleton />;
281289

282290
return (
283291
<>
284292
<form onSubmit={mode === 'create' ? handleSubmit : handleEditSubmit}>
285-
<CompleteBtn mode={mode} setEditDone={setEditDone} />
293+
<CompleteBtn mode={mode} setEditDone={setEditDone} isLoading={isLoading || isEditLoading} />
286294
<section>
287295
<FormTitle formData={formData} setFormData={setFormData} />
288296
<Category formData={formData} setFormData={setFormData} />

src/domains/community/write/image-upload/ImageInput.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ function ImageInput({ uploadedFile, onAddImage }: Props) {
1616

1717
const newFiles = Array.from(newFileList);
1818

19+
// 파일을 선택하지 않고 취소한 경우 조용히 리턴
20+
if (newFiles.length === 0) return;
21+
1922
try {
23+
// 파일 크기 검증 (모바일 최적화)
24+
const maxSize = 5 * 1024 * 1024; // 5MB
25+
const oversizedFiles = newFiles.filter((file) => file.size > maxSize);
26+
if (oversizedFiles.length > 0) {
27+
toastError('파일 크기는 5MB 이하로 업로드해주세요.');
28+
return;
29+
}
30+
2031
const totalLength = uploadedFile.length + newFiles.length;
2132
if (totalLength > 10) {
2233
toastError('최대 10개 파일까지 업로드할 수 있어요.');
@@ -49,7 +60,7 @@ function ImageInput({ uploadedFile, onAddImage }: Props) {
4960
<>
5061
<label
5162
htmlFor="fileInput"
52-
className="border-3 border-dashed shrink-0 border-gray-light w-[100px] h-[100px] sm:w-[80px] sm:h-[80px] rounded-xl cursor-pointer bg-gray-dark flex flex-col gap-3 items-center justify-center hover:bg-gray-dark/70"
63+
className="border-3 border-dashed shrink-0 border-gray-light w-[100px] h-[100px] sm:w-[80px] sm:h-[80px] rounded-xl cursor-pointer bg-gray-dark flex flex-col gap-3 items-center justify-center hover:bg-gray-dark/70 active:bg-gray-dark/50 touch-manipulation"
5364
>
5465
<ImageBox />
5566
<div className="flex items-center md:text-md text-sm">
@@ -61,9 +72,10 @@ function ImageInput({ uploadedFile, onAddImage }: Props) {
6172
<input
6273
type="file"
6374
id="fileInput"
64-
hidden
65-
accept="image/*"
75+
className="sr-only"
76+
accept="image/*,image/jpeg,image/jpg,image/png,image/webp"
6677
multiple
78+
capture="environment"
6779
onChange={handleInputChange}
6880
/>
6981
</>

src/domains/community/write/image-upload/UploadedImage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DeleteIcon from '@/shared/assets/icons/close_20.svg';
55
import React, { Dispatch, SetStateAction, useEffect, useRef } from 'react';
66
import gsap from 'gsap';
77
import { UploadedItem } from '@/domains/recipe/types/types';
8+
import { useToast } from '@/shared/hook/useToast';
89

910
type Props = {
1011
uploadedFile: UploadedItem[];
@@ -14,6 +15,7 @@ type Props = {
1415
function UploadedImage({ uploadedFile, setUploadedFile }: Props) {
1516
const imageRefs = useRef<HTMLElement[]>([]);
1617
const prevLength = useRef(0);
18+
const { toastError } = useToast();
1719

1820
useEffect(() => {
1921
const isAdded = uploadedFile.length > prevLength.current;
@@ -71,6 +73,7 @@ function UploadedImage({ uploadedFile, setUploadedFile }: Props) {
7173
onError={(e) => {
7274
// 402 에러 등으로 이미지 로딩 실패 시 fallback 이미지 사용
7375
e.currentTarget.src = '/CocktailDrop.webp';
76+
toastError('이미지가 너무 크거나 손상되어 기본 이미지로 대체됩니다.');
7477
}}
7578
/>
7679
<figcaption className="sr-only">업로드된 이미지입니다</figcaption>

src/domains/main/cocktailDrop/CocktailDrop.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function CocktailDrop({ isDesktop = false }: CocktailDropProps) {
5555

5656
// 내부에서 사용
5757
const finalY = getFinalY(window.innerWidth);
58-
console.log('finalY', finalY);
58+
5959
gsap.fromTo(
6060
logoRef.current,
6161
{ y: -300, opacity: 0 },

0 commit comments

Comments
 (0)