Skip to content
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
161 changes: 79 additions & 82 deletions src/components/Result/CaptureImage.tsx
Original file line number Diff line number Diff line change
@@ -1,91 +1,88 @@
// import { useRef } from 'react'
import { useRef } from 'react'

// type CaptureImageItem = {
// id: number
// src: string // 서버 URL or URL.createObjectURL
// label?: string
// uploading?: boolean // 업로드 진행 표시용(선택)
// }
type CaptureImageItem = {
id: number
src: string // 서버 URL or URL.createObjectURL
label?: string
uploading?: boolean // 업로드 진행 표시용(선택)
}

// type CaptureImageProps = {
// images: CaptureImageItem[]
// showUploadButton?: boolean
// onPickFiles?: (files: FileList) => void // 부모에서 업로드 처리
// }
type CaptureImageProps = {
images: CaptureImageItem[]
showUploadButton?: boolean
onPickFiles?: (files: FileList) => void // 부모에서 업로드 처리
}

const CaptureImage = () =>
// {
// // images,
// // showUploadButton = false,
// // onPickFiles,
// }: CaptureImageProps,
{
// const inputRef = useRef<HTMLInputElement>(null)
const CaptureImage = ({
images,
showUploadButton = false,
onPickFiles,
}: CaptureImageProps) => {
const inputRef = useRef<HTMLInputElement>(null)

return (
<></>
// <div className="bg-white rounded-lg shadow-md p-4 mt-4">
// <div className="flex items-center justify-between mb-2">
// <h3 className="text-center font-bold text-lg flex-1">
// 촬영된 사진을 확인해보세요!
// </h3>
return (
<div className="bg-white rounded-lg shadow-md p-4 mt-4">
<div className="flex items-center justify-between mb-2">
<h3 className="text-center font-bold text-lg flex-1">
촬영된 사진을 확인해보세요!
</h3>

// {showUploadButton && (
// <>
// <button
// className="ml-4 shrink-0 px-3 py-1.5 text-sm rounded-lg border border-gray-300"
// onClick={() => inputRef.current?.click()}
// >
// 사진 추가
// </button>
// <input
// ref={inputRef}
// type="file"
// accept="image/*"
// multiple
// className="hidden"
// onChange={(e) => e.target.files && onPickFiles?.(e.target.files)}
// />
// </>
// )}
// </div>
{showUploadButton && (
<>
<button
className="ml-4 shrink-0 px-3 py-1.5 text-sm rounded-lg border border-gray-300"
onClick={() => inputRef.current?.click()}
>
사진 추가
</button>
<input
ref={inputRef}
type="file"
accept="image/*"
multiple
className="hidden"
onChange={(e) => e.target.files && onPickFiles?.(e.target.files)}
/>
</>
)}
</div>

// {images.length === 0 ? (
// <div className="py-8 text-center text-sm text-gray-500">
// 아직 업로드된 사진이 없습니다.
// </div>
// ) : (
// <div className="grid grid-cols-2 sm:grid-cols-2 gap-4 justify-items-center">
// {images.map((img) => (
// <div key={img.id} className="flex flex-col items-center w-24">
// <div className="relative">
// <img
// src={img.src}
// alt={img.label ?? '촬영 사진'}
// className="rounded-full w-24 h-24 aspect-square object-cover"
// onError={(e) =>
// ((e.currentTarget as HTMLImageElement).style.visibility =
// 'hidden')
// }
// />
// {img.uploading && (
// <div className="absolute inset-0 rounded-full bg-black/30 flex items-center justify-center text-white text-xs">
// 업로드 중…
// </div>
// )}
// </div>
// {img.label && (
// <p className="text-base text-center font-bold mt-2">
// {img.label}
// </p>
// )}
// </div>
// ))}
// </div>
// )}
// </div>
)
}
{images.length === 0 ? (
<div className="py-8 text-center text-sm text-gray-500">
아직 업로드된 사진이 없습니다.
</div>
) : (
<div className="grid grid-cols-2 sm:grid-cols-2 gap-4 justify-items-center">
{images.map((img) => (
<div key={img.id} className="flex flex-col items-center w-24">
<div className="relative">
<img
src={img.src}
alt={img.label ?? '촬영 사진'}
className="rounded-full w-24 h-24 aspect-square object-cover"
onError={(e) => {
;(e.currentTarget as HTMLImageElement).style.visibility =
'hidden'
}}
/>
{img.uploading && (
<div className="absolute inset-0 rounded-full bg-black/30 flex items-center justify-center text-white text-xs">
업로드 중…
</div>
)}
</div>
{img.label && (
<p className="text-base text-center font-bold mt-2">
{img.label}
</p>
)}
</div>
))}
</div>
)}
</div>
)
}

export default CaptureImage

Expand Down
6 changes: 3 additions & 3 deletions src/pages/ResultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import API from '../apis/api'
import ScalpStatusCard from '../components/Result/ScalpStatusCard'
import ScalpRadarChart from '../components/Result/ScalpRadarChart'
import StatusSlider from '../components/Result/StatusSlider'
// import CaptureImage from '../components/Result/CaptureImage'
import ProductRecommendButton from '../components/Result/ProductRecommendButton'
import CaptureImage from '../components/Result/CaptureImage'

type Status = '양호' | '보통' | '심각'

Expand Down Expand Up @@ -67,7 +67,7 @@ const ResultPage = () => {
const [displayName, setDisplayName] = useState<string>('회원')

// 이미지
const [, setImages] = useState<ImageItem[]>(() => {
const [images, setImages] = useState<ImageItem[]>(() => {
return (
state.images ??
safeParse<ImageItem[]>(sessionStorage.getItem(SKEY_IMAGES)) ?? [
Expand Down Expand Up @@ -203,7 +203,7 @@ const ResultPage = () => {
</div>
)}

{/* <CaptureImage images={images} /> */}
<CaptureImage images={images} />
</div>
)
}
Expand Down