Skip to content

[URH-71] useImagePreSetup 신규 #58

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

Merged
merged 9 commits into from
Sep 9, 2024
Merged

Conversation

foresec
Copy link
Collaborator

@foresec foresec commented Aug 30, 2024

👾 Pull Request

  • 상태: 신규

1️⃣ Spec

  • 여러개의 이미지 파일들을 받아 미리보기를 제공하며, WebP 형식으로의 변환 및 품질을 조절할 수 있는 훅
  • API 통신 등의 로직 전 이미지 파일 관리

2️⃣ 변경 사항

  • 없음

3️⃣ 예시 코드

  const { previewUrls, isLoading, isError, webpImages } = useImagePreSetup({
    imageFiles: selectedFiles,
    convertToWebP: true,
    webPQuality: 0.5,
  });

props

  • imageFiles : 처리할 이미지 파일 배열
  • convertToWebP : WebP 형식으로 변환 여부
  • webPQuality : WebP 형식으로 변환할 때의 품질 설정값(0~1, Default=0.8)

returns

  • previewUrls : 이미지 파일의 미리보기 URL 배열
  • isLoading : 로딩 여부
  • isError : 오류 발생 여부
  • webpImages : WebP로 변환된 이미지 blob 배열. 변환하지 않은 경우 null
  • originalImages : 원본 이미지 파일 배열(props의 imageFIles와 동일)

사용 예시

import React, { useState } from 'react';
import useImagePreSetup from './hooks/useImagePreSetup';

function App() {
  const [selectedFiles, setSelectedFiles] = useState<File[]>([]);

  const { previewUrls, isLoading, isError, webpImages } = useImagePreSetup({
    imageFiles: selectedFiles,
    convertToWebP: true,
    webPQuality: 0.5,
  });

  const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const files = Array.from(event.target.files || []);
    setSelectedFiles(files);
  };

  return (
    <div>
      <input
        type="file"
        accept="image/*"
        multiple
        onChange={handleFileChange}
      />
      {isLoading && <p>Loading...</p>}
      {isError && <p>이미지 처리  오류가 발생했습니다.</p>}

      {previewUrls.length > 0 && (
        <div>
          <h2>Image Previews</h2>
          {previewUrls.map((url, idx) => (
            <div key={idx}>
              <img
                src={url || undefined}
                style={{ maxWidth: '300px', maxHeight: '300px' }}
              />
            </div>
          ))}
        </div>
      )}
    </div>
  );
}

export default App;

4️⃣ 관련 문서 (선택 사항)

@foresec foresec self-assigned this Aug 30, 2024
@Choozii Choozii requested review from bicochan and Choozii August 30, 2024 14:09
Copy link
Member

@bicochan bicochan left a comment

Choose a reason for hiding this comment

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

고생하셨어요 소현 님👍🏻✨ 리뷰 확인 부탁드려요!

Copy link
Member

@bicochan bicochan left a comment

Choose a reason for hiding this comment

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

승인이 너무 늦어져서 죄송합니다 ㅠㅠ
추가적인 내용은 다음 리팩토링 때 진행해 보시죠! 고생하셨어요 소현 님!👍🏻

@foresec foresec merged commit 930c483 into master Sep 9, 2024
2 checks passed
@foresec foresec deleted the URH-71/use-image-pre-setup branch September 9, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants