diff --git a/domain/Course/CoursePinList/index.tsx b/domain/Course/CoursePinList/index.tsx index 678a809..f910ce1 100644 --- a/domain/Course/CoursePinList/index.tsx +++ b/domain/Course/CoursePinList/index.tsx @@ -14,7 +14,7 @@ export default function CoursePinList(): JSX.Element { useEffect(() => { (async () => { const res = await getCourses(); - setCourseItems(res.slice(0, 4)); + setCourseItems(res.reverse().slice(0, 4)); })(); return () => setCourseItems([]); }, []); diff --git a/domain/Course/CreateCourse/index.tsx b/domain/Course/CreateCourse/index.tsx index 9d0b643..f9cd9cd 100644 --- a/domain/Course/CreateCourse/index.tsx +++ b/domain/Course/CreateCourse/index.tsx @@ -1,25 +1,34 @@ -import React, { FormEvent, useEffect, useState } from "react"; +import React from "react"; + +import { useRouter } from "next/router"; import * as S from "./style"; -import { getColors } from "../../../libs/colors"; +import useGetString from "../../../hooks/useGetString"; +import useOnChange from "../../../hooks/useOnChange"; +import useTagOnChange from "../../../hooks/useTagOnChange"; -import TagInput from "../../Tag/TagInput"; import Button from "../../../components/Button"; +import SelectCourseColor from "../SelectCourseColor"; +import TagInput from "../../Tag/TagInput"; +import { postNewCourse } from "../../../libs/course"; export default function CreateCourse(): JSX.Element { - const [courseColors, setCourseColors] = useState([]); - - useEffect(() => { - (async () => { - const res = await getColors(); - setCourseColors(res); - })(); - return () => setCourseColors([]); - }, []); - - const handleSubmit = async (event: FormEvent) => { - event.preventDefault(); + const router = useRouter(); + + const [color, setColor] = useGetString(); + const [title, setTitle] = useOnChange(); + const [explanation, setExplanation] = useOnChange(); + const [tags, setTags] = useTagOnChange(); + + const addCourse = async () => { + await postNewCourse({ + title: title, + explanation: explanation, + color: color, + tags: tags, + }); + router.back(); }; return ( @@ -27,33 +36,29 @@ export default function CreateCourse(): JSX.Element { 새로운 코스 추가 -
- - - 코스 색상 선택 - - - {courseColors.map((color, index) => { - return ; - })} - - - 코스 제목 - - - - 설명 - - - - 태그 - - - -