persistentStorage.ets 910 Bytes

function persistentStorage(id: string | number, type: 'add' | 'remove' | undefined = 'add') {
  let _clickedIds = AppStorage.get<string[]>('clickedIds');
  let clickedIds = _clickedIds?.toString()?.split(',') || [];
  let index = clickedIds.indexOf(id.toString())
  if (type === 'add') {
    if (index >= 0) return;
    clickedIds.push(id.toString());
  } else if (type === 'remove') {
    clickedIds.splice(index, 1);
  }
  AppStorage.set('clickedIds', clickedIds.join(','));
}

function hasClicked(id: string | number, curRouter: string) {
  let _clickedIds = AppStorage.get<string[]>('clickedIds');
  let clickedIds = _clickedIds?.toString()?.split(',') || [];
  let index = clickedIds.indexOf(id.toString())

  console.log('hasClicked-curRouter', curRouter)
  if (curRouter === 'MyCollectionListPage') return false
  if (index >= 0) return true;
  return false;
}

export { persistentStorage, hasClicked }