-
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.
* [Add] 사이드바 외부 클릭시 자동 닫힘 * [Add] useTrain 훅 내 날짜 핸들링 관련 로직 테스트 코드 * [Fix] 트레이닝 페이지 useRouter * [Modify] storage 클래스 window추가 * [Fix] window앞에 global키워드 nullable로 추가 --------- Co-authored-by: cloud <[email protected]>
- Loading branch information
1 parent
8388fa7
commit b222317
Showing
1 changed file
with
43 additions
and
0 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,43 @@ | ||
import CustomAlert from './alert'; | ||
|
||
class DataStorage { | ||
customAlert; | ||
|
||
constructor() { | ||
this.customAlert = new CustomAlert(); | ||
} | ||
|
||
set(key: string = 'iron-mate-data', data: any) { | ||
try { | ||
global?.window?.localStorage.setItem(key, JSON.stringify(data)); | ||
this.customAlert.toast('브라우저 내 데이터 저장이 완료되었습니다.'); | ||
} catch (e) { | ||
this.customAlert.toast('브라우저 내 데이터 저장에 실패하였습니다.'); | ||
console.error(e); | ||
} | ||
} | ||
|
||
get(key: string = 'iron-mate-data') { | ||
try { | ||
const data = JSON.parse( | ||
(global?.window?.localStorage.getItem(key) || '') as string | ||
); | ||
return data; | ||
} catch (e) { | ||
this.customAlert.toast('브라우저 내 데이터 가져오기에 실패하였습니다.'); | ||
console.error(e); | ||
} | ||
} | ||
|
||
remove(key: string = 'iron-mate-data') { | ||
try { | ||
const data = global?.window?.localStorage.removeItem(key); | ||
return data; | ||
} catch (e) { | ||
this.customAlert.toast('브라우저 내 데이터 삭제하기에 실패하였습니다.'); | ||
console.error(e); | ||
} | ||
} | ||
} | ||
|
||
export default DataStorage; |