javascript - After updating single element, updated element shows twice in my UI, spot it came from and spot it was dragged to -
i have main screen of app, there many different sections. user can drag element
section section.
the problem i'm having once user drags , drops element new section (which hits server updated info), element showing twice, once in place came from , once in place dragged to.
upon refreshing app, shows in place dragged to, correct.
i think issue lies somewhere in recieveelement
reducer, hit after update server.
would love in debugging this. thanks!
case 'receiveelement': const elementid = `${action.element.id}`; // don't add, duplicate const newstate = {...state}; // copy old state delete newstate[elementid]; // delete item object const newvisibleelementids = newstate.visibleelements.filter(id => id !== elementid); // remove item visible elements const newunplacedelementids = newstate.unplacedelements.filter(id => id !== elementid); return { ...newstate, elementsmap: { ...newstate.elementsmap, [elementid]: action.element, }, visibleelements: [...newvisibleelementids, elementid], unplacedelements: [...newunplacedelementids], };
in skyelement
react object, have following, hits server before reducer hit
enddrag(props, monitor) { if (monitor.diddrop()) { const result = monitor.getdropresult(); if (result.sectorid) { const obj = { id: props.id, sectorid: result.sectorid, slotid: result.slotid }; props.dispatch(requestupdateelement(obj)); } } },
Comments
Post a Comment