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

Fixed: infinite scroll issue when used with searchbar(dxp-289) #500

Merged
merged 2 commits into from
Apr 23, 2024
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
25 changes: 22 additions & 3 deletions src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ion-toolbar>
</ion-header>

<ion-content id="view-size-selector">
<ion-content ref="contentRef" :scroll-events="true" @ionScroll="enableScrolling()" id="view-size-selector">
<ion-searchbar class="searchbar" :value="completedOrders.query.queryString" :placeholder="translate('Search orders')" @keyup.enter="updateQueryString($event.target.value)" />

<div v-if="completedOrders.total">
Expand Down Expand Up @@ -156,7 +156,7 @@
</div>
</div>
</ion-card>
<ion-infinite-scroll @ionInfinite="loadMoreCompletedOrders($event)" threshold="100px" :disabled="!isCompletedOrderScrollable()" :key="completedOrders.query.queryString">
<ion-infinite-scroll @ionInfinite="loadMoreCompletedOrders($event)" threshold="100px" v-show="isCompletedOrderScrollable()" ref="infiniteScrollRef">
<ion-infinite-scroll-content loading-spinner="crescent" :loading-text="translate('Loading')"/>
</ion-infinite-scroll>
</div>
Expand Down Expand Up @@ -254,7 +254,8 @@ export default defineComponent({
return {
shipmentMethods: [] as Array<any>,
carrierPartyIds: [] as Array<any>,
searchedQuery: ''
searchedQuery: '',
isScrollingEnabled: false
}
},
computed: {
Expand All @@ -277,6 +278,9 @@ export default defineComponent({
this.store.dispatch('order/clearCompletedOrders')
emitter.off('updateOrderQuery', this.updateOrderQuery)
},
async ionViewWillEnter() {
this.isScrollingEnabled = false;
},
methods: {
getErrorMessage() {
return this.searchedQuery === '' ? translate("doesn't have any completed orders right now.", { facilityName: this.currentFacility.facilityName }) : translate( "No results found for . Try searching In Progress or Open tab instead. If you still can't find what you're looking for, try switching stores.", { searchedQuery: this.searchedQuery, lineBreak: '<br />' })
Expand All @@ -294,7 +298,22 @@ export default defineComponent({
getCompletedOrders() {
return JSON.parse(JSON.stringify(this.completedOrders.list)).slice(0, (this.completedOrders.query.viewIndex + 1) * (process.env.VUE_APP_VIEW_SIZE as any));
},
enableScrolling() {
const parentElement = (this as any).$refs.contentRef.$el
const scrollEl = parentElement.shadowRoot.querySelector("main[part='scroll']")
let scrollHeight = scrollEl.scrollHeight, infiniteHeight = (this as any).$refs.infiniteScrollRef.$el.offsetHeight, scrollTop = scrollEl.scrollTop, threshold = 100, height = scrollEl.offsetHeight
const distanceFromInfinite = scrollHeight - infiniteHeight - scrollTop - threshold - height
if(distanceFromInfinite < 0) {
this.isScrollingEnabled = false;
} else {
this.isScrollingEnabled = true;
}
},
async loadMoreCompletedOrders(event: any) {
// Added this check here as if added on infinite-scroll component the Loading content does not gets displayed
if (!(this.isScrollingEnabled && this.isCompletedOrderScrollable())) {
await event.target.complete();
}
const completedOrdersQuery = JSON.parse(JSON.stringify(this.completedOrders.query))
completedOrdersQuery.viewIndex++;
await this.store.dispatch('order/updateCompletedOrderIndex', { ...completedOrdersQuery })
Expand Down
25 changes: 22 additions & 3 deletions src/views/InProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ion-toolbar>
</ion-header>

<ion-content id="view-size-selector">
<ion-content ref="contentRef" :scroll-events="true" @ionScroll="enableScrolling()" id="view-size-selector">
<ion-searchbar class="searchbar" :placeholder="translate('Search orders')" v-model="inProgressOrders.query.queryString" @keyup.enter="updateQueryString($event.target.value)"/>
<div v-if="inProgressOrders.total">
<ion-radio-group v-model="selectedPicklistId" @ionChange="updateSelectedPicklist($event.detail.value)">
Expand Down Expand Up @@ -218,7 +218,7 @@
</div>
</div>
</ion-card>
<ion-infinite-scroll @ionInfinite="loadMoreInProgressOrders($event)" threshold="100px" :disabled="!isInProgressOrderScrollable()" :key="inProgressOrders.query.queryString">
<ion-infinite-scroll @ionInfinite="loadMoreInProgressOrders($event)" threshold="100px" v-show="isInProgressOrderScrollable()" ref="infiniteScrollRef">
<ion-infinite-scroll-content loading-spinner="crescent" :loading-text="translate('Loading')"/>
</ion-infinite-scroll>
</div>
Expand Down Expand Up @@ -389,9 +389,13 @@ export default defineComponent({
orderBoxes: [] as any,
searchedQuery: '',
addingBoxForOrderIds: [] as any,
selectedPicklistId: ''
selectedPicklistId: '',
isScrollingEnabled: false
}
},
async ionViewWillEnter() {
this.isScrollingEnabled = false;
},
methods: {
async openRejectReasonPopover(ev: Event, kitProducts: any, order: any) {
const reportIssuePopover = await popoverController.create({
Expand Down Expand Up @@ -956,7 +960,22 @@ export default defineComponent({
getPicklist(id: string) {
return this.picklists.find((picklist: any) => picklist.id === id)
},
enableScrolling() {
const parentElement = (this as any).$refs.contentRef.$el
const scrollEl = parentElement.shadowRoot.querySelector("main[part='scroll']")
let scrollHeight = scrollEl.scrollHeight, infiniteHeight = (this as any).$refs.infiniteScrollRef.$el.offsetHeight, scrollTop = scrollEl.scrollTop, threshold = 100, height = scrollEl.offsetHeight
const distanceFromInfinite = scrollHeight - infiniteHeight - scrollTop - threshold - height
if(distanceFromInfinite < 0) {
this.isScrollingEnabled = false;
} else {
this.isScrollingEnabled = true;
}
},
async loadMoreInProgressOrders(event: any) {
// Added this check here as if added on infinite-scroll component the Loading content does not gets displayed
if (!(this.isScrollingEnabled && this.isInProgressOrderScrollable())) {
await event.target.complete();
}
const inProgressOrdersQuery = JSON.parse(JSON.stringify(this.inProgressOrders.query))
inProgressOrdersQuery.viewIndex++;
await this.store.dispatch('order/updateInProgressIndex', { ...inProgressOrdersQuery })
Expand Down
25 changes: 22 additions & 3 deletions src/views/OpenOrders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ion-toolbar>
</ion-header>

<ion-content id="view-size-selector">
<ion-content ref="contentRef" :scroll-events="true" @ionScroll="enableScrolling()" id="view-size-selector">
<ion-searchbar class="searchbar" :value="openOrders.query.queryString" :placeholder="translate('Search orders')" @keyup.enter="updateQueryString($event.target.value)"/>
<div v-if="openOrders.total">
<div class="filters">
Expand Down Expand Up @@ -123,7 +123,7 @@
</div> -->
</ion-card>

<ion-infinite-scroll @ionInfinite="loadMoreOpenOrders($event)" threshold="100px" :disabled="!isOpenOrdersScrollable()" :key="openOrders.query.queryString">
<ion-infinite-scroll @ionInfinite="loadMoreOpenOrders($event)" threshold="100px" v-show="isOpenOrdersScrollable()" ref="infiniteScrollRef">
<ion-infinite-scroll-content loading-spinner="crescent" :loading-text="translate('Loading')"/>
</ion-infinite-scroll>
</div>
Expand Down Expand Up @@ -226,17 +226,36 @@ export default defineComponent({
data () {
return {
shipmentMethods: [] as Array<any>,
searchedQuery: ''
searchedQuery: '',
isScrollingEnabled: false
}
},
async ionViewWillEnter() {
this.isScrollingEnabled = false;
},
methods: {
getErrorMessage() {
return this.searchedQuery === '' ? translate("doesn't have any outstanding orders right now.", { facilityName: this.currentFacility.facilityName }) : translate( "No results found for . Try searching In Progress or Completed tab instead. If you still can't find what you're looking for, try switching stores.", { searchedQuery: this.searchedQuery, lineBreak: '<br />' })
},
getOpenOrders() {
return JSON.parse(JSON.stringify(this.openOrders.list)).slice(0, (this.openOrders.query.viewIndex + 1) * (process.env.VUE_APP_VIEW_SIZE as any));
},
enableScrolling() {
const parentElement = (this as any).$refs.contentRef.$el
const scrollEl = parentElement.shadowRoot.querySelector("main[part='scroll']")
let scrollHeight = scrollEl.scrollHeight, infiniteHeight = (this as any).$refs.infiniteScrollRef.$el.offsetHeight, scrollTop = scrollEl.scrollTop, threshold = 100, height = scrollEl.offsetHeight
const distanceFromInfinite = scrollHeight - infiniteHeight - scrollTop - threshold - height
if(distanceFromInfinite < 0) {
this.isScrollingEnabled = false;
} else {
this.isScrollingEnabled = true;
}
},
async loadMoreOpenOrders(event: any) {
// Added this check here as if added on infinite-scroll component the Loading content does not gets displayed
if (!(this.isScrollingEnabled && this.isOpenOrdersScrollable())) {
await event.target.complete();
}
const openOrdersQuery = JSON.parse(JSON.stringify(this.openOrders.query))
openOrdersQuery.viewIndex++;
await this.store.dispatch('order/updateOpenOrderIndex', { ...openOrdersQuery })
Expand Down
41 changes: 31 additions & 10 deletions src/views/TransferOrders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ion-toolbar>
</ion-header>

<ion-content id="transfer-order-filters">
<ion-content ref="contentRef" :scroll-events="true" @ionScroll="enableScrolling()" id="transfer-order-filters">
<ion-searchbar class="better-name-here" :value="transferOrders.query.queryString" @keyup.enter="updateQueryString($event.target.value)"/>
<div v-if="transferOrders.total">
<div class="results">
Expand All @@ -29,14 +29,16 @@
<ion-badge slot="end">{{ order.orderStatusDesc }}</ion-badge>
</ion-item>
</ion-list>
<!--
When searching for a keyword, and if the user moves to the last item, then the didFire value inside infinite scroll becomes true and thus the infinite scroll does not trigger again on the same page(https://github.com/hotwax/users/issues/84).
In ionic v7.6.0, an issue related to infinite scroll has been fixed that when more items can be added to the DOM, but infinite scroll does not fire as the window is not completely filled with the content(https://github.com/ionic-team/ionic-framework/issues/18071).
The above fix in ionic 7.6.0 is resulting in the issue of infinite scroll not being called again.
To fix this, we have added a key with value as queryString(searched keyword), so that the infinite scroll component can be re-rendered
whenever the searched string is changed resulting in the correct behaviour for infinite scroll
-->
<ion-infinite-scroll @ionInfinite="loadMoreTransferOrders($event)" threshold="100px" :disabled="!isTransferOrdersScrollable()" :key="transferOrders.query.queryString">
<!--
When searching for a keyword, and if the user moves to the last item, then the didFire value inside infinite scroll becomes true and thus the infinite scroll does not trigger again on the same page(https://github.com/hotwax/users/issues/84).
Also if we are at the section that has been loaded by infinite-scroll and then move to the details page then the list infinite scroll does not work after coming back to the page
In ionic v7.6.0, an issue related to infinite scroll has been fixed that when more items can be added to the DOM, but infinite scroll does not fire as the window is not completely filled with the content(https://github.com/ionic-team/ionic-framework/issues/18071).
The above fix in ionic 7.6.0 is resulting in the issue of infinite scroll not being called again.
To fix this we have maintained another variable `isScrollingEnabled` to check whether the scrolling can be performed or not.
If we do not define an extra variable and just use v-show to check for `isScrollable` then when coming back to the page infinite-scroll is called programatically.
We have added an ionScroll event on ionContent to check whether the infiniteScroll can be enabled or not by toggling the value of isScrollingEnabled whenever the height < 0.
-->
<ion-infinite-scroll @ionInfinite="loadMoreTransferOrders($event)" threshold="100px" v-show="isTransferOrdersScrollable()" ref="infiniteScrollRef">
<ion-infinite-scroll-content loading-spinner="crescent" :loading-text="translate('Loading')"/>
</ion-infinite-scroll>
</div>
Expand Down Expand Up @@ -105,14 +107,33 @@ export default defineComponent({
data () {
return {
shipmentMethods: [] as Array<any>,
searchedQuery: ''
searchedQuery: '',
isScrollingEnabled: false
}
},
async ionViewWillEnter() {
this.isScrollingEnabled = false;
},
methods: {
getErrorMessage() {
return this.searchedQuery === '' ? translate("doesn't have any transfer orders right now.", { facilityName: this.currentFacility.facilityName }) : translate( "No results found for .", { searchedQuery: this.searchedQuery })
},
enableScrolling() {
const parentElement = (this as any).$refs.contentRef.$el
const scrollEl = parentElement.shadowRoot.querySelector("main[part='scroll']")
let scrollHeight = scrollEl.scrollHeight, infiniteHeight = (this as any).$refs.infiniteScrollRef.$el.offsetHeight, scrollTop = scrollEl.scrollTop, threshold = 100, height = scrollEl.offsetHeight
const distanceFromInfinite = scrollHeight - infiniteHeight - scrollTop - threshold - height
if(distanceFromInfinite < 0) {
this.isScrollingEnabled = false;
} else {
this.isScrollingEnabled = true;
}
},
async loadMoreTransferOrders(event: any) {
// Added this check here as if added on infinite-scroll component the Loading content does not gets displayed
if (!(this.isScrollingEnabled && this.isTransferOrdersScrollable())) {
await event.target.complete();
}
const transferOrdersQuery = JSON.parse(JSON.stringify(this.transferOrders.query))
transferOrdersQuery.viewIndex = this.transferOrders.list?.length / (process.env.VUE_APP_VIEW_SIZE as any);
await this.store.dispatch('transferorder/updateTransferOrderQuery', { ...transferOrdersQuery })
Expand Down
Loading