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

Search current state using loading ref #129

Open
roberto910907 opened this issue Aug 4, 2024 · 4 comments
Open

Search current state using loading ref #129

roberto910907 opened this issue Aug 4, 2024 · 4 comments

Comments

@roberto910907
Copy link

roberto910907 commented Aug 4, 2024

Is it possible to implement an extra option when destructuring the composable to get the search current state?

const { result, search, loading } = useMeiliSearch('my_index');

That way, loading ref can be used to have some "in progress" loader.

Something similar to the loading boolean ref here: https://v4.apollo.vuejs.org/api/use-query.html#return

@roberto910907
Copy link
Author

Perhaps we can create a loading ref inside the composables and update its value before and after the awaits call, for example, this one: https://github.com/xlanex6/nuxt-meilisearch/blob/master/src/runtime/composables/useMeiliSearch.ts#L13

  const loading = ref(false)
  const client = useMeiliSearchRef()
  const result = useState(`${index}-search-result`, () => null as SearchResponse | null)

  const search = async (query: string, searchParams?: SearchParams) => {
    loading.value = true;
    
    const resp = await client.index(index).search(query, searchParams)
    
    loading.value = false;    

    result.value = resp as SearchResponse

    return resp
  }

  return {
    search,
    result,
    loading,
  }

We can also return an error ref and add a try-catch around the await call.

@xlanex6
Copy link
Owner

xlanex6 commented Aug 6, 2024

Hi @roberto910907

It looks great!

Can you please push it into a pull request?
As it's an open-source project, you're more than welcome to contribute to it.

@roberto910907
Copy link
Author

@xlanex6 Absolutely! Just wanted to validate my idea and your willingness to accept these changes before spending time on implementing the feature. I will implement the changes and possibly open the PR before the end of the day. Thanks!

@xlanex6
Copy link
Owner

xlanex6 commented Aug 9, 2024

@roberto910907
Let me knows if I can help with this feature

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