-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds button in settings tab to create test data.
- Loading branch information
Showing
2 changed files
with
35 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
import * as React from 'react' | ||
import { createFileRoute } from '@tanstack/react-router' | ||
import { createFileRoute, useNavigate } from '@tanstack/react-router' | ||
|
||
import { Button } from '../../components/Button' | ||
import { Text } from '../../components/Text' | ||
import { useActiveProjectIdStoreState } from '../../contexts/ActiveProjectIdProvider' | ||
import { useCreateTestObservations } from '../../hooks/mutations/useCreateTestObservations' | ||
|
||
export const Route = createFileRoute('/(MapTabs)/_Map/tab2')({ | ||
component: Settings, | ||
}) | ||
|
||
export function Settings() { | ||
const { mutate: createTestData, isPending } = useCreateTestObservations() | ||
|
||
const projectId = useActiveProjectIdStoreState((s) => s.activeProjectId) | ||
const navigate = useNavigate() | ||
|
||
function handleCreateTestData() { | ||
if (!projectId) { | ||
console.error('No active project selected. Cannot create test data.') | ||
return | ||
} | ||
createTestData( | ||
{ projectId: projectId, count: 20 }, | ||
{ | ||
onSuccess: () => { | ||
navigate({ to: '/main' }) | ||
}, | ||
onError: (err) => { | ||
console.error('Error creating test data', err) | ||
}, | ||
}, | ||
) | ||
} | ||
|
||
return ( | ||
<div> | ||
<Text>Tab 2</Text> | ||
<div style={{ padding: 16 }}> | ||
<Text kind="title" style={{ marginBottom: 8 }}> | ||
Settings | ||
</Text> | ||
<Button onClick={handleCreateTestData} disabled={isPending}> | ||
{isPending ? 'Creating...' : 'Create 20 Test Observations'} | ||
</Button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters