-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪚 OmniGraph™ Better output in CLI (#133)
- Loading branch information
1 parent
cf8697f
commit d21876b
Showing
31 changed files
with
389 additions
and
336 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-lz-oapp": patch | ||
--- | ||
|
||
Downgrade ink to version 3 for better interoperability |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
import('./dist/index.js'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testTimeout: 15000, | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,37 @@ | ||
import React from "react"; | ||
import { Box, Text } from "ink"; | ||
import Spinner from "ink-spinner"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { TaskState } from "@/utilities/tasks"; | ||
|
||
type ErrorComponent = React.ComponentType<{ error: unknown }>; | ||
|
||
interface Props { | ||
error: ErrorComponent; | ||
message: string; | ||
mutation: Pick<UseMutationResult, "isPending" | "isSuccess" | "error">; | ||
state: TaskState<unknown> | undefined; | ||
} | ||
|
||
export const Progress: React.FC<Props> = ({ | ||
mutation, | ||
message, | ||
error: Error, | ||
}) => { | ||
const { isPending, isSuccess, error } = mutation; | ||
|
||
export const Progress: React.FC<Props> = ({ state, message, error: Error }) => { | ||
return ( | ||
<Box flexDirection="column"> | ||
<Box> | ||
{isPending ? ( | ||
{state?.loading ? ( | ||
<Spinner /> | ||
) : isSuccess ? ( | ||
) : state?.success ? ( | ||
<Text color="green">✔</Text> | ||
) : error ? ( | ||
) : state?.failure ? ( | ||
<Text color="red">𐄂</Text> | ||
) : ( | ||
<Text color="yellow">○</Text> | ||
)} | ||
<Text> {message}</Text> | ||
</Box> | ||
|
||
{error == null ? null : ( | ||
{state?.failure ? ( | ||
<Box marginLeft={2}> | ||
<Error error={error} /> | ||
<Error error={state.error} /> | ||
</Box> | ||
)} | ||
) : null} | ||
</Box> | ||
); | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useCallback, useRef, useState } from 'react' | ||
|
||
/** | ||
* TaskState holds three different states of a task: | ||
* | ||
* - Pending state | ||
* - Success state | ||
* - Failure state | ||
*/ | ||
export type TaskState<T> = | ||
| { | ||
loading: true | ||
success?: never | ||
failure?: never | ||
data?: never | ||
error?: never | ||
} | ||
| { | ||
loading?: false | ||
success: true | ||
failure?: false | ||
data: T | ||
error?: never | ||
} | ||
| { | ||
loading?: false | ||
success?: false | ||
failure: true | ||
data?: never | ||
error: unknown | ||
} | ||
|
||
/** | ||
* Poor person's version of react-query | ||
* | ||
* Handles state management of a promise run just like useMutation() from react-query, | ||
* just with one less package and a bit less sophisticated reference checking mechanism | ||
* (especially the part where it expect the component that uses this not to unmount or change the task | ||
* at runtime) | ||
* | ||
* @param {() => Promise<T>} task | ||
* @returns | ||
*/ | ||
export const useTask = <T>(task: () => Promise<T>) => { | ||
const [state, setState] = useState<TaskState<T>>() | ||
|
||
// We'll keep the task in a reference so that we don't force the users to pass in memoized objects | ||
const taskRef = useRef(task) | ||
taskRef.current = task | ||
|
||
const run = useCallback(() => { | ||
// Set state to loading | ||
setState({ loading: true }) | ||
|
||
return taskRef.current().then( | ||
// Set state to success | ||
(data) => { | ||
return setState({ success: true, data }), Promise.resolve(data) | ||
}, | ||
// Set state to failure | ||
(error) => { | ||
return setState({ failure: true, error }), Promise.reject(error) | ||
} | ||
) | ||
}, [taskRef]) | ||
|
||
return { run, state } | ||
} |
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
Oops, something went wrong.