-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore : nav z-index 수정 * chore : 알람 수정 * feat : 지도 편지 생성 * feat : 지도 편지 작성 api 연동 * chore : 수정 * chore : 안 쓰는 error 수정
- Loading branch information
Showing
11 changed files
with
361 additions
and
18 deletions.
There are no files selected for viewing
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
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
132 changes: 132 additions & 0 deletions
132
src/components/CreateMapLetter/CreateMapLetterCotainer/CreateMapLetterCotainer.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,132 @@ | ||
import { Margin } from '@/components/Common/Margin/Margin'; | ||
import { TextArea } from '@/components/Common/TextArea/TextArea'; | ||
import { TopBar } from '@/components/Common/TopBar/TopBar'; | ||
import { ThemeWrapper } from '@/components/CreatLetterPage/ThemeWrapper/ThemeWrapper'; | ||
import { SelectSlider } from '@/components/SelectItemPage/SelectSlider/SelectSlider'; | ||
import { useAutoSave, useToastStore } from '@/hooks'; | ||
import React, { useState } from 'react'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { useLocalStorage } from '@/hooks/useLocalStorage'; // 로컬 스토리지 훅 가져오기 | ||
|
||
const CreateMapLetterCotainer = () => { | ||
const { addToast } = useToastStore(); | ||
|
||
const { lat, lot } = useParams<{ lat: string; lot: string }>(); | ||
|
||
// useLocalStorage 훅을 사용하여 로컬 저장소에 값 저장 및 불러오기 | ||
const { setValue: saveTitle, storedValue: storedTitle } = useLocalStorage( | ||
'maptitle', | ||
'' | ||
); | ||
const { setValue: saveLetterContent, storedValue: storedContent } = | ||
useLocalStorage('mapcontent', ''); | ||
const { setValue: saveFont, storedValue: storedFont } = useLocalStorage( | ||
'mapfont', | ||
'initial' | ||
); | ||
const { setValue: saveLetter, storedValue: storedLetter } = useLocalStorage( | ||
'mapletter', | ||
'1' | ||
); | ||
const { setValue: saveDescription, storedValue: storedDescription } = | ||
useLocalStorage('mapdescription', ''); | ||
|
||
// 위도와 경도를 로컬 스토리지에 저장 | ||
localStorage.setItem('maplat', lat?.slice(1) || ''); | ||
localStorage.setItem('maplot', lat?.slice(1) || ''); | ||
|
||
// 상태 관리 | ||
const [title, setTitle] = useState<string>(storedTitle || ''); | ||
const [letter, setLetter] = useState<string>(storedLetter || '1'); | ||
const [letterContent, setLetterContent] = useState<string>( | ||
storedContent || '' | ||
); | ||
const [font, setFont] = useState<string>(storedFont || 'initial'); | ||
const [description, setDescription] = useState<string>( | ||
storedDescription || '' | ||
); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const inputValue = e.target.value; | ||
setTitle(inputValue); | ||
}; | ||
|
||
const saveLetterData = () => { | ||
saveTitle(title); | ||
saveLetterContent(letterContent); | ||
saveFont(font); | ||
saveLetter(letter); | ||
saveDescription(description); | ||
}; | ||
|
||
useAutoSave(saveLetterData, 50000); | ||
|
||
return ( | ||
<> | ||
<TopBar | ||
handleBackClick={() => { | ||
navigate(-1); | ||
}} | ||
handleSuccesClick={() => { | ||
if ( | ||
!title.trim() || | ||
!letterContent.trim() || | ||
!description.trim() | ||
) { | ||
addToast( | ||
'공백을 제외한 제목과 내용을 입력해주세요', | ||
'warning' | ||
); | ||
return; | ||
} | ||
saveLetterData(); | ||
navigate('/letter/map/select'); | ||
}} | ||
/> | ||
|
||
<ThemeWrapper themeId={Number(letter)}> | ||
<> | ||
<Margin top={20} /> | ||
<div className="relative flex flex-col justify-center w-9/12 m-auto py-9"> | ||
<input | ||
onChange={handleChange} | ||
value={title} | ||
type="text" | ||
placeholder="제목을 입력해주세요" | ||
className={`z-10 w-full bg-transparent border-none focus:border-none focus:outline-none text-wrap ${font ? font : 'font-sans'}`} | ||
maxLength={20} | ||
/> | ||
<img src={'/to_line.f4c129e6.svg'} /> | ||
|
||
<div className="relative z-10"> | ||
<TextArea | ||
value={letterContent} | ||
setValue={setLetterContent} | ||
font={font} | ||
/> | ||
</div> | ||
|
||
<input | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
placeholder="힌트를 입력해주세요" | ||
className={`z-10 w-full bg-transparent border-none focus:border-none focus:outline-none text-wrap ${font ? font : 'font-sans'}`} | ||
/> | ||
<img src={'/to_line.f4c129e6.svg'} /> | ||
</div> | ||
|
||
<SelectSlider | ||
font={font} | ||
letter={letter} | ||
setFont={setFont} | ||
setLetter={setLetter} | ||
/> | ||
</> | ||
</ThemeWrapper> | ||
</> | ||
); | ||
}; | ||
|
||
export default CreateMapLetterCotainer; |
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 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { createMapLetter } from '@/service/letter/create/createMapLetter'; | ||
import { useToastStore } from './useToastStore'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const useCreateMapLetter = () => { | ||
const { addToast } = useToastStore(); | ||
const navigate = useNavigate(); | ||
const mutation = useMutation({ | ||
mutationFn: createMapLetter, | ||
onSuccess: () => { | ||
addToast('지도 편지를 전송했습니다.', 'success'); | ||
navigate('/letter/success'); | ||
localStorage.removeItem('maptitle'); | ||
localStorage.removeItem('mapcontent'); | ||
localStorage.removeItem('mapdescription'); | ||
localStorage.removeItem('mapfont'); | ||
localStorage.removeItem('mapletter'); | ||
localStorage.removeItem('maplat'); | ||
localStorage.removeItem('maplot'); | ||
}, | ||
onError: () => { | ||
addToast('지도 편지를 실패했습니다.', 'error'); | ||
} | ||
}); | ||
return mutation; | ||
}; |
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,10 @@ | ||
import CreateMapLetterCotainer from '@/components/CreateMapLetter/CreateMapLetterCotainer/CreateMapLetterCotainer'; | ||
import React from 'react'; | ||
|
||
export const CreateMapLetterPage = () => { | ||
return ( | ||
<div className="w-full h-full"> | ||
<CreateMapLetterCotainer /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.