Skip to content

Commit 3be08c0

Browse files
authored
feat: new geoJSON and zip file export api (#85)
* chore: update dependencies * feat: created export geoJSON hook * feat: created export zip file hook * chore: exported new hooks * chore: update props * chore: docs
1 parent 383c081 commit 3be08c0

File tree

6 files changed

+248
-22
lines changed

6 files changed

+248
-22
lines changed

docs/API.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
- [useConnectSyncServers](#useconnectsyncservers)
3030
- [useDisconnectSyncServers](#usedisconnectsyncservers)
3131
- [useSetAutostopDataSyncTimeout](#usesetautostopdatasynctimeout)
32+
- [useExportGeoJSON](#useexportgeojson)
33+
- [useExportZipFile](#useexportzipfile)
3234
- [useSingleDocByDocId](#usesingledocbydocid)
3335
- [useSingleDocByVersionId](#usesingledocbyversionid)
3436
- [useManyDocs](#usemanydocs)
@@ -547,6 +549,32 @@ Provides the progress of data sync for sync-enabled connected peers
547549
| ---------- | ---------- |
548550
| `useSetAutostopDataSyncTimeout` | `({ projectId, }: { projectId: string; }) => { error: Error; mutate: UseMutateFunction<void, Error, { after: number or null; }, unknown>; mutateAsync: UseMutateAsyncFunction<void, Error, { ...; }, unknown>; reset: () => void; status: "error"; } or { ...; }` |
549551

552+
### useExportGeoJSON
553+
554+
Creates a GeoJson file with all the observations and/or tracks in the project.
555+
556+
| Function | Type |
557+
| ---------- | ---------- |
558+
| `useExportGeoJSON` | `({ projectId }: { projectId: string; }) => { error: Error; mutate: UseMutateFunction<string, Error, { path: string; exportOptions: { observations?: boolean or undefined; tracks?: boolean or undefined; lang?: string or undefined; }; }, unknown>; mutateAsync: UseMutateAsyncFunction<...>; reset: () => void; status: "error...` |
559+
560+
Parameters:
561+
562+
* `opts.projectId`: Public ID of the project to apply changes to.
563+
564+
565+
### useExportZipFile
566+
567+
Creates a zip file containing a GeoJson file with all the observations and/or tracks in the project and all associated attachments (photos and audio).
568+
569+
| Function | Type |
570+
| ---------- | ---------- |
571+
| `useExportZipFile` | `({ projectId }: { projectId: string; }) => { error: Error; mutate: UseMutateFunction<string, Error, { path: string; exportOptions: { observations?: boolean or undefined; tracks?: boolean or undefined; lang?: string or undefined; attachments?: boolean or undefined; }; }, unknown>; mutateAsync: UseMutateAsyncFunction<...>...` |
572+
573+
Parameters:
574+
575+
* `opts.projectId`: Public ID of the project to apply changes to.
576+
577+
550578
### useSingleDocByDocId
551579

552580
Retrieve a single document from the database based on the document's document ID.

package-lock.json

Lines changed: 131 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
"types": "tsc"
5858
},
5959
"peerDependencies": {
60-
"@comapeo/core": "^3.1.0",
60+
"@comapeo/core": "^3.2.0",
6161
"@comapeo/ipc": "^3.0.0",
6262
"@comapeo/schema": "*",
6363
"@tanstack/react-query": "^5",
6464
"react": "^18 || ^19"
6565
},
6666
"devDependencies": {
67-
"@comapeo/core": "3.1.2",
67+
"@comapeo/core": "3.2.0",
6868
"@comapeo/ipc": "3.0.0",
6969
"@comapeo/schema": "1.6.0",
7070
"@eslint/compat": "1.2.9",

src/hooks/projects.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
createProjectMutationOptions,
2020
disconnectSyncServersMutationOptions,
2121
documentCreatedByQueryOptions,
22+
exportGeoJSONMutationOptions,
23+
exportZipFileMutationOptions,
2224
iconUrlQueryOptions,
2325
importProjectConfigMutationOptions,
2426
leaveProjectMutationOptions,
@@ -610,3 +612,37 @@ export function useSetAutostopDataSyncTimeout({
610612
? { error, mutate, mutateAsync, reset, status }
611613
: { error: null, mutate, mutateAsync, reset, status }
612614
}
615+
616+
/**
617+
* Creates a GeoJson file with all the observations and/or tracks in the project.
618+
*
619+
* @param opts.projectId Public ID of the project to apply changes to.
620+
*/
621+
export function useExportGeoJSON({ projectId }: { projectId: string }) {
622+
const { data: projectApi } = useSingleProject({ projectId })
623+
624+
const { error, mutate, mutateAsync, reset, status } = useMutation(
625+
exportGeoJSONMutationOptions({ projectApi }),
626+
)
627+
628+
return status === 'error'
629+
? { error, mutate, mutateAsync, reset, status }
630+
: { error: null, mutate, mutateAsync, reset, status }
631+
}
632+
633+
/**
634+
* Creates a zip file containing a GeoJson file with all the observations and/or tracks in the project and all associated attachments (photos and audio).
635+
*
636+
* @param opts.projectId Public ID of the project to apply changes to.
637+
*/
638+
export function useExportZipFile({ projectId }: { projectId: string }) {
639+
const { data: projectApi } = useSingleProject({ projectId })
640+
641+
const { error, mutate, mutateAsync, reset, status } = useMutation(
642+
exportZipFileMutationOptions({ projectApi }),
643+
)
644+
645+
return status === 'error'
646+
? { error, mutate, mutateAsync, reset, status }
647+
: { error: null, mutate, mutateAsync, reset, status }
648+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export {
4848
useStopSync,
4949
useSyncState,
5050
useUpdateProjectSettings,
51+
useExportGeoJSON,
52+
useExportZipFile,
5153
} from './hooks/projects.js'
5254
export { type SyncState } from './lib/sync.js'
5355
export {

src/lib/react-query/projects.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,52 @@ export function setAutostopDataSyncTimeoutMutationOptions({
517517
},
518518
} satisfies UseMutationOptions<void, Error, { after: number | null }>
519519
}
520+
521+
export function exportGeoJSONMutationOptions({
522+
projectApi,
523+
}: {
524+
projectApi: MapeoProjectApi
525+
}) {
526+
return {
527+
...baseMutationOptions(),
528+
mutationFn: async (opts) => {
529+
return projectApi.exportGeoJSONFile(opts.path, opts.exportOptions)
530+
},
531+
} satisfies UseMutationOptions<
532+
string,
533+
Error,
534+
{
535+
path: string
536+
exportOptions: {
537+
observations?: boolean
538+
tracks?: boolean
539+
lang?: string
540+
}
541+
}
542+
>
543+
}
544+
545+
export function exportZipFileMutationOptions({
546+
projectApi,
547+
}: {
548+
projectApi: MapeoProjectApi
549+
}) {
550+
return {
551+
...baseMutationOptions(),
552+
mutationFn: async (opts) => {
553+
return projectApi.exportZipFile(opts.path, opts.exportOptions)
554+
},
555+
} satisfies UseMutationOptions<
556+
string,
557+
Error,
558+
{
559+
path: string
560+
exportOptions: {
561+
observations?: boolean
562+
tracks?: boolean
563+
lang?: string
564+
attachments?: boolean
565+
}
566+
}
567+
>
568+
}

0 commit comments

Comments
 (0)