Skip to content

Commit 5858b99

Browse files
authored
Merge pull request #39 from povio/fix/media-queries
Add abortController and onUploadProgress for media queries
2 parents 7cf6a8e + 9c90ae0 commit 5858b99

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"
@@ -76,4 +76,4 @@
7676
"npm": ">= 8"
7777
},
7878
"packageManager": "yarn@4.2.2"
79-
}
79+
}

src/generators/templates/partials/query-use-mutation.hbs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{{! Js docs }}
22
{{{genQueryJsDocs endpoint mutation=true}}}
33
{{! Mutation definition}}
4-
export const {{queryName endpoint mutation=true}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}} }>{{#if hasMutationEffects}} & {{mutationEffectsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
4+
export const {{queryName endpoint mutation=true}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}}; abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void{{/if}} }>{{#if hasMutationEffects}} & {{mutationEffectsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
55
{{! Use acl check }}
66
{{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
77
{{! Use mutation effects }}
88
{{#if hasMutationEffects}}const { runMutationEffects } = useMutationEffects({ currentModule: {{queriesModuleName}} });{{/if}}
99

1010
return {{queryHook}}({
11-
mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}} } {{/if}}) => {{#if hasMutationFnBody}} { {{/if}}
11+
mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}}, abortController, onUploadProgress{{/if}} } {{/if}}) => {{#if hasMutationFnBody}} { {{/if}}
1212
{{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
1313
{{#if endpoint.mediaUpload}}const uploadInstructions = await {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}});
1414

@@ -17,6 +17,10 @@ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOption
1717
headers: {
1818
"Content-Type": file.type,
1919
},
20+
signal: abortController?.signal,
21+
onUploadProgress: onUploadProgress
22+
? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })
23+
: undefined,
2024
});
2125
}
2226

0 commit comments

Comments
 (0)