Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load more/append to list #1487

Closed
paul-uz opened this issue Jul 29, 2024 · 11 comments
Closed

Load more/append to list #1487

paul-uz opened this issue Jul 29, 2024 · 11 comments

Comments

@paul-uz
Copy link

paul-uz commented Jul 29, 2024

Using the older version of Inquirer, is there a way to load a list, and have a way to append to the list?

EG I pull list data from an external API, but just the first page, and the list shows a "more" option which loads and appends page 2 etc etc

@SBoudrias
Copy link
Owner

Hi, thanks for the question.

This isn't a feature supported in any versions - it might be through a plugin, but I don't see one documented.

As is, I think this would be better suited for a custom prompt. I feel pagination APIs would add a large surface to the core; and I'm not yet convinced of how wide the need for this is.

I'm happy to document a custom prompt in the readme plugins.

@paul-uz
Copy link
Author

paul-uz commented Jul 29, 2024

Yea, i am looking at making a custom prompt, but I'm confused by the docs/existing plugins.

None of them seem to be written i the same manner, and I can't figure out what I need to do for the older version of inquirer. The docs seem to suggest they are for @inquirer/prompts and not the old version.

Would you happen to have a boilerplate custom prompt for the old version that I can look at?

@SBoudrias
Copy link
Owner

If you update to inquirer@^10.0.0, you can write plugins with @inquirer/core. I would highly recommend that since the API is much simpler and easier to use.

If you don't update inquirer, I'd still recommend doing it this way. But then you mix the standalone prompt function you create and inquirer.prompts() - no reason they can't be used together.

There's no documentation for the old class style plugins - these were all hacked together hacking into internal APIs.

@paul-uz
Copy link
Author

paul-uz commented Jul 30, 2024

With @inquirer/prompts, how do you do ask multiple questions?

In the legacy version, it was inquirer.prompt(list).then(async (answers) => {...} where list was an array of prompt types.

I might be able to upgrade, as the custom prompt I want to write would replace inquirer-search-list which is only for the legacy version. That way I can write a new style custom prompt.

@SBoudrias
Copy link
Owner

So the new API really wants to simplify flow controls. The flow utilities were useful when launching in Node 4. At that time there was no promises, etc. Now it's not useful.

What I do today is basically:

const name = await input();
const age = await number();
const parentalApproval = age < 18 ? await confirm() : true;

@paul-uz
Copy link
Author

paul-uz commented Jul 30, 2024

So the new API really wants to simplify flow controls. The flow utilities were useful when launching in Node 4. At that time there was no promises, etc. Now it's not useful.

What I do today is basically:

const name = await input();
const age = await number();
const parentalApproval = age < 18 ? await confirm() : true;

Lovely I thought as much.

Will definitely give the new version a go and try a custom prompt!

@paul-uz
Copy link
Author

paul-uz commented Jul 31, 2024

@SBoudrias hmm, so i have tried creating a custom prompt, and to be perfectly honest, it's super difficult trying to figure it out from the existing prompts and the docs, which are very confusing, with no examples.

Do you have any better documentation on how to create a prompt?

@SBoudrias
Copy link
Owner

Not as of now, the documentation is a bit raw I'll admit - it's not yet been a focus area. Are you somewhat familiar with React hooks? That would go a long way understanding the APIs.

@paul-uz
Copy link
Author

paul-uz commented Jul 31, 2024

I'm not sadly. I'm pure backend 😂

@SBoudrias
Copy link
Owner

I might start there then 😄 https://react.dev/reference/react/hooks - useState and useEffect are the important ones.

@SBoudrias
Copy link
Owner

Took some time after work to write quite a bit more documentation on the patterns to create custom prompts. I'd appreciate feedback from your experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants