-
I am currently making an event subscription system, where a customer can subscribe to events (each page is certain event type). On particular page there is a schedule with dates and times of events. Each term for particular term is a block, inside parent block which is container of these inner blocks (yes, Innerblocks component is used to facilitate this). Now, I keep the data of each term both in attributes of the block, and also in meta of post (as array of objects - each object has data for particular term: start date, end date, start time, end time, city). Start date is also saved in third data source, custom MySql table, because these data have to be displayed in front end as table and sorted according to start date and this is not possible with meta data as array. I cannot get how to remove related data from both metadata and table when term block is removed (how to start deletion when post is saved). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I succeeded. In a nutshell, I registered custom Entity, as interface to REST API with addEntities and provided custom rest points to save data in a custom MySQL table. Handling of data (saving and deleting) from custom table is in parent block which has innerBlocks and wrapped in useEffect (because it is really a side-effect) and it triggers on saving a parent block in editor. For the metadata, all is handled in innerBlocks - I used useDebounce hook to save metadata, since I observed entering gets laggy if saving of metadata is not debounced. Finally, a very tricky part was detecting of innerBlock removal - removing of metadata is in useEffect cleanup function, but [attributes.id] is given as dependency, since if there are no dependencies, useEffect cleanup function fires too late for metadata cleanup, when attributes and hooks are already destroyed and not available. I will describe all that in more detail if anyone is interested. |
Beta Was this translation helpful? Give feedback.
I succeeded. In a nutshell, I registered custom Entity, as interface to REST API with addEntities and provided custom rest points to save data in a custom MySQL table. Handling of data (saving and deleting) from custom table is in parent block which has innerBlocks and wrapped in useEffect (because it is really a side-effect) and it triggers on saving a parent block in editor.
For the metadata, all is handled in innerBlocks - I used useDebounce hook to save metadata, since I observed entering gets laggy if saving of metadata is not debounced.
Finally, a very tricky part was detecting of innerBlock removal - removing of metadata is in useEffect cleanup function, but [attributes.id] is give…