twenty-eight-days / TwentyEightDaysNative

Privacy-First Cycle Tracking App (React Native, iOS/Android)
MIT License
1 stars 0 forks source link

Code bereinigen #24

Closed geccy25 closed 2 years ago

geccy25 commented 2 years ago

-> reusable Components

PiecePaperCode commented 2 years ago

redux.ts

// writing and reading to disc is async
// redux docent support async operations inside Slice
// they need to be performed outside of redux and written back in an async callback
export function read() {
  const { write } = periodSlice.actions
  storage.read().then(p => store.dispatch(write(p)))
}
export function write(periods: Period) {
  const { write } = periodSlice.actions
  storage.write(periods).then(p => store.dispatch(write(p)))
}
export function remove(item: Period) {
  const { write } = periodSlice.actions
  storage.delete(item).then(periods => store.dispatch(write(periods)))
}

DataScreen.ts

// eslint is disabled because useEffects needs to only run once and eslint
// doesn't compile the code with useEffect(()=>{},[])
useEffect(() => {
  // eslint-disable-line
  read() // eslint-disable-line
}, []) // eslint-disable-line