smeea / vdb

VTES cards search & deck building & twda search web application
MIT License
20 stars 10 forks source link

Add Missing in Inventory and generating proxy fails in PDF Proxy #36

Closed Denhomer closed 1 year ago

Denhomer commented 1 year ago

In the "PDF Proxy" page, the "Add Missing In Inventory" button is messing up the proxySelected object so that the Generate buttons fail with below error caused by the card details being missed out.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'localeCompare') at Rr (sorting.js:5:16) at Array.sort () at aa (cryptSort.js:28:22) at y (DeckProxyButton.jsx:115:25) at g (DeckProxySelectModal.jsx:176:5) at onClick (DeckProxySelectModal.jsx:232:34) at Object.Ke (react-dom.production.min.js:54:317) at et (react-dom.production.min.js:54:471) at react-dom.production.min.js:55:35 at Yr (react-dom.production.min.js:105:68)

This setProxySelected line does not do what is expected. Merging by spreading like this only does a shallow merge, where crypt and library only have the q and print attributes and each selected card loses the c attribute.

This could be solved by any deep merge solution e.g. const merge = (a,b) => Object.assign(a, ...Object.keys(b).map(k => ({[k]: typeof b[k] === 'object' ? merge(a[k], b[k]) : b[k]}))); and replace setProxySelected({ ...proxySelected, ...crypt, ...library }); with setProxySelected(merge(proxySelected, {...crypt, ...library}));

smeea commented 1 year ago

Fixed few updates ago (can't find particular commit).