Skip to content

Commit

Permalink
Adds button in settings tab to create test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
cimigree committed Jan 20, 2025
1 parent d6dd760 commit 0632df9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
38 changes: 34 additions & 4 deletions src/renderer/src/routes/(MapTabs)/_Map.tab2.tsx
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>
)
}
15 changes: 1 addition & 14 deletions src/renderer/src/routes/Onboarding/CreateProjectScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { PROJECT_NAME_MAX_LENGTH_GRAPHEMES } from '../../constants'
import { useActiveProjectIdStoreActions } from '../../contexts/ActiveProjectIdProvider'
import { useSelectProjectConfigFile } from '../../hooks/mutations/file-system'
import { useCreateProject } from '../../hooks/mutations/projects'
import { useCreateTestObservations } from '../../hooks/mutations/useCreateTestObservations'
import ProjectImage from '../../images/add_square.png'

export const m = defineMessages({
Expand Down Expand Up @@ -127,7 +126,6 @@ function CreateProjectScreenComponent() {
const [fileName, setFileName] = useState<string | undefined>()

const createProjectMutation = useCreateProject()
const createTestDataMutation = useCreateTestObservations()

const selectConfigFile = useSelectProjectConfigFile()
const { setActiveProjectId } = useActiveProjectIdStoreActions()
Expand Down Expand Up @@ -170,18 +168,7 @@ function CreateProjectScreenComponent() {
{
onSuccess: (projectId) => {
setActiveProjectId(projectId)
createTestDataMutation.mutate(
{ projectId, count: 20 },
{
onSuccess: () => {
navigate({ to: '/main' })
},
onError: (err) => {
console.error('Error creating test data', err)
navigate({ to: '/main' })
},
},
)
navigate({ to: '/main' })
},
onError: (error) => {
console.error('Error saving project:', error)
Expand Down

0 comments on commit 0632df9

Please sign in to comment.