Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30 編集画面で空白をクリックしたらマイルストーンが追加されるUIを作る #31

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/components/organisms/EditingCareerCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ const EditingCareerCalendar = ({ userId }: Props) => {
[lifeEvents]
);

const addNewLifeEvent = useCallback(
(newLifeEvent: Milestone) => {
setLifeEvents([...lifeEvents, newLifeEvent]);
},
[lifeEvents]
);

const handleClickCalender = useCallback(
(calendarIndex: number) => {
const newLifeEventBeginYear = calendarIndex + START_YEAR;
addNewLifeEvent({
userId: userId,
milestoneId: `${Math.random() * 10000}`, //仮置き
title: "新しいマイルストーン",
content: "新しいマイルストーンのコンテンツ",
imageHash: "",
beginDate: `${newLifeEventBeginYear}-01-01`,
finishDate: `${newLifeEventBeginYear}-12-01`,
});
},
[userId, addNewLifeEvent]
);

return (
<div
className="grid"
Expand All @@ -48,11 +71,19 @@ const EditingCareerCalendar = ({ userId }: Props) => {
))}
{array.map((_, index) => (
<div
className="border-y-[0.5px] col-start-2 col-end-4"
className="border-y-[0.5px] col-start-2 col-end-4 cursor-default"
style={{
gridRow: `${index * 12 + 1} / span 12`,
}}
key={`year-${index}`}
onClick={() => {
handleClickCalender(index);
}}
onKeyDown={(e) => {
if (e.key === "Enter") handleClickCalender(index);
}}
role="button"
tabIndex={0}
>
{" "}
</div>
Expand Down