diff --git a/packages/logging-system/package.json b/packages/logging-system/package.json index 294bead..559f6bb 100644 --- a/packages/logging-system/package.json +++ b/packages/logging-system/package.json @@ -46,7 +46,7 @@ "devDependencies": { "@types/react-router-dom": "^5.3.3", "@yourssu/crypto": "workspace:*", - "axios": "^1.6.4", + "axios": "^1.7.7", "react-router-dom": "^6.21.3" } } diff --git a/packages/logging-system/src/contexts/YLSProvider.tsx b/packages/logging-system/src/contexts/YLSProvider.tsx index 09db725..c416603 100644 --- a/packages/logging-system/src/contexts/YLSProvider.tsx +++ b/packages/logging-system/src/contexts/YLSProvider.tsx @@ -1,7 +1,9 @@ -import { createContext } from 'react'; +import { createContext, useEffect } from 'react'; import { createAxiosInstance } from '@/apis/createAxiosInstance'; import { LogRequestList, LogResponse } from '@/types/LogType'; +import { LogType } from '@/types/LogType'; +import { SetLocalStorageClear } from '@/SetLocalStorage'; interface YLSProviderProps { children: React.ReactNode; @@ -32,6 +34,27 @@ export const YLSProvider = ({ children, baseURL }: YLSProviderProps) => { } }; + useEffect(() => { + const handleVisibilityChange = () => { + if (document.visibilityState === 'visible') return; + + const logList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + const data: LogRequestList = { + logRequestList: logList, + }; + + SetLocalStorageClear(); + + void axiosInstance.put('/log/list', data); + }; + + document.addEventListener('visibilitychange', handleVisibilityChange); + + return () => { + document.removeEventListener('visibilitychange', handleVisibilityChange); + }; + }, []); + return (