Showing
1 changed file
with
23 additions
and
22 deletions
| 1 | -// PersistentStorage.persistProp('clickedIds', []); | ||
| 2 | -// | ||
| 3 | -// function persistentStorage(id: string | number, type: 'add' | 'remove' | undefined = 'add') { | ||
| 4 | -// let clickedIds = AppStorage.get<string>('clickedIds')?.split(',') || []; | ||
| 5 | -// let index = clickedIds.indexOf(id.toString()) | ||
| 6 | -// if (type === 'add') { | ||
| 7 | -// if (index >= 0) return; | ||
| 8 | -// clickedIds.push(id.toString()); | ||
| 9 | -// } else if (type === 'remove') { | ||
| 10 | -// clickedIds.splice(index, 1); | ||
| 11 | -// } | ||
| 12 | -// AppStorage.set('clickedIds', clickedIds.join(',')); | ||
| 13 | -// } | ||
| 14 | -// | ||
| 15 | -// function hasClicked(id: string | number) { | ||
| 16 | -// let clickedIds = AppStorage.get<string>('clickedIds')?.split(',') || []; | ||
| 17 | -// let index = clickedIds.indexOf(id.toString()) | ||
| 18 | -// if (index >= 0) return true; | ||
| 19 | -// return false; | ||
| 20 | -// } | ||
| 21 | -// | ||
| 22 | -// export { persistentStorage, hasClicked } | ||
| 1 | +PersistentStorage.persistProp('clickedIds', []); | ||
| 2 | + | ||
| 3 | +function persistentStorage(id: string | number, type: 'add' | 'remove' | undefined = 'add') { | ||
| 4 | + let _clickedIds = AppStorage.get<string[]>('clickedIds'); | ||
| 5 | + let clickedIds = _clickedIds?.toString()?.split(',') || []; | ||
| 6 | + let index = clickedIds.indexOf(id.toString()) | ||
| 7 | + if (type === 'add') { | ||
| 8 | + if (index >= 0) return; | ||
| 9 | + clickedIds.push(id.toString()); | ||
| 10 | + } else if (type === 'remove') { | ||
| 11 | + clickedIds.splice(index, 1); | ||
| 12 | + } | ||
| 13 | + AppStorage.set('clickedIds', clickedIds.join(',')); | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +function hasClicked(id: string | number) { | ||
| 17 | + let clickedIds = AppStorage.get<string>('clickedIds')?.split(',') || []; | ||
| 18 | + let index = clickedIds.indexOf(id.toString()) | ||
| 19 | + if (index >= 0) return true; | ||
| 20 | + return false; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +export { persistentStorage, hasClicked } |
-
Please register or login to post a comment