KhalisIncubator / MyPothi

5 stars 1 forks source link

[Bug] add gutka shows prev gutka stuff #18

Closed AkalUstat closed 4 years ago

AkalUstat commented 4 years ago

Possible fix: use map instead of flatlist (its not updating correctly)

Or realm may fix this

AkalUstat commented 4 years ago

This bug is much more complex than previously expected, moving up in prioroity. Aim to have done by this weekend

AkalUstat commented 4 years ago

Debugging reveals 3 things:

AkalUstat commented 4 years ago

Culprits: AddToGutka = (entryid, entrytype) => { const newObj = { id: entryid, type: entrytype } const allGutkas = this.state.gutkas; allGutkas.find(g => g.name === this.state.currentGutkaName).items = [...this.state.currentGutka, newObj]; this.setState(prevState => ({ currentGutka: [...prevState.currentGutka, newObj] })) AsyncStorage.setItem(${GUTKAS_KEY}, JSON.stringify(allGutkas)); } and updateCurrentGutka = (newGutka) => this.setState({ currentGutkaName: newGutka });

AkalUstat commented 4 years ago

also gets attempt to spread unspreadable instance

AkalUstat commented 4 years ago

Ok problem with code is that solution that came up in debugging is trying to spread an object: https://stackoverflow.com/questions/53991403/typeerror-invalid-attempt-to-spread-non-iterable-instance

AkalUstat commented 4 years ago

also try to use this, as it may also be causing problems in createGutka and addToGutka (from fetchGutkas):

const filteredItems = _.values(normalized.find(gutka => gutka.name === currGutka).items); this.setState({ isDataReady: true, gutkas: normalized, currentGutkaName: currGutka, currentGutka: filteredItems });

AkalUstat commented 4 years ago

Also just create a find current gutka method so i don't have repetitive code (and just have a state modifier functions list

AkalUstat commented 4 years ago

Try to finish today

AkalUstat commented 4 years ago

Upon further contemplation, instead of rewriting once and then rewriting again, finish with #21 #19

AkalUstat commented 4 years ago

Final conclusion: resultant of reassigning to diff object type. Fixing with type declarations...can reinstate flatlist