-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
components/diaries/edit/diary-edit-image/diary-edit-image.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.image-area { | ||
padding-left: 24px; | ||
} | ||
|
||
.image-item { | ||
position: relative; | ||
width: 110px; | ||
height: 110px; | ||
border-radius: 10px; | ||
background-color: #d9d9d9; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
overflow: hidden; | ||
|
||
input { | ||
display: none; | ||
} | ||
|
||
label { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
z-index: 10; | ||
cursor: pointer; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
components/diaries/edit/diary-edit-image/diary-edit-image.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Image from 'next/image'; | ||
import { Swiper, SwiperSlide } from 'swiper/react'; | ||
import 'swiper/css'; | ||
import styles from './diary-edit-image.module.scss'; | ||
import { useRef, useState } from 'react'; | ||
import { diaryImageUpload } from '@/api/image-api'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
export default function DiaryEditImage() { | ||
// const [imageId, setImageId] = useState<number | null>(null); | ||
|
||
return ( | ||
<Swiper spaceBetween={10} slidesPerView="auto" tag="div" wrapperTag="ul" className={styles['image-area']}> | ||
{Array(5) | ||
.fill(0) | ||
.map((_, index) => ( | ||
<SwiperSlide tag="li" className={styles['image-item']} key={index}> | ||
<DiaryEditImageItem index={index} /> | ||
</SwiperSlide> | ||
))} | ||
</Swiper> | ||
); | ||
} | ||
|
||
export function DiaryEditImageItem({ index }: { index: number }) { | ||
const [previewUrl, setPreviewUrl] = useState(''); | ||
const uploadRef = useRef<HTMLInputElement>(null); | ||
const { setValue, getValues } = useFormContext(); | ||
|
||
const handlePreview = async () => { | ||
const file = uploadRef.current && uploadRef.current.files![0]; | ||
const fileReader = new FileReader(); | ||
|
||
try { | ||
const result = (await diaryImageUpload({ images: file! })).data; | ||
const values = getValues('images'); | ||
values ? setValue('images', [...values, result.data[0]]) : setValue('images', [result.data[0]]); | ||
console.log(getValues('images')); | ||
// setImageId(result.data[0]); | ||
// profileMutation.mutateAsync({ imageId: result.data[0], nickname }); | ||
} catch (error) { | ||
throw new Error('이미지 요청하는데 에러가 났어요.'); | ||
} | ||
|
||
fileReader.readAsDataURL(file!); | ||
fileReader.onloadend = () => { | ||
setPreviewUrl(fileReader.result as string); | ||
}; | ||
}; | ||
return ( | ||
<> | ||
<label htmlFor={`image-${index}`}></label> | ||
<input type="file" id={`image-${index}`} onChange={handlePreview} ref={uploadRef} /> | ||
<Image | ||
src={previewUrl || `/images/diaries/imageupload-default.svg`} | ||
alt="" | ||
fill | ||
objectFit="cover" | ||
objectPosition="center" | ||
/> | ||
</> | ||
); | ||
} |
7 changes: 6 additions & 1 deletion
7
...it-weather/diary-edit-weather.module.scss → ...it-weather/diary-edit-weather.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState } from 'react'; | ||
import styles from './diary-edit-weather.module.scss'; | ||
import { WEATHER_TYPES } from '@/lib/constants/diaries-constants'; | ||
import Image from 'next/image'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
type WeatherType = (typeof WEATHER_TYPES)[number]; | ||
|
||
interface WeatherItem { | ||
defaultWeather?: string; | ||
} | ||
|
||
export default function WeatherItem(props: WeatherItem) { | ||
const { setValue } = useFormContext(); | ||
const [selectedWeather, setSelectedWeather] = useState<string | null>(props.defaultWeather || '맑음'); | ||
|
||
if (props.defaultWeather) { | ||
setValue('weather', props.defaultWeather); | ||
} | ||
|
||
const handleClick = (weather: WeatherType) => { | ||
setSelectedWeather(weather.label); | ||
setValue('weather', weather.label); | ||
}; | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<div className={styles.weatherContainer}> | ||
<div className={styles.label}>날씨</div> | ||
<div className={styles.weatherIcons}> | ||
{WEATHER_TYPES.map((weather) => ( | ||
<button | ||
key={weather.id} | ||
type="button" | ||
onClick={() => handleClick(weather)} | ||
className={selectedWeather === weather.label ? styles.selected : ''} | ||
> | ||
<Image | ||
src={selectedWeather === weather.label ? weather.selectedIcon : weather.icon} | ||
alt={weather.label} | ||
width={40} | ||
height={40} | ||
/> | ||
</button> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters