Skip to content

Commit 196d8ea

Browse files
authored
feat: 랜덤 이미지 사이즈 변경
2 parents ecd354d + f11398c commit 196d8ea

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

frontend/src/components/ImageUploader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Icon } from '@iconify/react';
2+
import heic2any from 'heic2any';
23
import { useRecoilState, useSetRecoilState } from 'recoil';
34
import { isImageBright, previewImage } from '../atom';
4-
import heic2jpeg from 'heic2any';
5-
import heic2any from 'heic2any';
65

76
const ImageUploader = () => {
87
const setImageSrc = useSetRecoilState(previewImage);

frontend/src/components/UnsplashUploader.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { Icon } from '@iconify/react';
2-
import { useEffect, useMemo, useRef, useState } from 'react';
3-
import { useRecoilState, useRecoilValue } from 'recoil';
4-
import { isImageBright, previewImage, ratioAtom } from '../atom';
2+
import { useEffect, useRef, useState } from 'react';
3+
import { useRecoilState } from 'recoil';
4+
import { isImageBright, previewImage } from '../atom';
55

6-
const HEIGHT = 280;
6+
const FIXED_RATIO = 16 / 9;
7+
const FIXED_HEIGHT = 450;
8+
const FIXED_WIDTH = FIXED_HEIGHT * FIXED_RATIO; // 고정 값으로 이미지 랜더링
9+
const RANDOM_URL = `https://picsum.photos/${FIXED_WIDTH}/${FIXED_HEIGHT}`; //
710

811
const UnsplashUploader = () => {
912
let timer: NodeJS.Timer | null = null;
1013
const [imageSrc, setImageSrc] = useRecoilState(previewImage);
1114
const [isBright, setIsBright] = useRecoilState(isImageBright);
12-
const previewRatio = useRecoilValue(ratioAtom);
1315
const [isLoading, setIsLoading] = useState<boolean>(false);
1416
const mounted = useRef(false);
15-
const width = useMemo(() => Math.round(HEIGHT * previewRatio), [previewRatio]);
1617

1718
const getRandomImage = async () => {
1819
if (!timer) {
19-
const response = await fetch(`https://picsum.photos/${width}/${HEIGHT}?random=${Date.now()}`);
20+
const response = await fetch(`${RANDOM_URL}?random=${Date.now()}`);
2021
setIsLoading(true);
2122
timer = setTimeout(function () {
2223
timer = null;
@@ -25,13 +26,17 @@ const UnsplashUploader = () => {
2526
}, 1100);
2627
}
2728
};
28-
const brigthControl = () => {
29+
30+
const brightControl = () => {
2931
setIsBright((prev) => !prev);
3032
};
33+
3134
useEffect(() => {
3235
if (imageSrc === '') {
33-
fetch(`https://picsum.photos/${width}/${HEIGHT}?random=${Date.now()}`).then((response) => {
36+
setIsLoading(true);
37+
fetch(`${RANDOM_URL}?random=${Date.now()}`).then((response) => {
3438
setImageSrc(response.url);
39+
setIsLoading(false);
3540
});
3641
}
3742
mounted.current = true;
@@ -50,7 +55,7 @@ const UnsplashUploader = () => {
5055
</div>
5156
</button>
5257
<label className={`${isBright ? 'text-darken' : 'text-muted'} flex justify-start items-center mt-3`}>
53-
<input defaultChecked={!isBright} className="h-4 w-4" type="checkbox" onClick={brigthControl} />
58+
<input defaultChecked={!isBright} className="h-4 w-4" type="checkbox" onClick={brightControl} />
5459
<span className="ml-[10px]">배경 어둡게</span>
5560
</label>
5661
</div>

0 commit comments

Comments
 (0)