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

React library for Stork #247

Open
jameslittle230 opened this issue Feb 1, 2022 · 4 comments
Open

React library for Stork #247

jameslittle230 opened this issue Feb 1, 2022 · 4 comments
Labels
improvement-request Request for new or enhanced behavior.

Comments

@jameslittle230
Copy link
Owner

jameslittle230 commented Feb 1, 2022

If you're writing a site that uses React, you should be able to npm install something and get access to Stork from the frontend.

I'm imagining an API like:

function MySearchComponent() {
    const [query, setQuery] = useState("");
    const [searchResults, setSearchResults] = useStork("https://example.com/my-index.st", "myIndex");

    const onInputChange = (event) => {
        setQuery(event.target.value);
        setSearchResults(event.target.value);
    }

    return (
        <>
            ...
            <input onChange={onInputChange} />
            <ul>
                {searchResults.results.map((result) => (<MySearchResultComponent result={result} />))}
            </ul>
        </>
    )
}

The searchResults variable would bind to an object that could hold an array of results, a number to indicate loading progress, and other bits of state. Ideally you'd be able to build the entire managed UI from the state you get from that hook.

Perhaps, for the people who want the managed UI (instead of having to style it themselves), I could expose a component:

function MyOtherSearchComponent() {
    return (
        <StorkSearch
            index="https://example.com/my-index.st"
            name="myIndex"
            onSearch={() => { /* analytics, or something */ }}
        />
    )
}

How does that look? Any initial feedback?

@healeycodes
Copy link
Contributor

This would fit my use case. I have a static blog and want to use the managed UI via React (but might want to roll my own UI in the future).

I'm not sure how to handle errors (let's say, a missing *.st file) in the initial example above. I'm guessing that useStork would throw and users could wrap MySearchComponent with an error boundary.

Overall design looks sensible 👍

@GeeWizWow
Copy link

GeeWizWow commented Jun 16, 2022

As a primary React developer, I would welcome the above API, but...

I can't help but feel that given the current status of the project, a better first step might be to expose a framework agnostic Javascript API, as well as perhaps provide a wrapper around the CLI tool to better integrate with the build pipelines used in the Javascript ecosystem (webpack?)

That would provide solid foundations for the build out of any number of framework specific APIs/ Implementations...

Edit: Sorry if a Javascript api is already exposed, I wasn't able to find one referenced in the documentation.

@jameslittle230
Copy link
Owner Author

@GeeWizWow - I want to make sure you've seen the Stork Javascript API for embedding Stork search interfaces on web pages - the React library I'm describing here would effectively wrap around this VanillaJS library.

You might be hoping to see a Stork Javascript API for building search indexes? That's definitely something I'm interested in, but haven't scoped out as much. A few other folks have created Node wrappers around the indexer binary which seems to have worked well for them.

Let me know if that helps clear up any confusion.

@GeeWizWow
Copy link

@jameslittle230 Those are exactly the things I wanted to see 🙏 Thanks for the links

@jameslittle230 jameslittle230 added improvement-request Request for new or enhanced behavior. and removed type:project labels Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement-request Request for new or enhanced behavior.
Projects
Status: Todo
Development

No branches or pull requests

3 participants