Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joining refs & adding URLs within hooks #859

Open
achou11 opened this issue Nov 25, 2024 · 0 comments
Open

Joining refs & adding URLs within hooks #859

achou11 opened this issue Nov 25, 2024 · 0 comments

Comments

@achou11
Copy link
Member

achou11 commented Nov 25, 2024

Several of our data types reference other data types. Currently we load each data type separately within hooks, then join them within components (e.g. here). This results in cascades of async code within multiple components.

Several data types also have URLs (e.g. preset -> iconUrl, attachment -> attachmentUrl), which we currently also fetch asynchronously within components. This similarly results in cascades of async code.

Moving all of this inside the mapeo core hooks could greatly simplify logic within components, e.g.

const presetsWithFields: Array<Omit<Preset, 'fieldRef'>, & { field: Field }> = usePresets({ with: 'fieldRef' })
const observations: Array<Observation & { attachments: Array<Observation['attachment'] & { originalUrl: string }> }> = useObservations()

This creates a clear boundary for async code interacting with the API, rather than having multiple places in different components where we are loading data. At some point, for the sake of performance, we can move some of these joins into the backend, so in the meantime moving this within the hooks will make that a smoother transition.

@achou11 achou11 converted this from a draft issue Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant