This repository was archived by the owner on Jun 15, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathWorkspaceInputModal.tsx
More file actions
61 lines (53 loc) · 2.25 KB
/
WorkspaceInputModal.tsx
File metadata and controls
61 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { ButtonCell } from '@Root/Components/ButtonCell'
import { SectionedTableCell } from '@Root/Components/SectionedTableCell'
import { TableSection } from '@Root/Components/TableSection'
import { useSafeApplicationContext } from '@Root/Hooks/useSafeApplicationContext'
import { ModalStackNavigationProp } from '@Root/ModalStack'
import { SCREEN_INPUT_MODAL_WORKSPACE_NAME } from '@Root/Screens/screens'
import { ThemeServiceContext } from '@Style/ThemeService'
import React, { FC, useContext, useEffect, useRef, useState } from 'react'
import { TextInput } from 'react-native'
import { Container, Input } from './InputModal.styled'
type Props = ModalStackNavigationProp<typeof SCREEN_INPUT_MODAL_WORKSPACE_NAME>
export const WorkspaceInputModal: FC<Props> = props => {
const { descriptor, renameWorkspace } = props.route.params
const themeService = useContext(ThemeServiceContext)
const application = useSafeApplicationContext()
const workspaceNameInputRef = useRef<TextInput>(null)
const [workspaceName, setWorkspaceName] = useState(descriptor.label)
const onSubmit = async () => {
const trimmedWorkspaceName = workspaceName.trim()
if (trimmedWorkspaceName === '') {
setWorkspaceName(descriptor.label)
await application?.alertService.alert('Workspace name cannot be empty')
workspaceNameInputRef.current?.focus()
return
}
await renameWorkspace(descriptor, trimmedWorkspaceName)
void application.sync.sync()
props.navigation.goBack()
}
useEffect(() => {
workspaceNameInputRef.current?.focus()
}, [])
return (
<Container>
<TableSection>
<SectionedTableCell textInputCell first={true}>
<Input
ref={workspaceNameInputRef as any}
placeholder={'Workspace name'}
onChangeText={setWorkspaceName}
value={workspaceName}
autoCorrect={false}
autoCapitalize={'none'}
keyboardAppearance={themeService?.keyboardColorForActiveTheme()}
underlineColorAndroid={'transparent'}
onSubmitEditing={onSubmit}
/>
</SectionedTableCell>
<ButtonCell maxHeight={45} disabled={workspaceName.length === 0} title={'Save'} bold onPress={onSubmit} />
</TableSection>
</Container>
)
}