박민혁 박민혁 2024-04-03
240403 박민혁 수정
@9c59873dec7763f1dc869bcc750bbd912a262806
client/views/component/autosearch/AutoSearch.jsx
--- client/views/component/autosearch/AutoSearch.jsx
+++ client/views/component/autosearch/AutoSearch.jsx
@@ -14,6 +14,15 @@
       selectClientName("");
   }, []);
 
+  useEffect(() => {
+    if (props.CUSTCD && accounts.length > 0) {
+      const matchedAccount = accounts.find(account => account.CUSTCD === props.CUSTCD);
+      if (matchedAccount) {
+        setInputValue(matchedAccount.JSNAME);
+      }
+    }
+  }, [props.CUSTCD, accounts]); 
+
   const selectClientName = (name) => {
     axios({
       method: 'post',
@@ -39,25 +48,34 @@
   const handleInputChange = (e) => {
     const value = e.target.value;
     setInputValue(value);
-
-    const filtered = accounts.filter((account) =>
-      account.JSNAME.toLowerCase().includes(value.toLowerCase())
-    );
-    setAccountResults(filtered);
-
-    if (value === "" || filtered.length === 0) {
+  
+    if (value === "") {
+      props.setCUSTCD("");
+      setAccountResults([]);
       list.style.display = "none";
       list.style.padding = "0";
       list.style.backgroundColor = "transparent";
       list.style.border = "0";
     } else {
-      list.style.display = "block";
-      list.style.padding = "10px";
-      list.style.backgroundColor = "#ffffff";
-      list.style.border = "1px solid #ddd";
+      const filtered = accounts.filter((account) =>
+        account.JSNAME.toLowerCase().includes(value.toLowerCase())
+      );
+      setAccountResults(filtered);
+  
+      if (filtered.length === 0) {
+        list.style.display = "none";
+        list.style.padding = "0";
+        list.style.backgroundColor = "transparent";
+        list.style.border = "0";
+      } else {
+        list.style.display = "block";
+        list.style.padding = "10px";
+        list.style.backgroundColor = "#ffffff";
+        list.style.border = "1px solid #ddd";
+      }
     }
   };
-
+  
   const handleItemClick = (account) => {
     setInputValue(account.JSNAME);
     props.setCUSTCD(account.CUSTCD);
client/views/layout/Header.jsx
--- client/views/layout/Header.jsx
+++ client/views/layout/Header.jsx
@@ -6,11 +6,7 @@
 function Header(props) {
   const navigate = useNavigate();
   const rollBackBtn = () => {
-    if (props.pathName === "영업 일지"){
-      navigate("/");
-    } else{
-      navigate(-1); // 바로 이전 페이지로 이동
-    }
+      navigate(-1);
   };
   return (
     <header>
client/views/layout/Menu.jsx
--- client/views/layout/Menu.jsx
+++ client/views/layout/Menu.jsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
 import { Link, useLocation } from "react-router-dom";
 import Icon from "@mdi/react";
 import {
@@ -35,27 +35,25 @@
   const [activeIndex, setActiveIndex] = useState(null);
   const location = useLocation();
 
-  const handleClick = (index) => {
-    setActiveIndex(index);
-  };
-
-  const isActive = (path) => location.pathname === path;
+  useEffect(() => {
+    const currentIndex = menuList.findIndex(menu => menu.path === location.pathname);
+    setActiveIndex(currentIndex);
+  }, [location]);
 
   return (
     <nav className="main-menu">
-      <ul className="flex justify-center aling-center">
+      <ul className="flex justify-center align-center">
         {menuList.map((menu, index) => (
           <li
+            key={index}
             className={`${
-              activeIndex === index || isActive(menu.path)
-                ? "active pl5 pr5"
-                : "pl5 pr5"
+              activeIndex === index ? "active pl5 pr5" : "pl5 pr5"
             }`}
-            onClick={() => handleClick(index)}
           >
             <Link
               to={menu.path}
               className="flex-column justify-center align-center"
+              onClick={() => setActiveIndex(index)}
             >
               <p>{menu.icon}</p>
               <p>{menu.pathName}</p>
client/views/pages/main/HomeInsert.jsx
--- client/views/pages/main/HomeInsert.jsx
+++ client/views/pages/main/HomeInsert.jsx
@@ -18,8 +18,17 @@
   React.useEffect(() => {
     if (props.insertTrigger) {
       insertNote();
+      sessionStorage.removeItem("data");
+      sessionStorage.removeItem("index");
+      sessionStorage.removeItem("scrollPosition");
+      sessionStorage.removeItem("searchScroll");
+      sessionStorage.removeItem("searchData");
+      sessionStorage.removeItem("searchState");
+
+      setTimeout(() => {
       props.setInsertTrigger(false);
-      navigate("/");
+        navigate("/");
+      }, 1000); 
     }
   }, [props.insertTrigger, props.setInsertTrigger]);
 
client/views/pages/main/HomeSelectList.jsx
--- client/views/pages/main/HomeSelectList.jsx
+++ client/views/pages/main/HomeSelectList.jsx
@@ -6,7 +6,6 @@
   mdiHandshakeOutline,
   mdiFileCheckOutline,
   mdiAccountOutline,
-  mdiChatOutline,
 } from "@mdi/js";
 import axios from "axios";
 
@@ -14,18 +13,65 @@
   const [data, setData] = React.useState([]);
   const [index, setIndex] = React.useState("1");
   const [hasMore, setHasMore] = React.useState(true);
+  const [isLoading, setIsLoading] = React.useState(true); // 데이터 로딩 상태 변수 추가
 
   const navigate = useNavigate();
+  const scrollRef = React.useRef(null);
+
+  // 이미 세션에 데이터가 저장되었다면 가져오고 아니면 함수 호출
+  useEffect(() => {
+    const savedData = sessionStorage.getItem("data");
+    const savedIndex = sessionStorage.getItem("index");
+    if (savedData && savedIndex) {
+      setData(JSON.parse(savedData));
+      setIndex(JSON.parse(savedIndex));
+      setIsLoading(false);
+    } else {
+      setIsLoading(false);
+      if (hasMore) {
+        selectNote();
+      }
+    }
+  }, []);
+
+  // 데이터가 변경되면 세션에 저장
+  useEffect(() => {
+    sessionStorage.setItem("data", JSON.stringify(data));
+    sessionStorage.setItem("index", JSON.stringify(index));
+    if (data.length > 0) {
+      restoreScrollPosition();
+    }
+  }, [data, index, hasMore]);
+
+  // 스크롤 데이터가 바꿔지면 세션에 저장
+  const restoreScrollPosition = () => {
+    const savedScrollPosition = sessionStorage.getItem("scrollPosition");
+    if (savedScrollPosition && scrollRef.current) {
+      scrollRef.current.scrollTo(0, parseInt(savedScrollPosition, 10));
+    }
+  };
+
+  const handleScroll = () => {
+    if (scrollRef.current) {
+      const { scrollTop } = scrollRef.current;
+      sessionStorage.setItem("scrollPosition", scrollTop.toString());
+    }
+  };
 
   useEffect(() => {
-    selectNote();
-  }, []);
+    const currentScrollRef = scrollRef.current;
+    currentScrollRef.addEventListener("scroll", handleScroll);
+
+    return () => {
+      currentScrollRef.removeEventListener("scroll", handleScroll);
+    };
+  }, [scrollRef.current]);
 
   // 무한 스크롤 적용
   useEffect(() => {
     const observer = new IntersectionObserver(
       (entries) => {
-        if (entries[0].isIntersecting) {
+        if (entries[0].isIntersecting && !isLoading) {
           if (hasMore) {
             selectNote();
           }
@@ -41,7 +87,7 @@
     return () => {
       if (lastElement) observer.unobserve(lastElement);
     };
-  }, [data, hasMore]);
+  }, [data, isLoading]);
 
   // 상세 조회 이동
   const handleItemClick = (notecd) => {
@@ -51,7 +97,7 @@
   // 영업 일지 조회 API
   const selectNote = () => {
     if (!props.SABNHO) {
-      return;
+      return ;
     }
     axios({
       method: "post",
@@ -71,10 +117,7 @@
           } else {
             const transformedData = response.data.resultData.map((item) => {
               const vsdate = item.NOTELIST.VSDATE;
-              const formattedVsdate = `${vsdate.slice(0, 4)}.${vsdate.slice(
-                4,
-                6
-              )}.${vsdate.slice(6, 8)}`;
+              const formattedVsdate = `${vsdate.slice(0, 4)}.${vsdate.slice(4, 6)}.${vsdate.slice(6, 8)}`;
               const tags = item.NOTELIST.HASTAG
                 ? item.NOTELIST.HASTAG.split("#").filter((tag) => tag)
                 : [];
@@ -99,7 +142,10 @@
   };
 
   return (
-    <div className="main-page">
+    <div
+      className="main-page"
+      ref={scrollRef}
+      style={{ overflow: "auto", height: "100vh" }} >
       <ul>
         {Array.isArray(data) &&
           data.map((item, index) => (
client/views/pages/main/HomeSelectOne.jsx
--- client/views/pages/main/HomeSelectOne.jsx
+++ client/views/pages/main/HomeSelectOne.jsx
@@ -38,8 +38,17 @@
   React.useEffect(() => {
     if (props.deleteTrigger) {
       deleteNote();
+      sessionStorage.removeItem("data");
+      sessionStorage.removeItem("index");
+      sessionStorage.removeItem("scrollPosition");
+      sessionStorage.removeItem("searchScroll");
+      sessionStorage.removeItem("searchData");
+      sessionStorage.removeItem("searchState");
+
+      setTimeout(() => {
       props.setDeleteTrigger(false);
-      navigate("/");
+        navigate("/");
+      }, 1000); 
     }
   }, [props.deleteTrigger, props.setDeleteTrigger]);
 
@@ -99,6 +108,7 @@
     })
       .then((response) => {
         props.onModal("해당 일지를 삭제했습니다");
+
       })
       .catch((error) => {
         props.onModal("오류 발생. 관리자에 문의해주세요");
@@ -128,7 +138,7 @@
             var minute = input.slice(10, 12);
             comments[i].CRTYMD = year + ". " + month + ". " + day + " " + hour + ":" + minute + " 등록됨";
 
-            if(comments[i].MDFYMD){
+            if (comments[i].MDFYMD) {
               var input = comments[i].MDFYMD;
               var year = input.slice(0, 4);
               var month = input.slice(4, 6);
@@ -136,7 +146,7 @@
               var hour = input.slice(8, 10);
               var minute = input.slice(10, 12);
               comments[i].MDFYMD = year + ". " + month + ". " + day + " " + hour + ":" + minute + " 수정됨";
-              }
+            }
           }
           setComments(comments);
         }
@@ -153,7 +163,7 @@
       return;
     }
 
-    if (!comment  ||  comment.trim() === '') {
+    if (!comment || comment.trim() === '') {
       props.onModal("댓글을 입력해주세요.");
       return;
     }
@@ -192,7 +202,7 @@
       url: url,
     })
       .then((response) => {
-          selectComment();
+        selectComment();
 
       })
       .catch((error) => {
client/views/pages/search/Search.jsx
--- client/views/pages/search/Search.jsx
+++ client/views/pages/search/Search.jsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useEffect }  from "react";
 import AutoSearch from "./../../component/autosearch/AutoSearch.jsx";
 import Icon from "@mdi/react";
 import {
@@ -21,11 +21,73 @@
   const [hastag, setHastag] = React.useState("");
 
   const navigate = useNavigate();
+  const scrollRef = React.useRef(null);
 
   const handleItemClick = (notecd) => {
     navigate(`/homeSelectOne?notecd=${notecd}`);
   };
 
+  // 이미 세션에 데이터가 저장되었다면 가져오고 아니면 함수 호출
+  useEffect(() => {
+    const savedState = JSON.parse(sessionStorage.getItem('searchState'));
+    const savedData = JSON.parse(sessionStorage.getItem('searchData'));
+
+    if (savedState) {
+      setCUSTCD(savedState.CUSTCD);
+      setStdate(savedState.stdate);
+      setEndate(savedState.endate);
+      setContsx(savedState.contsx);
+      setHastag(savedState.hastag);
+    }
+    if (savedData){
+      setData(savedData);
+    }
+  }, []);
+
+  // 데이터가 변경되면 세션에 저장
+  useEffect(() => {
+    const searchState = {
+      CUSTCD,
+      stdate,
+      endate,
+      contsx,
+      hastag,
+      scrollPosition: window.scrollY
+    };
+
+    sessionStorage.setItem("searchState", JSON.stringify(searchState));
+    sessionStorage.setItem("searchData", JSON.stringify(data));
+    if (data.length > 0) {
+      restoreScrollPosition();
+    }
+
+  }, [CUSTCD, stdate, endate, contsx, hastag, data]);
+
+    // 스크롤 데이터가 바꿔지면 세션에 저장
+    const restoreScrollPosition = () => {
+      const savedScrollPosition = sessionStorage.getItem("searchScroll");
+      if (savedScrollPosition && scrollRef.current) {
+        scrollRef.current.scrollTo(0, parseInt(savedScrollPosition, 10));
+      }
+    };
+  
+    const handleScroll = () => {
+      if (scrollRef.current) {
+        const { scrollTop } = scrollRef.current;
+        sessionStorage.setItem("searchScroll", scrollTop.toString());
+      }
+    };
+  
+    useEffect(() => {
+      const currentScrollRef = scrollRef.current;
+      currentScrollRef.addEventListener("scroll", handleScroll);
+  
+      return () => {
+        currentScrollRef.removeEventListener("scroll", handleScroll);
+      };
+    }, [scrollRef.current]);
+  
+    
   // 영업 일지 조회 API
   const selectNote = () => {
     if (!props.SABNHO) {
@@ -61,13 +123,8 @@
         if (response.data && response.data.resultCode === 200) {
           const transformedData = response.data.resultData.map((item) => {
             const vsdate = item.NOTELIST.VSDATE;
-            const formattedVsdate = `${vsdate.slice(0, 4)}.${vsdate.slice(
-              4,
-              6
-            )}.${vsdate.slice(6, 8)}`;
-            const tags = item.NOTELIST.HASTAG
-              ? item.NOTELIST.HASTAG.split("#").filter((tag) => tag)
-              : [];
+            const formattedVsdate = `${vsdate.slice(0, 4)}.${vsdate.slice(4, 6)}.${vsdate.slice(6, 8)}`;
+            const tags = item.NOTELIST.HASTAG ? item.NOTELIST.HASTAG.split("#").filter((tag) => tag) : [];
             return {
               ...item,
               NOTELIST: {
@@ -86,11 +143,13 @@
   };
 
   return (
-    <div className="search-page">
+    <div className="search-page" ref={scrollRef}
+    style={{ overflow: "auto", height: "100vh" }} >
       <div className="search-zone mb10">
         <div className="input-group mb10">
           <AutoSearch
             titleName={"거래처"}
+            CUSTCD={CUSTCD}
             setCUSTCD={setCUSTCD}
             SABNHO={props.SABNHO}
           />
@@ -154,7 +213,7 @@
         </div>
       </div>
 
-      <div className="main-page">
+      <div className="main-page" >
         <ul>
           {Array.isArray(data) &&
             data.map((item, index) => (
Add a comment
List