Unify CatalogPage: fixed map, hover support, delete ListMapLayout
All checks were successful
Build Docker Image / build (push) Successful in 4m31s

This commit is contained in:
Ruslan Bakiev
2026-01-08 11:15:54 +07:00
parent 4057bce4be
commit 8d1b7c6dc7
7 changed files with 148 additions and 348 deletions

View File

@@ -1,151 +0,0 @@
<template>
<div class="flex flex-col flex-1 min-h-0">
<!-- Desktop: side-by-side layout -->
<div class="hidden lg:flex flex-1 gap-4 min-h-0">
<!-- Left side: List (scrollable) -->
<div class="w-2/5 overflow-y-auto pr-2">
<slot name="list" />
</div>
<!-- Right side: Map (fixed position, full height) -->
<div class="w-3/5 relative">
<div class="fixed top-28 right-6 w-[calc(60%-3rem)] h-[calc(100vh-8rem)] rounded-lg overflow-hidden">
<ClientOnly>
<CatalogMap
ref="mapRef"
:map-id="mapId"
:items="itemsWithCoords"
:point-color="pointColor"
@select-item="onMapSelectItem"
/>
</ClientOnly>
</div>
</div>
</div>
<!-- Mobile: toggle between list and map -->
<div class="lg:hidden flex-1 flex flex-col min-h-0">
<!-- Content area -->
<div class="flex-1 overflow-y-auto" v-show="mobileView === 'list'">
<slot name="list" />
</div>
<div class="flex-1" v-show="mobileView === 'map'">
<ClientOnly>
<CatalogMap
ref="mobileMapRef"
:map-id="`${mapId}-mobile`"
:items="itemsWithCoords"
:point-color="pointColor"
@select-item="onMapSelectItem"
/>
</ClientOnly>
</div>
<!-- Mobile toggle buttons -->
<div class="fixed bottom-4 left-1/2 -translate-x-1/2 z-30">
<div class="btn-group shadow-lg">
<button
class="btn btn-sm"
:class="{ 'btn-active': mobileView === 'list' }"
@click="mobileView = 'list'"
>
{{ $t('common.list') }}
</button>
<button
class="btn btn-sm"
:class="{ 'btn-active': mobileView === 'map' }"
@click="mobileView = 'map'"
>
{{ $t('common.map') }}
</button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
interface MapItem {
uuid: string
latitude?: number | null
longitude?: number | null
name?: string
country?: string
[key: string]: any
}
const props = withDefaults(defineProps<{
items: MapItem[]
selectedItemId?: string
hoveredItemId?: string
mapId: string
pointColor?: string
}>(), {
pointColor: '#3b82f6'
})
const emit = defineEmits<{
'select-item': [uuid: string]
'update:selectedItemId': [uuid: string]
}>()
// Filter items with valid coordinates
const itemsWithCoords = computed(() =>
props.items.filter(item =>
item.latitude != null &&
item.longitude != null &&
!isNaN(Number(item.latitude)) &&
!isNaN(Number(item.longitude))
).map(item => ({
uuid: item.uuid,
name: item.name || '',
latitude: Number(item.latitude),
longitude: Number(item.longitude),
country: item.country
}))
)
// Mobile view toggle
const mobileView = ref<'list' | 'map'>('list')
// Map refs
const mapRef = ref<{ flyTo: (lat: number, lng: number, zoom?: number) => void } | null>(null)
const mobileMapRef = ref<{ flyTo: (lat: number, lng: number, zoom?: number) => void } | null>(null)
// Handle map item selection
const onMapSelectItem = (uuid: string) => {
emit('select-item', uuid)
emit('update:selectedItemId', uuid)
}
// Fly to a specific item
const flyTo = (lat: number, lng: number, zoom = 8) => {
mapRef.value?.flyTo(lat, lng, zoom)
mobileMapRef.value?.flyTo(lat, lng, zoom)
}
// Fly to item by uuid
const flyToItem = (uuid: string) => {
const item = itemsWithCoords.value.find(i => i.uuid === uuid)
if (item) {
flyTo(item.latitude, item.longitude, 8)
}
}
// Watch selectedItemId and fly to it
watch(() => props.selectedItemId, (uuid) => {
if (uuid) {
flyToItem(uuid)
}
})
// Watch hoveredItemId and fly to it on hover
watch(() => props.hoveredItemId, (uuid) => {
if (uuid) {
flyToItem(uuid)
}
})
// Expose methods for parent components
defineExpose({ flyTo, flyToItem })
</script>

