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

feat: prevent loading state while waiting for the post #5012

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 8 additions & 35 deletions src/pages/Portfolio/ImpactDashboard/EducationModule.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<async-portfolio-section @visible="whenVisible" data-testid="education-module">
<async-portfolio-section data-testid="education-module">
<kv-grid class="tw-grid-cols-12 tw-items-center">
<div
class="tw-col-span-12 lg:tw-col-span-5 xl:tw-col-span-6 md:tw-items-start
Expand All @@ -17,14 +17,13 @@
</p>
</div>
<div class="tw-col-span-12 lg:tw-col-span-7 xl:tw-col-span-6">
<education-post :post="post" :loading="loading" />
<education-post :post="post" />
</div>
</kv-grid>
</async-portfolio-section>
</template>

<script>
import { gql } from '@apollo/client';
import AsyncPortfolioSection from './AsyncPortfolioSection';
import KvGrid from '~/@kiva/kv-components/vue/KvGrid';
import EducationPost from './EducationPost';
Expand All @@ -33,47 +32,21 @@ const imageRequire = require.context('@/assets/images/', true);

export default {
name: 'EducationModule',
inject: ['apollo'],
props: {
post: {
type: Object,
default: null,
},
},
components: {
AsyncPortfolioSection,
EducationPost,
KvGrid,
},
data() {
return {
loading: true,
loadingPromise: null,
post: null,
imageRequire,
};
},
methods: {
fetchAsyncData() {
if (this.loading && !this.loadingPromise) {
this.loadingPromise = this.apollo.query({
query: gql`query ContentfulBlogPosts (
$customFields: String,
$limit: Int
) {
contentful {
blogPosts: entries(contentType:"blogPost", customFields:$customFields, limit:$limit)
}
}`,
variables: {
customFields: 'metadata.tags.sys.id[in]=impact-page|order=-fields.originalPublishDate'
},
}).then(({ data }) => {
this.loading = false;
this.post = data?.contentful?.blogPosts?.items?.[0]?.fields ?? null;
this.$emit('hide-module', this.post === null);
}).finally(() => {
this.loadingPromise = null;
});
}
},
whenVisible() {
this.fetchAsyncData();
}
},
};
</script>
17 changes: 1 addition & 16 deletions src/pages/Portfolio/ImpactDashboard/EducationPost.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div class="card-container">
<a
v-if="!loading"
:href="url"
class="card-container-link-image"
@click="trackEvent('blog-image')"
Expand All @@ -15,46 +14,36 @@
fallback-format="jpg"
/>
</a>
<kv-loading-placeholder v-else class="placeholder" :style="{ height: '16rem' }" />
<a
v-if="!loading"
:href="url"
@click="trackEvent('blog-headline')"
class="tw-text-h3 text-overflow tw-decoration-white tw-cursor-pointer"
:class="{ 'tw-line-clamp-2' : truncateHeadline }"
>
{{ headline }}
</a>
<kv-loading-placeholder v-else class="placeholder" :style="{ height: '2rem' }" />
<p
v-if="!loading" class="text-overflow tw-mt-0.5"
class="text-overflow tw-mt-0.5"
:class="{ 'tw-line-clamp-3 md:tw-line-clamp-4' : truncateSummary }"
>
{{ summary }}
</p>
<kv-loading-placeholder v-else class="placeholder" :style="{ height: '2rem' }" />
</div>
</template>

<script>
import KvContentfulImg from '~/@kiva/kv-components/vue/KvContentfulImg';
import KvLoadingPlaceholder from '~/@kiva/kv-components/vue/KvLoadingPlaceholder';

export default {
name: 'EducationPost',
components: {
KvContentfulImg,
KvLoadingPlaceholder
},
props: {
post: {
type: Object,
default: () => {}
},
loading: {
type: Boolean,
default: false,
}
},
data() {
return {
Expand Down Expand Up @@ -146,8 +135,4 @@ export default {
.text-overflow {
@apply tw-text-white tw-overflow-hidden tw-text-ellipsis;
}

.placeholder {
@apply tw-w-full tw-mb-2;
}
</style>
29 changes: 24 additions & 5 deletions src/pages/Portfolio/ImpactDashboard/ImpactDashboardPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<lending-insights />
<recent-loans-list />
<your-donations />
<education-module v-if="showEdModule" @hide-module="hideModule" />
<education-module v-if="post" :post="post" />
<kiva-credit-stats />
<account-updates />
<your-teams />
Expand All @@ -26,6 +26,7 @@
import WwwPage from '@/components/WwwFrame/WwwPage';
import TheMyKivaSecondaryMenu from '@/components/WwwFrame/Menus/TheMyKivaSecondaryMenu';
import ThePortfolioTertiaryMenu from '@/components/WwwFrame/Menus/ThePortfolioTertiaryMenu';
import { gql } from '@apollo/client';
import KvGrid from '~/@kiva/kv-components/vue/KvGrid';
import KvPageContainer from '~/@kiva/kv-components/vue/KvPageContainer';
import AccountOverview from './AccountOverview';
Expand All @@ -40,7 +41,7 @@ import YourDonations from './YourDonations';

export default {
name: 'ImpactDashboardPage',
inject: ['cookieStore'],
inject: ['apollo', 'cookieStore'],
components: {
AccountOverview,
AccountUpdates,
Expand All @@ -59,13 +60,31 @@ export default {
},
data() {
return {
showEdModule: true
post: null
};
},
methods: {
hideModule(payload) {
this.showEdModule = !payload;
loadEducationPost() {
// Donation Education Module Experiment MARS-497
this.apollo.query({
query: gql`query ContentfulBlogPosts (
$customFields: String,
$limit: Int
) {
contentful {
blogPosts: entries(contentType:"blogPost", customFields:$customFields, limit:$limit)
}
}`,
variables: {
customFields: 'metadata.tags.sys.id[in]=impact-page|order=-fields.originalPublishDate'
},
}).then(({ data }) => {
this.post = data?.contentful?.blogPosts?.items?.[0]?.fields ?? null;
});
}
},
created() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use mounted instead so that this isn't started on the server-side. The server completes the request as soon as created finishes, so anything async started during that is ignored.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a quick pr for this. Thanks!

this.loadEducationPost();
}
};
</script>
Loading