70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
/**
|
|
* 삭제된 트랜잭션 ID를 추적하는 유틸리티
|
|
* 로컬에서 삭제된 트랜잭션이 서버 동기화 후 다시 나타나는 문제를 해결합니다.
|
|
*/
|
|
|
|
// 삭제된 트랜잭션 ID를 저장하는 로컬 스토리지 키
|
|
const DELETED_TRANSACTIONS_KEY = 'deletedTransactions';
|
|
|
|
/**
|
|
* 삭제된 트랜잭션 ID를 저장
|
|
* @param id 삭제된 트랜잭션 ID
|
|
*/
|
|
export const addToDeletedTransactions = (id: string): void => {
|
|
try {
|
|
const deletedIds = getDeletedTransactions();
|
|
if (!deletedIds.includes(id)) {
|
|
deletedIds.push(id);
|
|
localStorage.setItem(DELETED_TRANSACTIONS_KEY, JSON.stringify(deletedIds));
|
|
console.log(`[삭제 추적] ID 추가됨: ${id}`);
|
|
}
|
|
} catch (error) {
|
|
console.error('[삭제 추적] ID 추가 실패:', error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 삭제된 트랜잭션 ID 목록 가져오기
|
|
* @returns 삭제된 트랜잭션 ID 배열
|
|
*/
|
|
export const getDeletedTransactions = (): string[] => {
|
|
try {
|
|
const deletedStr = localStorage.getItem(DELETED_TRANSACTIONS_KEY);
|
|
const deletedIds = deletedStr ? JSON.parse(deletedStr) : [];
|
|
return Array.isArray(deletedIds) ? deletedIds : [];
|
|
} catch (error) {
|
|
console.error('[삭제 추적] 목록 조회 실패:', error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 삭제된 트랜잭션 ID 제거 (서버에서 성공적으로 삭제된 경우)
|
|
* @param id 제거할 트랜잭션 ID
|
|
*/
|
|
export const removeFromDeletedTransactions = (id: string): void => {
|
|
try {
|
|
const deletedIds = getDeletedTransactions();
|
|
const updatedIds = deletedIds.filter(deletedId => deletedId !== id);
|
|
|
|
if (deletedIds.length !== updatedIds.length) {
|
|
localStorage.setItem(DELETED_TRANSACTIONS_KEY, JSON.stringify(updatedIds));
|
|
console.log(`[삭제 추적] ID 제거됨: ${id}`);
|
|
}
|
|
} catch (error) {
|
|
console.error('[삭제 추적] ID 제거 실패:', error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 삭제된 트랜잭션 ID 목록 초기화
|
|
*/
|
|
export const clearDeletedTransactions = (): void => {
|
|
try {
|
|
localStorage.removeItem(DELETED_TRANSACTIONS_KEY);
|
|
console.log('[삭제 추적] 목록 초기화됨');
|
|
} catch (error) {
|
|
console.error('[삭제 추적] 목록 초기화 실패:', error);
|
|
}
|
|
};
|