feat: loading state on urql actions

This commit is contained in:
liyasthomas
2022-02-04 17:41:21 +05:30
parent 5aa6bf0d53
commit 6fb8bcfe25
5 changed files with 66 additions and 13 deletions

View File

@@ -19,7 +19,11 @@
</template>
<template #footer>
<span>
<ButtonPrimary :label="t('action.save')" @click.native="addNewTeam" />
<ButtonPrimary
:label="t('action.save')"
:loading="isLoading"
@click.native="addNewTeam"
/>
<ButtonSecondary
:label="t('action.cancel')"
@click.native="hideModal"
@@ -51,12 +55,15 @@ const emit = defineEmits<{
const name = ref<string | null>(null)
const addNewTeam = () =>
pipe(
TeamNameCodec.decode(name.value), // Perform decode (returns either)
TE.fromEither, // Convert either to a task either
TE.mapLeft(() => "invalid_name" as const), // Failure above is an invalid_name, give it an identifiable value
TE.chainW(createTeam), // Create the team
const isLoading = ref(false)
const addNewTeam = async () => {
isLoading.value = true
await pipe(
TeamNameCodec.decode(name.value),
TE.fromEither,
TE.mapLeft(() => "invalid_name" as const),
TE.chainW(createTeam),
TE.match(
(err) => {
// err is of type "invalid_name" | GQLError<Err>
@@ -72,6 +79,8 @@ const addNewTeam = () =>
}
)
)()
isLoading.value = false
}
const hideModal = () => {
name.value = null