Skip to content

Commit

Permalink
Merge pull request #209 from Team-Lecue/hotfix/jungwoo
Browse files Browse the repository at this point in the history
[ Hotfix ] 뒤로가기 시 기존 데이터 유지 반영
  • Loading branch information
jungwoo3490 authored Jan 19, 2024
2 parents ac5095f + b5fc643 commit 14a5775
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/Target/components/FavoriteImageInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import { IcCamera, ImgBook } from '../../../assets';
import * as S from './FavoriteImageInput.style';
Expand All @@ -11,6 +11,18 @@ function FavoriteImageInput({ changeFileData }: FavoriteImageInputProps) {
const imgRef = useRef<HTMLInputElement | null>(null);
const [imgFile, setImgFile] = useState('');

useEffect(() => {
if (
sessionStorage.getItem('image') &&
sessionStorage.getItem('image') !== null
) {
const a = sessionStorage.getItem('image');
if (typeof a === 'string') {
setImgFile(a);
}
}
}, []);

const handleImageUpload = async (): Promise<void> => {
const fileInput = imgRef.current;

Expand All @@ -21,6 +33,7 @@ function FavoriteImageInput({ changeFileData }: FavoriteImageInputProps) {
base64Reader.readAsDataURL(file);
base64Reader.onloadend = () => {
if (base64Reader.result !== null) {
sessionStorage.setItem('image', base64Reader.result as string);
changeFileData(file);
setImgFile(base64Reader.result as string);
}
Expand Down
17 changes: 16 additions & 1 deletion src/Target/page/TargetPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ function TargetPage() {
const { data, isLoading } = useGetPresignedUrl();
const putMutation = usePutPresignedUrl();

useEffect(() => {
if (
sessionStorage.getItem('name') &&
sessionStorage.getItem('name') !== null
) {
const a = sessionStorage.getItem('name');
if (typeof a === 'string') {
setName(a);
}
}
}, []);

useEffect(() => {
if (data) {
const { url, fileName } = data;
Expand Down Expand Up @@ -71,7 +83,10 @@ function TargetPage() {
</S.FavoriteInputWrapper>
</S.InputSectionWrapper>
<CompleteButton
isActive={fileData !== null && name.length !== 0}
isActive={
(fileData !== null || sessionStorage.getItem('image') !== null) &&
name.length !== 0
}
onClick={handleClickCompleteButton}
/>
</S.TargetPageBodyWrapper>
Expand Down

0 comments on commit 14a5775

Please sign in to comment.