-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Feature] - 여행기 장소 이미지 업로드 중일 경우, spinner를 보여주도록 리팩터링 #332
Changes from all commits
4ab4c20
1d84ffd
44fe3ac
9e5e6b0
93d54df
08064b6
bb9c29f
8a7f161
69618ab
48353a5
e9166e0
b5026a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import React from "react"; | ||
|
||
import Spinner from "@components/common/Spinner/Spinner"; | ||
|
||
import { useDragScroll } from "@hooks/index"; | ||
|
||
import * as S from "./MultiImageUpload.styled"; | ||
|
||
const MAX_PICTURES_COUNT = 10; | ||
|
||
interface MultiImageUploadProps extends React.ComponentPropsWithoutRef<"div"> { | ||
previewUrls: string[]; | ||
previewImageStates: { url: string; isLoading: boolean }[]; | ||
fileInputRef: React.RefObject<HTMLInputElement>; | ||
onImageChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
onDeleteImage: (index: number) => void; | ||
onButtonClick: () => void; | ||
} | ||
|
||
const MultiImageUpload = ({ | ||
previewUrls, | ||
previewImageStates, | ||
fileInputRef, | ||
onImageChange, | ||
onDeleteImage, | ||
|
@@ -24,7 +26,35 @@ const MultiImageUpload = ({ | |
}: MultiImageUploadProps) => { | ||
const { scrollRef, onMouseDown, onMouseUp, onMouseMove, isDragging } = useDragScroll(); | ||
|
||
const hasPictures = previewUrls.length !== 0; | ||
const hasPictures = previewImageStates.length !== 0; | ||
|
||
const renderImageOrSpinner = (imageState: { url: string; isLoading: boolean }, index: number) => ( | ||
<S.MultiImageUploadPictureWrapper key={index}> | ||
<S.MultiImageUploadDeleteButton onClick={() => onDeleteImage(index)}> | ||
<svg | ||
width="11" | ||
height="11" | ||
viewBox="0 0 11 11" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M1.1002 11L0 9.9L4.40079 5.5L0 1.1L1.1002 0L5.50098 4.4L9.90177 0L11.002 1.1L6.60118 5.5L11.002 9.9L9.90177 11L5.50098 6.6L1.1002 11Z" | ||
fill="#616161" | ||
/> | ||
</svg> | ||
</S.MultiImageUploadDeleteButton> | ||
{imageState.isLoading ? ( | ||
<Spinner variants="circle" size={40} /> | ||
) : ( | ||
<S.MultiImageUploadPicture | ||
src={imageState.url} | ||
alt={`업로드된 이미지 ${index + 1}`} | ||
draggable="false" | ||
/> | ||
)} | ||
</S.MultiImageUploadPictureWrapper> | ||
); | ||
Comment on lines
+31
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존에 has로 나눠지던 거 하나로 추상화한 거 좋네요! |
||
|
||
return ( | ||
<S.MultiImageUploadContainer {...props}> | ||
|
@@ -51,7 +81,7 @@ const MultiImageUpload = ({ | |
</S.MultiImageUploadSVGWrapper> | ||
|
||
<p> | ||
{previewUrls.length} / {MAX_PICTURES_COUNT} | ||
{previewImageStates.length} / {MAX_PICTURES_COUNT} | ||
</p> | ||
Comment on lines
83
to
85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사소한거긴한데 Text detailBold 컴포넌트 이용하면 좋을 거 같다는 생각이 듭니다! 제 tag merge 되고 바꾸면 더 좋을 거 같네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 머지 되고 반영할 부분들 찾아서 반영하면 좋을거같슴다~ |
||
</S.MultiImageUploadPictureAddButton> | ||
<S.MultiImageUploadHiddenInput | ||
|
@@ -72,29 +102,7 @@ const MultiImageUpload = ({ | |
onMouseLeave={onMouseUp} | ||
$isDragging={isDragging} | ||
> | ||
{previewUrls.map((previewUrl, index) => ( | ||
<S.MultiImageUploadPictureWrapper key={previewUrl}> | ||
<S.MultiImageUploadDeleteButton onClick={() => onDeleteImage(index)}> | ||
<svg | ||
width="11" | ||
height="11" | ||
viewBox="0 0 11 11" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M1.1002 11L0 9.9L4.40079 5.5L0 1.1L1.1002 0L5.50098 4.4L9.90177 0L11.002 1.1L6.60118 5.5L11.002 9.9L9.90177 11L5.50098 6.6L1.1002 11Z" | ||
fill="#616161" | ||
/> | ||
</svg> | ||
</S.MultiImageUploadDeleteButton> | ||
<S.MultiImageUploadPicture | ||
src={previewUrl} | ||
alt={`업로드된 이미지 ${index + 1}`} | ||
draggable="false" | ||
/> | ||
</S.MultiImageUploadPictureWrapper> | ||
))} | ||
{previewImageStates.map((imageState, index) => renderImageOrSpinner(imageState, index))} | ||
</S.ImageScrollContainer> | ||
</S.MultiImageUploadPictureContainer> | ||
)} | ||
|
@@ -138,7 +146,7 @@ const MultiImageUpload = ({ | |
</S.MultiImageUploadSVGWrapper> | ||
|
||
<p> | ||
{previewUrls.length} / {MAX_PICTURES_COUNT} | ||
{previewImageStates.length} / {MAX_PICTURES_COUNT} | ||
</p> | ||
Comment on lines
148
to
150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 얘도요! |
||
</S.MultiImageUploadPictureAddButton> | ||
<S.MultiImageUploadHiddenInput | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,32 @@ const meta = { | |
viewport: { | ||
defaultViewport: "desktop", | ||
}, | ||
docs: { | ||
description: { | ||
component: | ||
"두 가지 variants(tturi, circle)가 있는 Spinner 컴포넌트이며, tturi의 경우 size를 70~100 정도로 사용해야합니다.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 세심한 description 🥹 👍 |
||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
variants: { | ||
options: ["tturi", "circle"], | ||
control: "select", | ||
}, | ||
size: { | ||
control: "range", | ||
}, | ||
}, | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof Spinner>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = {}; | ||
export const Default: Story = { | ||
args: { | ||
variants: "tturi", | ||
size: 100, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type SpinnerVariants = "tturi" | "circle"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MAX_IMAGE_UPLOAD_COUNT = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IconButton,Icon 컴포넌트 없을 때 svg 크기 조절이 안되서 svg 이미지를 이렇게 하드코딩으로 넣어놨었는데요..! 😅
지금은 지니가 잘 만들어준 IconButton,Icon 컴포넌트가 있기때문에 IconButton 사용하면 코드가 훨 간결해 질 것 같습니다!
iconType="x-icon"
으로 하시면 될거에요There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 안그래도 적용해보려고 시도해보았슴다,, ㅜㅜ 분명 storybook이나 다른 앱에선 아이콘 조절이 잘 되는데, 여기서는 이미지 크기가 깨지더라구여.. ㅜ