Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix: loading in account linking
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroBenicio committed Oct 6, 2023
1 parent 6517658 commit b0df6bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
28 changes: 26 additions & 2 deletions src/components/button/button-text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const props = defineProps({
required: false,
default: "STANDARD",
},
isLoading: {
type: Boolean,
required: false,
default: false
}
});
const click = () => {
if (props.state != ButtonTextState.DISABLED) emit("click");
Expand All @@ -31,15 +36,34 @@ const click = () => {
standard: state === ButtonTextState.STANDARD,
boring: state === ButtonTextState.BORING,
alert: state === ButtonTextState.ALERT,
disable: state === ButtonTextState.DISABLED,
disable: state === ButtonTextState.DISABLED
}"
@click.stop.prevent="click"
>
{{ text }}
<div id="loading" v-if="isLoading"/>{{ text }}
</button>
</template>

<style scoped>

#loading {
display: inline-block;
width: 1.4em;
height: 1.4em;
border: 3px solid rgba(255,255,255,.3);
border-radius: 50%;
margin-right: 0.7em;
border-top-color: #fff;
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
.textButton {
width: 100%;
height: 2.7em;
Expand Down
11 changes: 8 additions & 3 deletions src/components/sheet/sheet-add-gmail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ const canSubmit = computed(
form.value.password?.length > 0,
);

const isLoading = ref<boolean>(false)

const submit = async () => {
isLoading.value = true
error.value = "";
try {
await tiki.capture.login(form.value);
tiki.capture.scan().catch((error) => console.error(error.toString()));
error.value = "";
form.value = { username: "", password: "", type: GMAIL };
tiki.capture.scan().catch((error) => console.error(error.toString()));
emit("back");
} catch (err: any) {
error.value = err.toString();
}
isLoading.value = false
};
</script>

Expand All @@ -54,8 +58,9 @@ const submit = async () => {
/>
<text-button
text="Connect Gmail"
:state="canSubmit ? ButtonTextState.STANDARD : ButtonTextState.DISABLED"
:state="canSubmit && !isLoading ? ButtonTextState.STANDARD : ButtonTextState.DISABLED"
@click="submit"
:isLoading="isLoading"
/>
</div>
</template>
11 changes: 8 additions & 3 deletions src/components/sheet/sheet-add-retailer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ const canSubmit = computed(
form.value.password?.length > 0,
);

const isLoading = ref<boolean>(false)

const submit = async () => {
isLoading.value = true
error.value = "";
try {
await tiki.capture.login(form.value);
tiki.capture.scan().catch((error) => console.error(error.toString()));
error.value = "";
form.value = { username: "", password: "", type: AMAZON };
tiki.capture.scan().catch((error) => console.error(error.toString()));
emit("back");
} catch (err: any) {
error.value = err.toString();
}
isLoading.value = false
};
</script>

Expand All @@ -56,8 +60,9 @@ const submit = async () => {
/>
<text-button
text="Connect Retailer"
:state="canSubmit ? ButtonTextState.STANDARD : ButtonTextState.DISABLED"
:state="canSubmit && !isLoading ? ButtonTextState.STANDARD : ButtonTextState.DISABLED"
@click="submit"
:isLoading="isLoading"
/>
</div>
</template>

0 comments on commit b0df6bb

Please sign in to comment.