-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diary_day : Editor 완성 Refactoring 도 완료
- Loading branch information
1 parent
8e0532c
commit 495126c
Showing
9 changed files
with
375 additions
and
150 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
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,45 @@ | ||
import { useEffect } from "react"; | ||
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; | ||
import { | ||
diaryContent, | ||
diaryContentType, | ||
diaryItemList, | ||
diaryItemType, | ||
isDisabled, | ||
titleText, | ||
} from "../../recoil/diary"; | ||
import JuiceFont from "../common/JuiceFont"; | ||
|
||
interface IEditorHead { | ||
day: string; | ||
} | ||
/** | ||
* Editor 의 최상단부 Save / Edit 기능 | ||
* @param day : string(yyyy-MM-dd) | ||
* @returns Mode Save & Edit 통해 Edit 하고 diaryContent State push | ||
*/ | ||
const EditorHead = ({ day }: IEditorHead) => { | ||
const [disabled, setDisabled] = useRecoilState<boolean>(isDisabled); | ||
const title = useRecoilValue<string>(titleText); | ||
const items = useRecoilValue<diaryItemType[]>(diaryItemList); | ||
const [diary, setDiary] = useRecoilState<diaryContentType[]>(diaryContent); | ||
// 여기 뭔가 이상함ㅋㅋ 왜지? | ||
useEffect(() => { | ||
!disabled && | ||
setDiary([...diary, { day: day, title: title, content: items }]); | ||
console.log(diary); | ||
}, [disabled]); | ||
return ( | ||
<div className="flex justify-between items-center"> | ||
<JuiceFont>{day}</JuiceFont> | ||
<button | ||
onClick={() => setDisabled((prev) => !prev)} | ||
className="font-mono bg-emerald-400 p-1 rounded-md shadow-md text-white hover:bg-emerald-600 duration-300" | ||
> | ||
{disabled ? "Edit" : "Save"} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditorHead; |
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,113 @@ | ||
import { Reorder } from "framer-motion"; | ||
import { useEffect, useState } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { useRecoilState, useRecoilValue } from "recoil"; | ||
import { | ||
diaryItemList, | ||
diaryItemType, | ||
isDisabled, | ||
itemStyle, | ||
itemStyleType, | ||
itemTextBgColor, | ||
itemTextBgColorType, | ||
itemTextColor, | ||
itemTextColorType, | ||
itemTextSize, | ||
itemTextSizeType, | ||
} from "../../recoil/diary"; | ||
import SetBtn from "../common/SetBtn"; | ||
|
||
/** | ||
* Editor의 중하단부, context의 List를 더하거나 CSS를 수정한다. 내용을 추가 할 수 있다. | ||
* @returns Item List 가 출력 (Item -> 내용) | ||
*/ | ||
const ItemList = () => { | ||
const { register, watch, setValue } = useForm(); | ||
const disabled = useRecoilValue<boolean>(isDisabled); | ||
const [items, setItems] = useRecoilState<diaryItemType[]>(diaryItemList); | ||
// recoil default 가 0 가 있어서 1부터다! | ||
const [itemId, setItemId] = useState<number>(1); | ||
const [style, setStyle] = useRecoilState<itemStyleType[]>(itemStyle); | ||
const [size, setSize] = useRecoilState<itemTextSizeType>(itemTextSize); | ||
const [color, setColor] = useRecoilState<itemTextColorType>(itemTextColor); | ||
const [bgColor, setBgColor] = | ||
useRecoilState<itemTextBgColorType>(itemTextBgColor); | ||
|
||
const onPlusClick = () => { | ||
setItemId((prev) => prev + 1); | ||
setStyle([...style, { textSize: "text-base", textColor: "", textBg: "" }]); | ||
setItems([ | ||
...items, | ||
{ | ||
id: "context" + itemId, | ||
context: "", | ||
style: { textSize: "text-base", textColor: "", textBg: "" }, | ||
}, | ||
]); | ||
}; | ||
const onSettingClick = (index: number) => { | ||
let tempStyle: itemStyleType[] = [...style]; | ||
tempStyle[index] = { textSize: size, textColor: color, textBg: bgColor }; | ||
setStyle(tempStyle); | ||
setSize("text-base"); | ||
setColor(""); | ||
setBgColor(""); | ||
}; | ||
|
||
useEffect(() => { | ||
let tempItemList: diaryItemType[] = []; | ||
for (let i = 0; i < items.length; i++) { | ||
let temp: diaryItemType = { | ||
id: "context" + i, | ||
context: watch("context" + i), | ||
style: style[i], | ||
}; | ||
tempItemList.push(temp); | ||
} | ||
setItems(tempItemList); | ||
}, [disabled, style]); | ||
|
||
return ( | ||
<Reorder.Group axis="y" values={items} onReorder={setItems}> | ||
<div> | ||
{items.map((value, index) => ( | ||
<Reorder.Item | ||
key={value.id} | ||
value={value} | ||
dragConstraints={{ | ||
top: -50, | ||
bottom: 100, | ||
left: 0, | ||
right: 0, | ||
}} | ||
> | ||
<div | ||
key={value.id} | ||
className="flex gap-1 group relative items-center" | ||
> | ||
<button | ||
onClick={onPlusClick} | ||
className="group-hover:opacity-100 relative opacity-0 hover:opacity-100 hover:bg-gray-200 w-8 h-8 rounded-md duration-500 text-gray-400" | ||
> | ||
+ | ||
</button> | ||
<SetBtn | ||
isWeakGray | ||
isSettingBox | ||
onClick={() => onSettingClick(index)} | ||
others="relative opacity-0 group-hover:opacity-100 hover:opacity-100 hover:bg-gray-200 duration-500" | ||
/> | ||
<div | ||
{...register(value.id)} | ||
contentEditable={!disabled} | ||
onInput={(e) => setValue(value.id, e.currentTarget.textContent)} | ||
className={`font-mono border-none rounded-sm w-full px-1 active:bg-blue-200 active:rounded-sm duration-150 whitespace-pre-line ${value.style.textSize} ${value.style.textColor} bg-[${value.style.textBg}]`} | ||
/> | ||
</div> | ||
</Reorder.Item> | ||
))} | ||
</div> | ||
</Reorder.Group> | ||
); | ||
}; | ||
export default ItemList; |
Oops, something went wrong.