Skip to content

Commit

Permalink
Merge pull request #206 from amansinghbais/198-product-remain-highlig…
Browse files Browse the repository at this point in the history
…hted

Improved: code to remove highlight from product after some time and on click on other products, moved lastScannedId to state (#198)
  • Loading branch information
ravilodhi authored Mar 14, 2024
2 parents 5763fcf + 681e323 commit ba1e984
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/components/Picklist-detail-item.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<ion-item :id="picklistItem.id" :class="picklistItem.id === lastScannedId ? 'scanned-item' : '' " :key="picklistItem.id" v-for="picklistItem in picklistItems" @click="picklistItem.isChecked = !picklistItem.isChecked" lines="none" >
<ion-item :id="picklistItem.id" :class="picklistItem.id === lastScannedId ? 'scanned-item' : '' " :key="picklistItem.id" v-for="picklistItem in picklistItems" @click="picklistItem.isChecked = !picklistItem.isChecked; clearLastScannedId()" lines="none" >
<ion-thumbnail slot="start">
<DxpShopifyImg :src="getProduct(picklistItem.productId).mainImageUrl" size="small" />
</ion-thumbnail>
Expand Down Expand Up @@ -30,12 +30,18 @@ export default defineComponent({
IonThumbnail,
DxpShopifyImg
},
props: ['picklistItems', 'lastScannedId'],
props: ['picklistItems'],
computed: {
...mapGetters({
getProduct: 'product/getProduct'
getProduct: 'product/getProduct',
lastScannedId: 'picklist/getLastScannedId',
}),
},
methods: {
clearLastScannedId() {
this.store.dispatch("picklist/updateLastScannedId", "")
}
},
setup() {
const store = useStore();
const productIdentificationStore = useProductIdentificationStore();
Expand Down
1 change: 1 addition & 0 deletions src/components/Picklist-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineComponent({
props: ['picklists'],
methods: {
async viewPicklist (picklist: any) {
this.store.dispatch("picklist/updateLastScannedId", "")
// if current is not set promise.reject returns which will not allow further code execution
// and hence, router.push will not execute stopping the code from breaking
await this.store.dispatch('picklist/setCurrentPicklist', { id: picklist.picklistId })
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/picklist/PicklistState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default interface PicklistState {
total: any
};
filters: any;
lastScannedId: string;
}
4 changes: 4 additions & 0 deletions src/store/modules/picklist/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ const actions: ActionTree<PicklistState, RootState> = {
clearPicklist ({ commit }) {
commit(types.PICKLISTS_UPDATED, { list: [], total: 0 })
commit(types.PICKLISTS_COMPLETED_UPDATED, { list: [], total: 0 })
},

updateLastScannedId ({ commit }, id) {
commit(types.PICKLIST_LAST_SCANNED_ID_UPDATED, id)
}
}
export default actions;
3 changes: 3 additions & 0 deletions src/store/modules/picklist/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const getters: GetterTree <PicklistState, RootState> = {
},
showMyPicklists(state) {
return state.filters.showMyPicklists;
},
getLastScannedId(state) {
return state.lastScannedId;
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/picklist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const picklistModule: Module<PicklistState, RootState> = {
// enabling picklist filters by default
hideCompletedPicklists: true,
showMyPicklists: true
}
},
lastScannedId: ''
},
getters,
mutations,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/picklist/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const PICKLISTS_UPDATED = SN_PICKLIST + '/UPDATED'
export const PICKLISTS_COMPLETED_UPDATED = SN_PICKLIST + '/COMPLETED'
export const PICKLIST_CURRENT_UPDATED = SN_PICKLIST + '/CURRENT_UPDATED'
export const PICKLIST_FILTERS_UPDATED = SN_PICKLIST + '/FILTERS_UPDATED'
export const PICKLIST_LAST_SCANNED_ID_UPDATED = SN_PICKLIST + '/LAST_SCANNED_ID_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/picklist/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const mutations: MutationTree <PicklistState> = {
},
[types.PICKLIST_FILTERS_UPDATED] (state, payload) {
state.filters = { ...state.filters, ...payload };
},
[types.PICKLIST_LAST_SCANNED_ID_UPDATED] (state, payload) {
state.lastScannedId = payload
}
}
export default mutations;
12 changes: 8 additions & 4 deletions src/views/Picklist-Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ion-item-divider>
<ion-label> {{ picklist.sortBy }}</ion-label>
</ion-item-divider>
<PicklistDetailItem :lastScannedId="lastScannedId" :picklistItems="picklist.record"/>
<PicklistDetailItem :picklistItems="picklist.record"/>
</ion-item-group>
</ion-list>
</ion-content>
Expand Down Expand Up @@ -128,7 +128,6 @@ export default defineComponent({
data() {
return {
picklistGroup: [],
lastScannedId: '',
sortOptions: JSON.parse(process.env.VUE_APP_PICKLISTS_SORT_OPTIONS)
}
},
Expand Down Expand Up @@ -185,12 +184,17 @@ export default defineComponent({
const item = this.picklist.pickingItemList.find((product) => product.productId === productId && !product.isChecked)
if (item) {
item.isChecked = true;
this.lastScannedId = item.id;
this.store.dispatch("picklist/updateLastScannedId", item.id)
// Highlight specific element
const scannedElement = document.getElementById(item.id);
scannedElement && (scannedElement.scrollIntoView());
// Scanned product should get un-highlighted after 3s for better experience hence adding setTimeOut
setTimeout(() => {
this.store.dispatch("picklist/updateLastScannedId", "")
}, 3000)
} else {
this.lastScannedId = "";
this.store.dispatch("picklist/updateLastScannedId", "")
showToast(translate("Product not found in remaining items"))
}
},
Expand Down
1 change: 1 addition & 0 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default defineComponent({
logout () {
this.store.dispatch('user/logout', { isUserUnauthorised: false }).then((redirectionUrl) => {
this.store.dispatch('picklist/clearPicklist')
this.store.dispatch("picklist/updateLastScannedId", "")
// if not having redirection url then redirect the user to launchpad
if(!redirectionUrl) {
Expand Down

0 comments on commit ba1e984

Please sign in to comment.