Skip to content

Commit

Permalink
rename: setLocalStorage -> SetLocalStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanna922 committed Feb 9, 2024
1 parent 79f0edf commit 1167263
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setLocalStorage } from './setLocalStorage';
import { SetLocalStorage } from './SetLocalStorage';
import { LogPayloadParams, ServiceNameType } from './types/LogType';
import CryptoJS from 'crypto-js';

Expand Down Expand Up @@ -57,7 +57,7 @@ const initialLog = (
logger.event.name = name;
logger.event.path = path;

setLocalStorage(logger);
SetLocalStorage(logger);
};

export const useYLSLogger = () => {
Expand Down
24 changes: 24 additions & 0 deletions src/setLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { postLog } from './apis/postLog';
import { LogType } from './types/LogType';

const SetLocalStorageClear = () => {
const list: any[] = [];
localStorage.setItem('yls-web', JSON.stringify(list));
};

export const SetLocalStorage = async (logger: LogType) => {
if (window.localStorage.getItem('yls-web') == undefined) {
const list: any[] = [];
list.push(logger);
localStorage.setItem('yls-web', JSON.stringify(list));
} else {
const remainList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || [];
if (remainList.length < 10) {
const updateList = [...remainList, logger];
localStorage.setItem('yls-web', JSON.stringify(updateList));
} else {
SetLocalStorageClear();
const res = await postLog();
}
}
};

0 comments on commit 1167263

Please sign in to comment.