-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create YLS context for using baseURL (#14)
* config: allow any type in YLS - 예외 허용 * fix: noExternal packages - sha256 외에 사용하는 부분이 있어서 수정 * feat: modify AxiosInstance to receive the baseURL as a parameter * feat: create YLSWrapper, YLSProvider * feat: create useYLSContext for using context * feat: apply useYLSContext * fix: modify YLS demo * docs: update README.md
- Loading branch information
Showing
24 changed files
with
467 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { YLSWrapper } from '@yourssu/logging-system-react'; | ||
import ReactDOM from 'react-dom/client'; | ||
|
||
import { App } from './App'; | ||
|
||
const baseURL = import.meta.env.VITE_API_YLS_URL; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<YLSWrapper baseURL={baseURL}> | ||
<App /> | ||
</YLSWrapper> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json" | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["vite/client"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import react from '@vitejs/plugin-react'; | ||
import { defineConfig } from 'vite'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
extends: ['../../.eslintrc.cjs'], | ||
rules: { | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import axios from 'axios'; | ||
|
||
export const createAxiosInstance = (baseURL: string) => { | ||
return axios.create({ | ||
baseURL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
withCredentials: true, | ||
}, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { YLSProvider } from '@/contexts/YLSProvider'; | ||
|
||
interface YLSWrapperProps { | ||
children: React.ReactNode; | ||
baseURL: string; | ||
} | ||
|
||
/** | ||
* YLS에 사용되는 Context를 위한 컴포넌트입니다. | ||
* YLS를 사용하는 프로젝트의 최상위 컴포넌트로 사용해야 합니다. | ||
*/ | ||
export const YLSWrapper = ({ children, baseURL }: YLSWrapperProps) => { | ||
return <YLSProvider baseURL={baseURL}>{children}</YLSProvider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createContext } from 'react'; | ||
|
||
import { createAxiosInstance } from '@/apis/createAxiosInstance'; | ||
import { LogRequestList, LogResponse } from '@/types/LogType'; | ||
|
||
interface YLSProviderProps { | ||
children: React.ReactNode; | ||
baseURL: string; | ||
} | ||
|
||
export interface YLSContextType { | ||
postLog: (data: LogRequestList) => Promise<LogResponse>; | ||
} | ||
|
||
export const YLSContext = createContext<YLSContextType | undefined>(undefined); | ||
|
||
/** | ||
* YLS에 사용되는 Context Provider를 위한 컴포넌트입니다. | ||
* 일반적으로 YLSWrapper 컴포넌트를 사용하시면 됩니다. | ||
* @param param0 | ||
* @returns | ||
*/ | ||
export const YLSProvider = ({ children, baseURL }: YLSProviderProps) => { | ||
const axiosInstance = createAxiosInstance(baseURL); | ||
|
||
const postLog = async (data: LogRequestList): Promise<LogResponse> => { | ||
try { | ||
const res = await axiosInstance.put('/log/list', data); | ||
return res.data; | ||
} catch (e) { | ||
throw new Error('Failed to post log'); | ||
} | ||
}; | ||
|
||
return ( | ||
<YLSContext.Provider | ||
value={{ | ||
postLog, | ||
}} | ||
> | ||
{children} | ||
</YLSContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { YLSContext } from '@/contexts/YLSProvider'; | ||
|
||
export const useYLSContext = () => { | ||
const context = useContext(YLSContext); | ||
if (!context) { | ||
throw new Error('useYLSContext must be used within a YLSProvider'); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { YLSWrapper } from './components/YLSWrapper'; | ||
export { useYLSLogger } from './Logger'; | ||
export { LogClick } from './components/LogClick'; | ||
export { LogScreen } from './components/LogScreen'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.