2026-09-18 12:54:45 +03:30
|
|
|
<!--
|
|
|
|
|
Ported from legacy henza_pwa/src/views/user/src/components/favorits.vue,
|
|
|
|
|
restyled into the redesigned design language (see components/home/* and
|
|
|
|
|
HomeView).
|
|
|
|
|
|
2026-10-12 15:19:50 +03:30
|
|
|
Favourites are server-side (FAV-01: GET/POST customer/me/favorites), and the
|
|
|
|
|
products behind them are fetched BY ID — the saved ids go straight to
|
|
|
|
|
`?ids=…`, one request for the lot.
|
|
|
|
|
|
|
|
|
|
It used to fetch the whole catalogue and filter it in the browser, which with
|
|
|
|
|
~16k products meant downloading all of them to show a handful. It was also
|
|
|
|
|
wrong beyond the first page once paging existed: a favourite outside the
|
|
|
|
|
loaded slice would simply not appear.
|
2026-09-18 12:54:45 +03:30
|
|
|
-->
|
|
|
|
|
<template>
|
|
|
|
|
<div class="favs">
|
|
|
|
|
<PageBar title="علاقهمندی" back-to="userPage::hasSubRoute" />
|
|
|
|
|
|
|
|
|
|
<Spinner :spinning="loading" tip="در حال دریافت اطلاعات">
|
|
|
|
|
<container class="favs__body">
|
|
|
|
|
<template v-if="favoriteProducts.length">
|
|
|
|
|
<SectionHead title="ذخیرهشدهها" :subtitle="`${favoriteProducts.length} محصول`" />
|
|
|
|
|
<div class="favs__grid">
|
|
|
|
|
<ProductCard v-for="item in favoriteProducts" :key="item.id" :value="item" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<section v-else-if="!loading" class="favs__empty">
|
|
|
|
|
<Icon icon="vuesax-linear:heart" size="26" />
|
|
|
|
|
<p>هنوز محصولی را به علاقهمندیها اضافه نکردهاید.</p>
|
|
|
|
|
<button type="button" class="favs__emptyCta" @click="router.push({ name: 'home' })">
|
|
|
|
|
دیدن محصولات
|
|
|
|
|
</button>
|
|
|
|
|
</section>
|
|
|
|
|
</container>
|
|
|
|
|
</Spinner>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-10-12 15:19:50 +03:30
|
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
2026-09-18 12:54:45 +03:30
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
import Icon from '../../components/icon/Icon.vue'
|
|
|
|
|
import PageBar from '../../components/ui/PageBar.vue'
|
|
|
|
|
import Spinner from '../../components/Spinner.vue'
|
|
|
|
|
import SectionHead from '../../components/home/SectionHead.vue'
|
|
|
|
|
import ProductCard from '../../components/product/ProductCard.vue'
|
|
|
|
|
import { useFavoritesStore } from '../../stores/favoritesStore'
|
2026-10-12 15:19:50 +03:30
|
|
|
import { api, type ProductSummary } from '../../api/client'
|
2026-09-18 12:54:45 +03:30
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const favorites = useFavoritesStore()
|
|
|
|
|
const loading = ref(false)
|
2026-10-12 15:19:50 +03:30
|
|
|
const fetched = ref<ProductSummary[]>([])
|
2026-09-18 12:54:45 +03:30
|
|
|
|
2026-10-12 15:19:50 +03:30
|
|
|
/**
|
|
|
|
|
* Still filtered against the store, so un-hearting a product removes its card
|
|
|
|
|
* at once without waiting for a refetch — the fetched list is the source of the
|
|
|
|
|
* product DATA, the store is the source of truth for what is saved.
|
|
|
|
|
*/
|
|
|
|
|
const favoriteProducts = computed(() => fetched.value.filter((p) => favorites.isFavorite(p.id)))
|
2026-09-18 12:54:45 +03:30
|
|
|
|
2026-10-12 15:19:50 +03:30
|
|
|
async function load() {
|
|
|
|
|
const ids = favorites.ids
|
|
|
|
|
if (ids.length === 0) {
|
|
|
|
|
fetched.value = []
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
loading.value = fetched.value.length === 0
|
2026-09-18 12:54:45 +03:30
|
|
|
try {
|
2026-10-12 15:19:50 +03:30
|
|
|
fetched.value = await api.getProductsByIds(ids)
|
2026-10-11 14:31:32 +03:30
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e)
|
2026-09-18 12:54:45 +03:30
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
2026-10-12 15:19:50 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(load)
|
|
|
|
|
|
|
|
|
|
// The ids arrive from the server just after sign-in, and change when the person
|
|
|
|
|
// hearts something elsewhere in the app — both land here as a new id list.
|
|
|
|
|
watch(() => favorites.ids.join(','), load)
|
2026-09-18 12:54:45 +03:30
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
.favs {
|
2026-10-04 16:18:56 +03:30
|
|
|
background: @page;
|
2026-09-18 12:54:45 +03:30
|
|
|
min-height: 100vh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.favs__body {
|
|
|
|
|
padding-top: 76px;
|
|
|
|
|
padding-bottom: 90px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.favs__grid {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
|
|
|
gap: 14px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.favs__empty {
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
padding: 38px 20px;
|
|
|
|
|
border: 1px dashed @hairline;
|
|
|
|
|
border-radius: 18px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
color: @inkFaint;
|
|
|
|
|
}
|
|
|
|
|
.favs__empty p {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 12.5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.favs__emptyCta {
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
padding: 9px 18px;
|
|
|
|
|
border: 0;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
font-family: inherit;
|
|
|
|
|
font-size: 12.5px;
|
|
|
|
|
font-weight: 700;
|
2026-10-04 16:18:56 +03:30
|
|
|
color: @onInk;
|
2026-09-18 12:54:45 +03:30
|
|
|
background: @ink;
|
|
|
|
|
}
|
|
|
|
|
</style>
|