BigJk / snd

Sales & Dungeons — Thermal Printer as D&D / TTRPG Utility
https://sales-and-dungeons.app/
MIT License
500 stars 17 forks source link

Add headless folder import/export functionality via File API (if available) #35

Closed nbadal closed 1 year ago

nbadal commented 1 year ago

This uses a JSON blob format to pass file contents to/from the backend. I also refactored the adjacent folder code to use await/async as well.

Single file operations to follow soon.

BigJk commented 1 year ago

First of all thank you for making that work! This is definitely the right approach for making file access work in headless mode and the JSON import in the backend is fine as it is 👍

After further reconsideration I would like to stick to basic promise usage at least in the components themselves as mithril's lifecycle methods can't be async anyways. You can keep the async usage in your file api if you want. async is just syntactic sugar for promises we can still consume the functions in the component.

The mentioned bug about the modal not closing is also related to async. You changed the onimport to being async while the modal components expects a non-async function. This makes the re-render not trigger or triggering at the wrong moment.

I provided a example above how to use chained promises to consume your file functions without async and still keep this quite simple.

BigJk commented 1 year ago

Looks 💯 as far as I can see! Thanks a lot.