-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathselect-address-map-mobile.vue
More file actions
194 lines (165 loc) · 5.44 KB
/
Copy pathselect-address-map-mobile.vue
File metadata and controls
194 lines (165 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<template>
<div class="select-address-map-mobile" data-test-id="select-address-map-mobile">
<template v-if="addresses.length || filterIsApplied">
<div class="select-address-map-mobile__container">
<SelectAddressFilter class="select-address-map-mobile__filter" @apply-filter="applyFilter" />
</div>
<div class="select-address-map-mobile__content">
<VcLoaderOverlay v-if="pickupLocationsLoading" />
<SelectAddressMapList
v-show="activeView === 'list'"
:addresses="addresses"
:selected-address-id="selectedAddressId"
:selectable="selectable"
class="select-address-map-mobile__list"
@select="onSelect"
@reset-filter="resetFilter"
/>
<SelectAddressMapView
v-show="activeView === 'map'"
:api-key="apiKey"
:addresses="addresses"
:selected-address-id="selectedAddressId"
class="select-address-map-mobile__map"
data-test-id="pickup-locations-map"
@select="onSelect"
/>
</div>
<div class="select-address-map-mobile__actions">
<VcButton
v-if="activeView === 'map'"
prepend-icon="list"
size="sm"
data-test-id="view-list-button"
@click="activeView = 'list'"
>
{{ $t("shared.checkout.select_bopis_modal.view_list") }}
</VcButton>
<VcButton v-else prepend-icon="map" size="sm" data-test-id="view-map-button" @click="activeView = 'map'">
{{ $t("shared.checkout.select_bopis_modal.view_map") }}
</VcButton>
</div>
<!-- Info card with slide-up animation -->
<div v-if="selectedLocation" class="select-address-map-mobile__info-card">
<Transition name="slide-up" @after-leave="onTransitionAfterLeave">
<PickupLocationCard
v-if="isInfoCardVisible"
:location="selectedLocation"
:selectable="selectable"
data-test-id="pickup-location-card"
@close="onInfoCardClose"
@select="onCardSelect"
/>
</Transition>
</div>
</template>
<div v-else class="select-address-map-mobile__not-found">
{{ $t("pages.account.order_details.bopis.cart_pickup_points_not_found") }}
</div>
</div>
</template>
<script setup lang="ts">
import { nextTick, ref, toRef, watch } from "vue";
import { SelectAddressFilter } from "@/shared/checkout";
import { useSelectAddressMap } from "@/shared/checkout/composables";
import { useModal } from "@/shared/modal";
import PickupLocationCard from "../pickup-location-card.vue";
import SelectAddressMapList from "./select-address-map-list.vue";
import SelectAddressMapView from "./select-address-map-view.vue";
import type { PickupLocationType } from "@/shared/checkout/composables";
type ViewModeType = "list" | "map";
interface IProps {
addresses: PickupLocationType[];
apiKey: string;
currentAddress?: { id: string };
selectable?: boolean;
}
interface IEmits {
(event: "result", value: string): void;
(event: "filterChange"): void;
}
const emit = defineEmits<IEmits>();
const props = withDefaults(defineProps<IProps>(), {
selectable: true,
});
const { closeModal } = useModal();
const activeView = ref<ViewModeType>("list");
const selectedLocation = ref<PickupLocationType>();
const isInfoCardVisible = ref(false);
const closingLocationId = ref<string>();
const { selectedAddressId, filterIsApplied, pickupLocationsLoading, selectAddress, applyFilter, resetFilter } =
useSelectAddressMap({
addresses: toRef(props, "addresses"),
currentAddress: toRef(props, "currentAddress"),
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;
void nextTick(() => {
isInfoCardVisible.value = true;
});
}
function onCardSelect(locationId: string) {
emit("result", locationId);
closeModal();
}
function onInfoCardClose() {
closingLocationId.value = selectedLocation.value?.id;
isInfoCardVisible.value = false;
}
function onTransitionAfterLeave() {
// Only clear if no new location was selected during animation
if (selectedLocation.value?.id === closingLocationId.value) {
selectedLocation.value = undefined;
}
closingLocationId.value = undefined;
}
</script>
<style lang="scss">
.select-address-map-mobile {
@apply flex flex-col h-full max-h-full;
&__container {
@apply flex flex-col px-6 min-h-0;
}
&__content {
@apply relative flex-1 px-5 min-h-0;
}
&__list {
@apply h-full px-1 pb-3;
}
&__map {
@apply h-full;
}
&__actions {
@apply flex px-6 py-4 border-t;
}
&__info-card {
@apply absolute inset-0 z-10 p-4 bg-additional-950/40;
.slide-up-enter-active,
.slide-up-leave-active {
@apply transition-transform duration-300;
}
.slide-up-enter-from,
.slide-up-leave-to {
@apply translate-y-full;
}
}
}
</style>