Skip to content

Commit

Permalink
✨ feat(appaddurlpreview.vue): add loading state to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinsOnuoha committed Nov 4, 2023
1 parent eeed9ab commit 8ea13f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/components/AppAddUrl/AppAddUrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ADD_SAMPLE } from '@/graphql/mutations/samples'
import type { Statement } from '@/entities/Statement'
import { GET_STATEMENTS } from '@/graphql/queries/statements'
import { useValidateOgUrl } from '@/composables/useValidateOgUrl'
import AppAddUrlError from '@/components/AppAddUrl/AppAddUrlError.vue'
import AppAddUrlError from '@/components/AppAddUrl/AppAddUrlSuccessError.vue'
import AppAddUrlPreview from '@/components/AppAddUrl/AppAddUrlPreview.vue'
const props = defineProps({
Expand All @@ -24,7 +24,11 @@ watch(data, (n) => {
}
})
const { loading: loadingMutation, mutate: addSample } = useMutation(ADD_SAMPLE, () => ({
const {
loading: loadingMutation,
mutate: addSample,
error: mutationError
} = useMutation(ADD_SAMPLE, () => ({
variables: {
objects: {
statement_id: props.statement?.id,
Expand Down Expand Up @@ -54,6 +58,7 @@ const { loading: loadingMutation, mutate: addSample } = useMutation(ADD_SAMPLE,
required
name="add-url"
v-model="inputValue"
:disabled="loadingValidation || loadingMutation"
placeholder="e.g https://dribbble.com/shots..."
type="text"
/>
Expand All @@ -62,11 +67,16 @@ const { loading: loadingMutation, mutate: addSample } = useMutation(ADD_SAMPLE,
:disabled="!canCreate || loadingValidation || loadingMutation"
@click="validate(inputValue)"
>
Add Inspiration ✨
{{ loadingValidation ? 'Validating URL...' : 'Add Inspiration ✨' }}
</button>
</div>
<AppAddUrlError :msg="data?.error ? 'Provided URL is invalid ❌' : ''" />
<AppAddUrlPreview v-if="!data?.error && data?.data" :og-item="data.data" />
<AppAddUrlPreview
v-if="!data?.error && data?.data"
:og-item="data.data"
:loading="loadingMutation"
:has-error="!!mutationError"
/>
</template>

<style lang="scss">
Expand Down
7 changes: 6 additions & 1 deletion src/components/AppAddUrl/AppAddUrlPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const ogUrl = computed(() => props.ogItem?.ogUrl ?? '')
const props = defineProps({
ogItem: {
type: Object as PropType<OgItem>
}
},
loading: Boolean,
hasError: Boolean
})
</script>

Expand All @@ -25,6 +27,9 @@ const props = defineProps({
:aria-description="ogDescription"
class="AppAddUrlPreview font--fira"
>
<div class="AppAddUrlPreview__overlay">
{{ !loading && !hasError ? 'Inspiration Added 🎉' : 'Adding URL...' }}
</div>
<MdiCheckCircleOutline class="absolute right-1 top-1 text-green-400 text-xl" />
<div
class="AppAddUrlPreview__img"
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/components/AppAddUrl/_AppAddUrlPreview.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.AppAddUrlPreview {
@apply flex h-auto w-full bg-white border rounded-lg mb-4 transition-all overflow-hidden relative;

&__overlay {
@apply absolute w-full h-full bg-gradient-to-tr from-purple-900 to-transparent flex justify-center items-center text-white font-bold text-sm;
}
&__img {
@apply min-w-[33%] w-1/3 rounded-l-lg bg-cover;
}
Expand Down

0 comments on commit 8ea13f5

Please sign in to comment.