mirror of
https://github.com/EthanShoeDev/fressh.git
synced 2026-01-11 14:22:51 +00:00
commit
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
|
import SSHClient, { PtyType } from '@dylankenneally/react-native-ssh-sftp'
|
||||||
import { createFormHook, createFormHookContexts } from '@tanstack/react-form'
|
import { createFormHook, createFormHookContexts } from '@tanstack/react-form'
|
||||||
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'
|
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'
|
||||||
|
|
||||||
const { fieldContext, formContext } = createFormHookContexts()
|
const { fieldContext, formContext } = createFormHookContexts()
|
||||||
|
|
||||||
|
// https://tanstack.com/form/latest/docs/framework/react/quick-start
|
||||||
function TextField(
|
function TextField(
|
||||||
props: React.ComponentProps<typeof TextInput> & {
|
props: React.ComponentProps<typeof TextInput> & {
|
||||||
label?: string
|
label?: string
|
||||||
@@ -100,14 +102,28 @@ export default function Index() {
|
|||||||
password: '',
|
password: '',
|
||||||
},
|
},
|
||||||
validators: {
|
validators: {
|
||||||
onSubmitAsync: async (values) => {
|
onSubmitAsync: async ({ value }) => {
|
||||||
// we will connect here.
|
// we will connect here.
|
||||||
// if connection fails, tanstack form will know the form is in an error state.
|
// if connection fails, tanstack form will know the form is in an error state.
|
||||||
|
|
||||||
// we can read that state from the field.state.meta.errors (or errorMap)
|
// we can read that state from the field.state.meta.errors (or errorMap)
|
||||||
//
|
//
|
||||||
|
SSHClient.connectWithPassword(
|
||||||
|
value.host,
|
||||||
|
value.port,
|
||||||
|
value.username,
|
||||||
|
value.password,
|
||||||
|
).then(async (client) => {
|
||||||
|
alert('Connected')
|
||||||
|
client.on('Shell', (data) => {
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
await client.startShell(PtyType.XTERM)
|
||||||
|
|
||||||
console.log(values)
|
setTimeout(() => {
|
||||||
|
client.disconnect()
|
||||||
|
}, 5_000)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -188,7 +204,12 @@ export default function Index() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<View style={styles.actions}>
|
<View style={styles.actions}>
|
||||||
<connectionForm.SubmitButton title="Connect" />
|
<connectionForm.SubmitButton
|
||||||
|
title="Connect"
|
||||||
|
onPress={() => {
|
||||||
|
connectionForm.handleSubmit()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
</connectionForm.AppForm>
|
</connectionForm.AppForm>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user