fix order

This commit is contained in:
javad committed 2026-10-09 11:06:09 +03:30
1 parent c6d732ff10
commit 93873228ff
3 files changed
+82 -37

No files matched your search

+18 -25
View File
@@ -1,37 +1,30 @@
'use client'
import ProductCategoryBox from '@/app/components/layout/shop/products-cat'
import Image from 'next/image'
import axiosInstance from '@/axios/axiosInstance'
import { useEffect, useState } from 'react'
import { useQuery,useQueryClient } from '@tanstack/react-query'
import { useEffect } from 'react'
import { useQuery } from '@tanstack/react-query'
const Page = ()=>{
const [category, setCategory] = useState([])
const queryClient = useQueryClient()
useEffect(()=>{
},[])
const query = useQuery({ queryKey: ['categoryProducts'], queryFn: async ()=>{
return await axiosInstance.get("shop/v2/product-category/list/")
},refetchOnWindowFocus:false, onSuccess(result:any) {
},refetchOnWindowFocus:true, })
setCategory(result.data)
setTimeout(async ()=>{
const scrollpos = localStorage.getItem('scrollY')
if (scrollpos){
await window.scrollTo(0, parseInt(scrollpos));
const category = query.data?.data ?? []
useEffect(() => {
if (!query.isSuccess) return
const frame = requestAnimationFrame(() => {
try {
const position = Number(localStorage.getItem('scrollY'))
if (Number.isFinite(position) && position > 0) window.scrollTo(0, position)
} catch {
console.warn('Could not restore the saved shop scroll position.')
}
},150)
}, })
})
return () => cancelAnimationFrame(frame)
}, [query.isSuccess])
if(query.isLoading){
return (
@@ -53,10 +46,10 @@ const Page = ()=>{
{query.isSuccess?category.map((iteam:any)=>{
return <ProductCategoryBox key={iteam.id} iteam={iteam} />
}):null}
</div>
</>
)
}
export default Page
export default Page