View File

@@ -19,6 +19,7 @@
<!-- Left: List (scrollable) --> <!-- Left: List (scrollable) -->
<div class="w-2/5 overflow-y-auto pr-2"> <div class="w-2/5 overflow-y-auto pr-2">
<Stack gap="4"> <Stack gap="4">
<slot name="header" />
<slot name="filters" /> <slot name="filters" />
<Stack gap="3"> <Stack gap="3">
@@ -27,6 +28,8 @@
:key="item.uuid" :key="item.uuid"
:class="{ 'ring-2 ring-primary rounded-lg': item.uuid === selectedId }" :class="{ 'ring-2 ring-primary rounded-lg': item.uuid === selectedId }"
@click="onItemClick(item)" @click="onItemClick(item)"
@mouseenter="emit('update:hoveredId', item.uuid)"
@mouseleave="emit('update:hoveredId', undefined)"
> >
<slot name="card" :item="item" /> <slot name="card" :item="item" />
</div> </div>
@@ -42,8 +45,9 @@
</Stack> </Stack>
</div> </div>
<!-- Right: Map --> <!-- Right: Map (fixed position) -->
<div class="w-3/5 rounded-lg overflow-hidden"> <div class="w-3/5 relative">
<div class="fixed top-28 right-6 w-[calc(60%-3rem)] h-[calc(100vh-8rem)] rounded-lg overflow-hidden">
<ClientOnly> <ClientOnly>
<CatalogMap <CatalogMap
ref="mapRef" ref="mapRef"
@@ -55,11 +59,13 @@
</ClientOnly> </ClientOnly>
</div> </div>
</div> </div>
</div>
<!-- Mobile: toggle between list and map --> <!-- Mobile: toggle between list and map -->
<div class="lg:hidden flex-1 flex flex-col min-h-0"> <div class="lg:hidden flex-1 flex flex-col min-h-0">
<div class="flex-1 overflow-y-auto py-4" v-show="mobileView === 'list'"> <div class="flex-1 overflow-y-auto py-4" v-show="mobileView === 'list'">
<Stack gap="4"> <Stack gap="4">
<slot name="header" />
<slot name="filters" /> <slot name="filters" />
<Stack gap="3"> <Stack gap="3">
@@ -68,6 +74,8 @@
:key="item.uuid" :key="item.uuid"
:class="{ 'ring-2 ring-primary rounded-lg': item.uuid === selectedId }" :class="{ 'ring-2 ring-primary rounded-lg': item.uuid === selectedId }"
@click="onItemClick(item)" @click="onItemClick(item)"
@mouseenter="emit('update:hoveredId', item.uuid)"
@mouseleave="emit('update:hoveredId', undefined)"
> >
<slot name="card" :item="item" /> <slot name="card" :item="item" />
</div> </div>
@@ -120,6 +128,7 @@
<!-- Without Map: Simple List --> <!-- Without Map: Simple List -->
<div v-else class="flex-1 overflow-y-auto py-4"> <div v-else class="flex-1 overflow-y-auto py-4">
<Stack gap="4"> <Stack gap="4">
<slot name="header" />
<slot name="filters" /> <slot name="filters" />
<Stack gap="3"> <Stack gap="3">
@@ -162,6 +171,7 @@ const props = withDefaults(defineProps<{
mapId?: string mapId?: string
pointColor?: string pointColor?: string
selectedId?: string selectedId?: string
hoveredId?: string
}>(), { }>(), {
loading: false, loading: false,
withMap: true, withMap: true,
@@ -172,6 +182,7 @@ const props = withDefaults(defineProps<{
const emit = defineEmits<{ const emit = defineEmits<{
'select': [item: MapItem] 'select': [item: MapItem]
'update:selectedId': [uuid: string] 'update:selectedId': [uuid: string]
'update:hoveredId': [uuid: string | undefined]
}>() }>()
// Filter items with valid coordinates for map // Filter items with valid coordinates for map
@@ -229,6 +240,17 @@ watch(() => props.selectedId, (uuid) => {
} }
}) })
// Watch hoveredId and fly to it
watch(() => props.hoveredId, (uuid) => {
if (uuid && props.withMap) {
const item = itemsWithCoords.value.find(i => i.uuid === uuid)
if (item) {
mapRef.value?.flyTo(item.latitude, item.longitude, 8)
mobileMapRef.value?.flyTo(item.latitude, item.longitude, 8)
}
}
})
// Expose flyTo for external use // Expose flyTo for external use
const flyTo = (lat: number, lng: number, zoom = 8) => { const flyTo = (lat: number, lng: number, zoom = 8) => {
mapRef.value?.flyTo(lat, lng, zoom) mapRef.value?.flyTo(lat, lng, zoom)

View File

@@ -5,6 +5,7 @@
map-id="hubs-map" map-id="hubs-map"
point-color="#10b981" point-color="#10b981"
:selected-id="selectedHubId" :selected-id="selectedHubId"
v-model:hovered-id="hoveredHubId"
@select="onSelectHub" @select="onSelectHub"
> >
<template #filters> <template #filters>
@@ -59,8 +60,9 @@ const {
init init
} = useCatalogHubs() } = useCatalogHubs()
// Selected hub for map highlighting // Selected/hovered hub for map highlighting
const selectedHubId = ref<string>() const selectedHubId = ref<string>()
const hoveredHubId = ref<string>()
const onSelectHub = (hub: any) => { const onSelectHub = (hub: any) => {
selectedHubId.value = hub.uuid selectedHubId.value = hub.uuid

View File

@@ -5,6 +5,7 @@
map-id="offers-map" map-id="offers-map"
point-color="#f59e0b" point-color="#f59e0b"
:selected-id="selectedOfferId" :selected-id="selectedOfferId"
v-model:hovered-id="hoveredOfferId"
@select="onSelectOffer" @select="onSelectOffer"
> >
<template #filters> <template #filters>
@@ -78,8 +79,9 @@ const onProductFilterChange = (value: string) => {
setProductUuid(value === 'all' ? null : value) setProductUuid(value === 'all' ? null : value)
} }
// Selected offer for map highlighting // Selected/hovered offer for map highlighting
const selectedOfferId = ref<string>() const selectedOfferId = ref<string>()
const hoveredOfferId = ref<string>()
const onSelectOffer = (offer: any) => { const onSelectOffer = (offer: any) => {
selectedOfferId.value = offer.uuid selectedOfferId.value = offer.uuid

View File

@@ -5,6 +5,7 @@
map-id="suppliers-map" map-id="suppliers-map"
point-color="#3b82f6" point-color="#3b82f6"
:selected-id="selectedSupplierId" :selected-id="selectedSupplierId"
v-model:hovered-id="hoveredSupplierId"
@select="onSelectSupplier" @select="onSelectSupplier"
> >
<template #card="{ item }"> <template #card="{ item }">
@@ -44,8 +45,9 @@ const {
init init
} = useCatalogSuppliers() } = useCatalogSuppliers()
// Selected supplier for map highlighting // Selected/hovered supplier for map highlighting
const selectedSupplierId = ref<string>() const selectedSupplierId = ref<string>()
const hoveredSupplierId = ref<string>()
const onSelectSupplier = (supplier: any) => { const onSelectSupplier = (supplier: any) => {
selectedSupplierId.value = supplier.uuid || supplier.teamUuid selectedSupplierId.value = supplier.uuid || supplier.teamUuid

View File

@@ -1,71 +1,40 @@
<template> <template>
<div class="flex flex-col flex-1 min-h-0"> <CatalogPage
<!-- Loading state -->
<div v-if="isLoading" class="flex-1 flex items-center justify-center">
<Card padding="lg">
<Stack align="center" justify="center" gap="3">
<Spinner />
<Text tone="muted">{{ t('profileAddresses.states.loading') }}</Text>
</Stack>
</Card>
</div>
<!-- ListMapLayout -->
<ListMapLayout
v-else-if="items.length"
:items="itemsForMap" :items="itemsForMap"
:selected-item-id="selectedAddressId" :loading="isLoading"
:hovered-item-id="hoveredAddressId"
map-id="addresses-map" map-id="addresses-map"
point-color="#10b981" point-color="#10b981"
@select-item="onSelectAddress" :selected-id="selectedAddressId"
v-model:hovered-id="hoveredAddressId"
@select="onSelectAddress"
> >
<template #list> <template #header>
<Stack gap="4">
<!-- Add new address button -->
<NuxtLink :to="localePath('/clientarea/addresses/new')"> <NuxtLink :to="localePath('/clientarea/addresses/new')">
<Button variant="outline" class="w-full"> <Button variant="outline" class="w-full">
<Icon name="lucide:plus" size="16" class="mr-2" /> <Icon name="lucide:plus" size="16" class="mr-2" />
{{ t('profileAddresses.actions.add') }} {{ t('profileAddresses.actions.add') }}
</Button> </Button>
</NuxtLink> </NuxtLink>
</template>
<!-- Address cards --> <template #card="{ item }">
<Stack gap="3">
<NuxtLink <NuxtLink
v-for="addr in items" :to="localePath(`/clientarea/addresses/${item.uuid}`)"
:key="addr.uuid"
:to="localePath(`/clientarea/addresses/${addr.uuid}`)"
class="block" class="block"
> >
<Card <Card padding="sm" interactive>
padding="sm"
interactive
:class="{ 'ring-2 ring-primary': addr.uuid === selectedAddressId }"
@click.prevent="onSelectAddress(addr.uuid)"
@mouseenter="hoveredAddressId = addr.uuid"
@mouseleave="hoveredAddressId = undefined"
>
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
<Text size="base" weight="semibold" class="truncate">{{ addr.name }}</Text> <Text size="base" weight="semibold" class="truncate">{{ item.name }}</Text>
<Text tone="muted" size="sm" class="line-clamp-2">{{ addr.address }}</Text> <Text tone="muted" size="sm" class="line-clamp-2">{{ item.address }}</Text>
<div class="flex items-center mt-1"> <div class="flex items-center mt-1">
<span class="text-lg">{{ isoToEmoji(addr.countryCode) }}</span> <span class="text-lg">{{ isoToEmoji(item.countryCode) }}</span>
</div> </div>
</div> </div>
</Card> </Card>
</NuxtLink> </NuxtLink>
</Stack>
<Stack v-if="items.length === 0" align="center" gap="2">
<Text tone="muted">{{ t('profileAddresses.empty.title') }}</Text>
</Stack>
</Stack>
</template> </template>
</ListMapLayout>
<!-- Empty state --> <template #empty>
<div v-else class="flex-1 flex items-center justify-center">
<EmptyState <EmptyState
icon="📍" icon="📍"
:title="t('profileAddresses.empty.title')" :title="t('profileAddresses.empty.title')"
@@ -74,8 +43,8 @@
:action-to="localePath('/clientarea/addresses/new')" :action-to="localePath('/clientarea/addresses/new')"
action-icon="lucide:plus" action-icon="lucide:plus"
/> />
</div> </template>
</div> </CatalogPage>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -97,19 +66,21 @@ const {
const selectedAddressId = ref<string>() const selectedAddressId = ref<string>()
const hoveredAddressId = ref<string>() const hoveredAddressId = ref<string>()
// Map items for ListMapLayout // Map items for CatalogPage
const itemsForMap = computed(() => { const itemsForMap = computed(() => {
return items.value.map(addr => ({ return items.value.map(addr => ({
uuid: addr.uuid, uuid: addr.uuid,
name: addr.name, name: addr.name,
address: addr.address,
latitude: addr.latitude, latitude: addr.latitude,
longitude: addr.longitude, longitude: addr.longitude,
countryCode: addr.countryCode,
country: addr.countryCode country: addr.countryCode
})) }))
}) })
const onSelectAddress = (uuid: string) => { const onSelectAddress = (item: any) => {
selectedAddressId.value = uuid selectedAddressId.value = item.uuid
} }
await init() await init()

View File

@@ -1,59 +1,27 @@
<template> <template>
<div class="flex flex-col flex-1 min-h-0"> <CatalogPage
<!-- Loading state -->
<div v-if="isLoading" class="flex-1 flex items-center justify-center">
<Card padding="lg">
<Stack align="center" justify="center" gap="3">
<Spinner />
<Text tone="muted">{{ t('ordersList.states.loading') }}</Text>
</Stack>
</Card>
</div>
<!-- Error state -->
<div v-else-if="hasError" class="flex-1 flex items-center justify-center">
<Alert variant="error">
<Stack gap="2">
<Heading :level="4" weight="semibold">{{ $t('common.error') }}</Heading>
<Text tone="muted">{{ error }}</Text>
<Button @click="load">{{ t('ordersList.errors.retry') }}</Button>
</Stack>
</Alert>
</div>
<!-- ListMapLayout -->
<ListMapLayout
v-else-if="items.length"
:items="itemsForMap" :items="itemsForMap"
:selected-item-id="selectedOrderId" :loading="isLoading"
:hovered-item-id="hoveredOrderId"
map-id="orders-map" map-id="orders-map"
point-color="#6366f1" point-color="#6366f1"
@select-item="onSelectOrder" :selected-id="selectedOrderId"
v-model:hovered-id="hoveredOrderId"
@select="onSelectOrder"
> >
<template #list> <template #filters>
<Stack gap="4"> <CatalogFilterSelect :filters="filters" v-model="selectedFilter" />
<CatalogFilters :filters="filters" v-model="selectedFilter" /> </template>
<Stack gap="4"> <template #card="{ item }">
<Card <Card padding="lg" class="cursor-pointer">
v-for="order in filteredItems"
:key="order.uuid"
padding="lg"
class="cursor-pointer"
:class="{ 'ring-2 ring-primary': order.uuid === selectedOrderId }"
@click="onSelectOrder(order.uuid)"
@mouseenter="hoveredOrderId = order.uuid"
@mouseleave="hoveredOrderId = undefined"
>
<Stack gap="4"> <Stack gap="4">
<Stack direction="row" justify="between" align="center"> <Stack direction="row" justify="between" align="center">
<Stack gap="1"> <Stack gap="1">
<Text size="sm" tone="muted">{{ t('ordersList.card.order_label') }}</Text> <Text size="sm" tone="muted">{{ t('ordersList.card.order_label') }}</Text>
<Heading :level="3">#{{ order.name }}</Heading> <Heading :level="3">#{{ item.name }}</Heading>
</Stack> </Stack>
<div class="badge badge-outline"> <div class="badge badge-outline">
{{ getOrderStartDate(order) }} {{ getOrderEndDate(order) }} {{ getOrderStartDate(item) }} {{ getOrderEndDate(item) }}
</div> </div>
</Stack> </Stack>
@@ -62,43 +30,35 @@
<Grid :cols="1" :md="3" :gap="3"> <Grid :cols="1" :md="3" :gap="3">
<Stack gap="1"> <Stack gap="1">
<Text size="sm" tone="muted">{{ t('ordersList.card.route') }}</Text> <Text size="sm" tone="muted">{{ t('ordersList.card.route') }}</Text>
<Text weight="semibold">{{ order.sourceLocationName }} {{ order.destinationLocationName }}</Text> <Text weight="semibold">{{ item.sourceLocationName }} {{ item.destinationLocationName }}</Text>
</Stack> </Stack>
<Stack gap="1"> <Stack gap="1">
<Text size="sm" tone="muted">{{ t('ordersList.card.product') }}</Text> <Text size="sm" tone="muted">{{ t('ordersList.card.product') }}</Text>
<Text> <Text>
{{ order.orderLines?.[0]?.productName || t('ordersList.card.product_loading') }} {{ item.orderLines?.[0]?.productName || t('ordersList.card.product_loading') }}
<template v-if="order.orderLines?.length > 1"> <template v-if="item.orderLines?.length > 1">
<span class="badge badge-ghost ml-2">+{{ order.orderLines.length - 1 }}</span> <span class="badge badge-ghost ml-2">+{{ item.orderLines.length - 1 }}</span>
</template> </template>
</Text> </Text>
<Text tone="muted" size="sm"> <Text tone="muted" size="sm">
{{ order.orderLines?.[0]?.quantity || 0 }} {{ order.orderLines?.[0]?.unit || t('ordersList.card.unit_tons') }} {{ item.orderLines?.[0]?.quantity || 0 }} {{ item.orderLines?.[0]?.unit || t('ordersList.card.unit_tons') }}
</Text> </Text>
</Stack> </Stack>
<Stack gap="1"> <Stack gap="1">
<Text size="sm" tone="muted">{{ t('ordersList.card.status') }}</Text> <Text size="sm" tone="muted">{{ t('ordersList.card.status') }}</Text>
<Badge :variant="getStatusVariant(order.status)"> <Badge :variant="getStatusVariant(item.status)">
{{ getStatusText(order.status) }} {{ getStatusText(item.status) }}
</Badge> </Badge>
<Text tone="muted" size="sm">{{ t('ordersList.card.stages_completed', { done: getCompletedStages(order), total: order.stages?.length || 0 }) }}</Text> <Text tone="muted" size="sm">{{ t('ordersList.card.stages_completed', { done: getCompletedStages(item), total: item.stages?.length || 0 }) }}</Text>
</Stack> </Stack>
</Grid> </Grid>
</Stack> </Stack>
</Card> </Card>
</Stack>
<Stack v-if="filteredItems.length === 0" align="center" gap="2">
<Text tone="muted">{{ $t('orders.no_orders') }}</Text>
</Stack>
</Stack>
</template> </template>
</ListMapLayout>
<!-- Empty state --> <template #empty>
<div v-else class="flex-1 flex items-center justify-center">
<EmptyState <EmptyState
icon="📦" icon="📦"
:title="$t('orders.no_orders')" :title="$t('orders.no_orders')"
@@ -107,8 +67,8 @@
:action-to="localePath('/clientarea')" :action-to="localePath('/clientarea')"
action-icon="lucide:plus" action-icon="lucide:plus"
/> />
</div> </template>
</div> </CatalogPage>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -121,25 +81,22 @@ const localePath = useLocalePath()
const { t } = useI18n() const { t } = useI18n()
const { const {
items,
filteredItems, filteredItems,
isLoading, isLoading,
filters, filters,
selectedFilter, selectedFilter,
load,
init, init,
getStatusVariant, getStatusVariant,
getStatusText getStatusText
} = useTeamOrders() } = useTeamOrders()
const hasError = ref(false)
const error = ref('')
const selectedOrderId = ref<string>() const selectedOrderId = ref<string>()
const hoveredOrderId = ref<string>() const hoveredOrderId = ref<string>()
// Map items for ListMapLayout (use source location coordinates) // Map items for CatalogPage (use source location coordinates)
const itemsForMap = computed(() => { const itemsForMap = computed(() => {
return items.value.map(order => ({ return filteredItems.value.map(order => ({
...order,
uuid: order.uuid, uuid: order.uuid,
name: order.name || `#${order.uuid.slice(0, 8)}`, name: order.name || `#${order.uuid.slice(0, 8)}`,
latitude: order.sourceLatitude, latitude: order.sourceLatitude,
@@ -148,16 +105,11 @@ const itemsForMap = computed(() => {
})) }))
}) })
const onSelectOrder = (uuid: string) => { const onSelectOrder = (item: any) => {
selectedOrderId.value = uuid selectedOrderId.value = item.uuid
} }
try { await init()
await init()
} catch (err: any) {
hasError.value = true
error.value = err.message || t('ordersDetail.errors.load_failed')
}
const getOrderStartDate = (order: any) => { const getOrderStartDate = (order: any) => {
if (!order.createdAt) return t('ordersDetail.labels.dates_undefined') if (!order.createdAt) return t('ordersDetail.labels.dates_undefined')