Skip to content

Commit

Permalink
fix: index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek committed Apr 29, 2024
1 parent 0958012 commit d9063c4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pages/indexes/create.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<Layout :title="t('title')" :subtitle="t('subtitle')">
<form class="space-y-4" @submit.prevent="submit()">
<form
class="space-y-4"
@reset.prevent="reset(factory())"
@submit.prevent="submit()">
<Alert v-if="error" dismissable theme="danger" @close="error = null">
{{ error }}
</Alert>
Expand Down Expand Up @@ -42,8 +45,10 @@ import { useFormSubmit, useMeiliClient } from '~/composables'
import { resettableRef } from '~/utils'
import Button from '~/components/layout/forms/Button.vue'
import Buttons from '~/components/layout/forms/Buttons.vue'
import Label from '~/components/layout/forms/Label.vue'
import { TOAST_PLEASEWAIT, TOAST_SUCCESS, useToasts } from '~/stores/toasts'
import Alert from '~/components/layout/Alert.vue'
import { promiseTimeout } from '@vueuse/core'
const { t } = useI18n()
const client = useMeiliClient()
Expand All @@ -58,19 +63,21 @@ const { value: index, reset, modified } = resettableRef(factory())
const { loading, error, handle } = useFormSubmit()
const self = reactive({ index, loading })
const submit = async () => {
const toast = createToast({
...TOAST_PLEASEWAIT(t),
title: t('toasts.success.title'),
text: t('toasts.success.pendingText'),
immediate: false,
})
let indexUid = self.index.uid
await handle(async () => {
toast.spawn()
const task = await client.createIndex(indexUid, {
primaryKey: self.index.primaryKey,
})
const toast = createToast({
...TOAST_PLEASEWAIT,
title: t('toasts.success.title'),
text: t('toasts.success.pendingText'),
})
await client.waitForTask(task.taskUid)
toast.update({
...TOAST_SUCCESS,
...TOAST_SUCCESS(t),
})
reset(factory())
navigateTo(`/indexes/${indexUid}/documents`)
Expand Down

0 comments on commit d9063c4

Please sign in to comment.