diff --git a/src/api/services/mainPage.js b/src/api/services/mainPage.js new file mode 100644 index 0000000..b7b277a --- /dev/null +++ b/src/api/services/mainPage.js @@ -0,0 +1,20 @@ +import * as EgovNet from "@/api/egovFetch"; + +export const fetchMainPage = async () => { + const retrieveListURL = "/mainPage"; + const requestOptions = { + method: "GET", + headers: { + "Content-type": "application/json", + }, + }; + + return new Promise((resolve, reject) => { + EgovNet.requestFetch( + retrieveListURL, + requestOptions, + (resp) => resolve(resp), + (err) => reject(err) + ); + }); +}; diff --git a/src/pages/main/EgovMain.jsx b/src/pages/main/EgovMain.jsx index 30a0e28..04bd14a 100644 --- a/src/pages/main/EgovMain.jsx +++ b/src/pages/main/EgovMain.jsx @@ -1,12 +1,12 @@ -import { useState, useEffect, useCallback } from "react"; +import { useState, useEffect } from "react"; import { Link, useLocation } from "react-router-dom"; -import * as EgovNet from "@/api/egovFetch"; import URL from "@/constants/url"; import simpleMainIng from "/assets/images/img_simple_main.png"; import initPage from "@/js/ui"; - +import { fetchMainPage } from "@/api/services/mainPage"; +import BoardList from "./fragments/BoardList"; function EgovMain(props) { console.group("EgovMain"); console.log("[Start] EgovMain ------------------------------"); @@ -15,91 +15,25 @@ function EgovMain(props) { const location = useLocation(); console.log("EgovMain [location] : ", location); - // eslint-disable-next-line no-unused-vars - const [noticeBoard, setNoticeBoard] = useState(); - // eslint-disable-next-line no-unused-vars - const [gallaryBoard, setGallaryBoard] = useState(); - const [noticeListTag, setNoticeListTag] = useState(); - const [gallaryListTag, setGallaryListTag] = useState(); - - useEffect(() => { - initPage(); - }); + const [noticeBoardList, setNoticeBoardList] = useState([]); + const [gallaryBoardList, setGallaryBoardList] = useState([]); - const retrieveList = useCallback(() => { + const retrieveList = async () => { console.groupCollapsed("EgovMain.retrieveList()"); - - const retrieveListURL = "/mainPage"; - const requestOptions = { - method: "GET", - headers: { - "Content-type": "application/json", - }, - }; - - EgovNet.requestFetch( - retrieveListURL, - requestOptions, - (resp) => { - setNoticeBoard(resp.result.notiList); - setGallaryBoard(resp.result.galList); - - let mutNotiListTag = []; - mutNotiListTag.push(