-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lazy loading in command change (#92)
* feat: option lazy loading * fix: debounce in select input --------- Co-authored-by: kidneyweak <[email protected]>
- Loading branch information
1 parent
4479aa9
commit 277d64c
Showing
7 changed files
with
69 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import React, { useState, useMemo } from 'react' | ||
import { Text, Box } from 'ink' | ||
import CommandContext from '../services/commandContext' | ||
|
||
interface TerminalProps { | ||
type: string | ||
} | ||
|
||
export default function Terminal (props: TerminalProps) { | ||
const commandContext = new CommandContext() | ||
const [output, setOutput] = useState('') | ||
useEffect(() => { | ||
const [output, setOutput] = useState<string>('') | ||
const [loading, setLoading] = useState(false) | ||
|
||
useMemo(() => { | ||
let isCancelled = false | ||
|
||
const fetchCommandHelp = async () => { | ||
const result = await commandContext.getCommandHelp(props.type) | ||
setOutput(result) | ||
setLoading(true) | ||
|
||
try { | ||
const result = await commandContext.getCommandHelp(props.type) | ||
if (!isCancelled) { | ||
setOutput(result) | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching command help: ${error}`) | ||
} | ||
|
||
setLoading(false) | ||
} | ||
fetchCommandHelp().catch((err) => { | ||
console.log(err) | ||
|
||
setOutput('') | ||
fetchCommandHelp().catch((error) => { | ||
console.error(`Error fetching command help: ${error}`) | ||
}) | ||
|
||
return () => { | ||
isCancelled = true | ||
} | ||
}, [props.type]) | ||
|
||
return ( | ||
<> | ||
<Box width={125} height={16} marginBottom={2} paddingBottom={2} flexDirection="column"> | ||
<Text>Command output:</Text> | ||
<Box marginTop={1}> | ||
<Text wrap="truncate-end">{output}</Text> | ||
{loading ? ( | ||
<></> | ||
) : ( | ||
<Text wrap="truncate-end"> | ||
{output} | ||
</Text> | ||
)} | ||
</Box> | ||
</> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters