Skip to content

Commit

Permalink
chore: use write hooks from @comapeo/core-react (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 authored Jan 16, 2025
1 parent fae648a commit 9d90a5e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 70 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"valibot": "^0.42.1"
},
"devDependencies": {
"@comapeo/core-react": "1.1.0",
"@comapeo/core-react": "2.0.1",
"@electron-forge/cli": "7.6.0",
"@electron-forge/maker-deb": "7.6.0",
"@electron-forge/maker-dmg": "7.6.0",
Expand Down
20 changes: 0 additions & 20 deletions src/renderer/src/hooks/mutations/deviceInfo.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/renderer/src/hooks/mutations/projects.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/renderer/src/routes/Onboarding/CreateProjectScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, type ChangeEvent } from 'react'
import { useCreateProject } from '@comapeo/core-react'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import {
Accordion,
Expand All @@ -22,7 +23,6 @@ import { Text } from '../../components/Text'
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 ProjectImage from '../../images/add_square.png'

export const m = defineMessages({
Expand Down Expand Up @@ -177,9 +177,10 @@ function CreateProjectScreenComponent() {
)
}

const backPressHandler = createProjectMutation.isPending
? undefined
: () => navigate({ to: '/Onboarding/CreateJoinProjectScreen' })
const backPressHandler =
createProjectMutation.status === 'pending'
? undefined
: () => navigate({ to: '/Onboarding/CreateJoinProjectScreen' })

const topMenu = (
<OnboardingTopMenu currentStep={3} onBackPress={backPressHandler} />
Expand Down Expand Up @@ -288,10 +289,12 @@ function CreateProjectScreenComponent() {
maxWidth: 350,
padding: '12px 20px',
}}
disabled={createProjectMutation.isPending}
disabled={createProjectMutation.status === 'pending'}
>
{formatMessage(
createProjectMutation.isPending ? m.saving : m.createProject,
createProjectMutation.status === 'pending'
? m.saving
: m.createProject,
)}
</Button>
</OnboardingScreenLayout>
Expand Down
27 changes: 15 additions & 12 deletions src/renderer/src/routes/Onboarding/DeviceNamingScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, type ChangeEvent } from 'react'
import { useSetOwnDeviceInfo } from '@comapeo/core-react'
import { TextField } from '@mui/material'
import { styled } from '@mui/material/styles'
import { createFileRoute, useNavigate } from '@tanstack/react-router'
Expand All @@ -14,7 +15,6 @@ import {
} from '../../components/Onboarding/onboardingLogic'
import { Text } from '../../components/Text'
import { DEVICE_NAME_MAX_LENGTH_GRAPHEMES } from '../../constants'
import { useEditDeviceInfo } from '../../hooks/mutations/deviceInfo'
import DeviceImage from '../../images/device.png'

export const m = defineMessages({
Expand Down Expand Up @@ -91,7 +91,7 @@ export function DeviceNamingScreenComponent() {
const [deviceName, setDeviceName] = useState('')
const [inputError, setInputError] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const setDeviceNameMutation = useEditDeviceInfo()
const setDeviceInfoMutation = useSetOwnDeviceInfo()

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value
Expand All @@ -112,15 +112,18 @@ export function DeviceNamingScreenComponent() {
setInputError(true)
return
}
setDeviceNameMutation.mutate(deviceName, {
onSuccess: () => {
navigate({ to: '/Onboarding/CreateJoinProjectScreen' })
setDeviceInfoMutation.mutate(
{ deviceType: 'desktop', name: deviceName },
{
onSuccess: () => {
navigate({ to: '/Onboarding/CreateJoinProjectScreen' })
},
onError: (error) => {
console.error('Error setting device name:', error)
setErrorMessage(formatMessage(m.errorSavingDeviceName))
},
},
onError: (error) => {
console.error('Error setting device name:', error)
setErrorMessage(formatMessage(m.errorSavingDeviceName))
},
})
)
}

const topMenu = (
Expand Down Expand Up @@ -183,9 +186,9 @@ export function DeviceNamingScreenComponent() {
maxWidth: 350,
padding: 12,
}}
disabled={setDeviceNameMutation.isPending || inputError}
disabled={setDeviceInfoMutation.status === 'pending' || inputError}
>
{setDeviceNameMutation.isPending
{setDeviceInfoMutation.status === 'pending'
? formatMessage(m.saving)
: formatMessage(m.addName)}
</Button>
Expand Down

0 comments on commit 9d90a5e

Please sign in to comment.