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

Make it easier to use write hooks that involve passing references from preceding write operations #29

Open
achou11 opened this issue Jan 13, 2025 · 0 comments

Comments

@achou11
Copy link
Member

achou11 commented Jan 13, 2025

Extracted from #20

The most notable example of this is when creating/updating observations that have attachments. Right now, the end-user has to work with the relevant write hook to create the attachment(s) prior to creating the observation e.g.

const createBlob = useCreateBlob(...)

const createObservation = useCreateDoc({ docType: 'observation', ... })

// Example of a single attachment
function onPress() {
  createBlob.mutate(..., {
    onSuccess: (blob) => {
      // Create observation that references blob after its creation
      createObservation.mutate({ value: { attachments: [{ ...blob, driveDiscoveryId: blob.driveId }] }, ...})
    }
  })
}

// Example of multiple attachments
function onPress() {
  const blobs = await Promise.all([
    // Necessary if using useCreateBlob() because we don't expose a Promise-based method like React Query's `mutateAsync()`
    new Promise((res , rej) => createBlob.mutate(..., { onSuccess: res, onError: rej})),
    new Promise((res , rej) => createBlob.mutate(..., { onSuccess: res, onError: rej})),    
  ])

  // Create observation that has multiple attachments
  createObservation.mutate({ value: { attachments: blobs.map((b) => ({ ...b, driveDiscoveryId: blob.driveId })), ... } })
}

The idea would be to have something similar to what the original issue outlined such that the end-user code could look more like this:

createObservation.mutate({ value: ..., attachmentsToAdd: [...] })

As mentioned in #26, I didn't figure out a satisfactory way of implementing this and decided to leave that as a follow-up, since it's mostly for end-usage convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant