Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- [useConnectSyncServers](#useconnectsyncservers)
- [useDisconnectSyncServers](#usedisconnectsyncservers)
- [useSetAutostopDataSyncTimeout](#usesetautostopdatasynctimeout)
- [useExportGeoJSON](#useexportgeojson)
- [useExportZipFile](#useexportzipfile)
- [useSingleDocByDocId](#usesingledocbydocid)
- [useSingleDocByVersionId](#usesingledocbyversionid)
- [useManyDocs](#usemanydocs)
Expand Down Expand Up @@ -547,6 +549,32 @@ Provides the progress of data sync for sync-enabled connected peers
| ---------- | ---------- |
| `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 { ...; }` |

### useExportGeoJSON

Creates a GeoJson file with all the observations and/or tracks in the project.

| Function | Type |
| ---------- | ---------- |
| `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...` |

Parameters:

* `opts.projectId`: Public ID of the project to apply changes to.


### useExportZipFile

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).

| Function | Type |
| ---------- | ---------- |
| `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<...>...` |

Parameters:

* `opts.projectId`: Public ID of the project to apply changes to.


### useSingleDocByDocId

Retrieve a single document from the database based on the document's document ID.
Expand Down
151 changes: 131 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
"types": "tsc"
},
"peerDependencies": {
"@comapeo/core": "^3.1.0",
"@comapeo/core": "^3.2.0",
"@comapeo/ipc": "^3.0.0",
"@comapeo/schema": "*",
"@tanstack/react-query": "^5",
"react": "^18 || ^19"
},
"devDependencies": {
"@comapeo/core": "3.1.2",
"@comapeo/core": "3.2.0",
"@comapeo/ipc": "3.0.0",
"@comapeo/schema": "1.6.0",
"@eslint/compat": "1.2.9",
Expand Down
36 changes: 36 additions & 0 deletions src/hooks/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
createProjectMutationOptions,
disconnectSyncServersMutationOptions,
documentCreatedByQueryOptions,
exportGeoJSONMutationOptions,
exportZipFileMutationOptions,
iconUrlQueryOptions,
importProjectConfigMutationOptions,
leaveProjectMutationOptions,
Expand Down Expand Up @@ -610,3 +612,37 @@ export function useSetAutostopDataSyncTimeout({
? { error, mutate, mutateAsync, reset, status }
: { error: null, mutate, mutateAsync, reset, status }
}

/**
* Creates a GeoJson file with all the observations and/or tracks in the project.
*
* @param opts.projectId Public ID of the project to apply changes to.
*/
export function useExportGeoJSON({ projectId }: { projectId: string }) {
const { data: projectApi } = useSingleProject({ projectId })

const { error, mutate, mutateAsync, reset, status } = useMutation(
exportGeoJSONMutationOptions({ projectApi }),
)

return status === 'error'
? { error, mutate, mutateAsync, reset, status }
: { error: null, mutate, mutateAsync, reset, status }
}

/**
* 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).
*
* @param opts.projectId Public ID of the project to apply changes to.
*/
export function useExportZipFile({ projectId }: { projectId: string }) {
const { data: projectApi } = useSingleProject({ projectId })

const { error, mutate, mutateAsync, reset, status } = useMutation(
exportZipFileMutationOptions({ projectApi }),
)

return status === 'error'
? { error, mutate, mutateAsync, reset, status }
: { error: null, mutate, mutateAsync, reset, status }
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export {
useStopSync,
useSyncState,
useUpdateProjectSettings,
useExportGeoJSON,
useExportZipFile,
} from './hooks/projects.js'
export { type SyncState } from './lib/sync.js'
export {
Expand Down
49 changes: 49 additions & 0 deletions src/lib/react-query/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,52 @@ export function setAutostopDataSyncTimeoutMutationOptions({
},
} satisfies UseMutationOptions<void, Error, { after: number | null }>
}

export function exportGeoJSONMutationOptions({
projectApi,
}: {
projectApi: MapeoProjectApi
}) {
return {
...baseMutationOptions(),
mutationFn: async (opts) => {
return projectApi.exportGeoJSONFile(opts.path, opts.exportOptions)
},
} satisfies UseMutationOptions<
string,
Error,
{
path: string
exportOptions: {
observations?: boolean
tracks?: boolean
lang?: string
}
}
>
}

export function exportZipFileMutationOptions({
projectApi,
}: {
projectApi: MapeoProjectApi
}) {
return {
...baseMutationOptions(),
mutationFn: async (opts) => {
return projectApi.exportZipFile(opts.path, opts.exportOptions)
},
} satisfies UseMutationOptions<
string,
Error,
{
path: string
exportOptions: {
observations?: boolean
tracks?: boolean
lang?: string
attachments?: boolean
}
}
>
}
Loading