Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</template>

<script setup lang="ts">
import { nextTick, ref, toRef } from "vue";
import { nextTick, ref, toRef, watch } from "vue";
import { SelectAddressFilter } from "@/shared/checkout";
import { useSelectAddressMap } from "@/shared/checkout/composables";
import { useModal } from "@/shared/modal";
Expand Down Expand Up @@ -108,6 +108,24 @@ const { selectedAddressId, filterIsApplied, pickupLocationsLoading, selectAddres
onFilterChange: () => emit("filterChange"),
});

// Automatically scroll to current address in list and position map
watch(
() => props.addresses,
(addresses) => {
if (props.currentAddress?.id && addresses.length) {
const currentLocation = addresses.find((addr) => addr.id === props.currentAddress?.id);

if (currentLocation) {
selectAddress(currentLocation, {
scrollToSelectedOnMap: true,
scrollToSelectedOnList: true,
});
}
}
},
{ immediate: true, flush: "post" },
);

function onSelect(address: PickupLocationType) {
selectAddress(address, { scrollToSelectedOnMap: true });
selectedLocation.value = address;
Expand Down
25 changes: 20 additions & 5 deletions client-app/shared/checkout/composables/useSelectAddressMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ function getLatLng(location: string | undefined) {
}
}

function scrollToAddressInList(addressId: string) {
const listElement = document.querySelector(`[data-address-id="${CSS.escape(addressId)}"]`);

if (listElement) {
listElement.scrollIntoView({ behavior: "smooth", block: "center" });
}
}

export function useSelectAddressMap(options: IUseSelectAddressMapOptions) {
const { addresses, currentAddress, onFilterChange } = options;

Expand Down Expand Up @@ -94,11 +102,7 @@ export function useSelectAddressMap(options: IUseSelectAddressMapOptions) {
}

if (selectOptions.scrollToSelectedOnList && address.id) {
const listElement = document.querySelector(`[data-address-id="${CSS.escape(address.id)}"]`);

if (listElement) {
listElement.scrollIntoView({ behavior: "smooth", block: "center" });
}
scrollToAddressInList(address.id);
}
}

Expand Down Expand Up @@ -148,6 +152,17 @@ export function useSelectAddressMap(options: IUseSelectAddressMapOptions) {
}
}

// Automatically open info card and scroll to selected item in list
if (address) {
onceIdle(() => {
showLocationInfoCard(address);

if (address.id) {
scrollToAddressInList(address.id);
}
});
}

unwatch();
}
});
Expand Down