|
| 1 | +import { Box, Text, useInput, useStdout } from "ink"; |
| 2 | +import React, { useEffect, useLayoutEffect } from 'react'; |
| 3 | +import { Form } from '../Form.js'; |
| 4 | +import { clearInterval } from 'node:timers'; |
| 5 | +import { FullScreen } from '../FullScreen.js'; |
| 6 | + |
| 7 | +let counter = 0; |
| 8 | + |
| 9 | +export function Test() { |
| 10 | + const stdout = useStdout(); |
| 11 | + |
| 12 | + const [isSubmitted, setIsSubmitted] = React.useState(false); |
| 13 | + const [showPrompt, setShowPrompt] = React.useState(false); |
| 14 | + |
| 15 | + useLayoutEffect(() => { |
| 16 | + stdout.write('This is ap revious message\n') |
| 17 | + |
| 18 | + setTimeout(() => { |
| 19 | + process.stdout.write('\x1b[?1049h'); |
| 20 | + process.stdout.write('\x1b[?1000h'); |
| 21 | + setShowPrompt(true) |
| 22 | + }, 3000); |
| 23 | + |
| 24 | + }, []); |
| 25 | + |
| 26 | + useEffect(() => { |
| 27 | + const id = setInterval(() => { |
| 28 | + if (isSubmitted) { |
| 29 | + stdout.write('hi\n') |
| 30 | + counter++; |
| 31 | + } |
| 32 | + |
| 33 | + if (counter >= 1) { |
| 34 | + clearInterval(id) |
| 35 | + } |
| 36 | + }, 1000) |
| 37 | + }, [isSubmitted]); |
| 38 | + |
| 39 | + return (<Box flexDirection='column'> |
| 40 | + {!isSubmitted && showPrompt && ( |
| 41 | + <Form |
| 42 | + onSubmit={value => { |
| 43 | + process.stdout.write('\x1b[?1049l'); |
| 44 | + process.stdout.write('\x1b[?1000l'); |
| 45 | + setIsSubmitted(true) |
| 46 | + }} |
| 47 | + form={{ |
| 48 | + title: "Form title", |
| 49 | + sections: [ |
| 50 | + { |
| 51 | + title: "asdf-global", |
| 52 | + fields: [ |
| 53 | + { type: 'string', name: 'plugin', label: 'plugin', required: true }, |
| 54 | + { type: 'string', name: 'version', label: 'version', required: true }, |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + title: "asdf-install", |
| 59 | + fields: [ |
| 60 | + { type: 'string', name: 'directory', label: 'directory', required: true }, |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + title: "asdf-local", |
| 65 | + fields: [ |
| 66 | + { type: 'string', name: 'plugin', label: 'plugin', required: true }, |
| 67 | + { type: 'string', name: 'version', label: 'version', required: true }, |
| 68 | + { type: 'string', name: 'directory', label: 'directory' }, |
| 69 | + { type: 'string', name: 'directories', label: 'directories' }, |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + title: "asdf-plugin", |
| 74 | + fields: [ |
| 75 | + { type: 'string', name: 'plugin', label: 'plugin', required: true }, |
| 76 | + { type: 'string', name: 'versions', label: 'version'}, |
| 77 | + { type: 'string', name: 'gitUrl', label: 'plugin' }, |
| 78 | + ] |
| 79 | + }, |
| 80 | + ] |
| 81 | + }} |
| 82 | + /> |
| 83 | + )} |
| 84 | + { |
| 85 | + isSubmitted && ( |
| 86 | + <Text color={'green'}>Submitted!!</Text> |
| 87 | + ) |
| 88 | + } |
| 89 | + </Box>) |
| 90 | + |
| 91 | +} |
0 commit comments