cart checker for remove cart when slug changed
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"use client"
|
||||
|
||||
import { useCart } from '@/app/[name]/(Dialogs)/cart/hook/useCart'
|
||||
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData'
|
||||
import { useParams } from 'next/navigation'
|
||||
import { useEffect, useRef, type FC } from 'react'
|
||||
|
||||
const CartChecker: FC = () => {
|
||||
|
||||
const { isSuccess } = useGetProfile()
|
||||
const params = useParams()
|
||||
const currentSlug = params.name as string
|
||||
const { slug: cartSlug, clearCart } = useCart()
|
||||
const hasClearedRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSuccess && currentSlug && cartSlug && currentSlug !== cartSlug) {
|
||||
if (!hasClearedRef.current) {
|
||||
hasClearedRef.current = true
|
||||
clearCart()
|
||||
}
|
||||
} else if (currentSlug === cartSlug) {
|
||||
hasClearedRef.current = false
|
||||
}
|
||||
}, [isSuccess, currentSlug, cartSlug, clearCart])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export default CartChecker
|
||||
@@ -43,7 +43,7 @@ function applyPrimaryColor(colorHex: string) {
|
||||
|
||||
function PreferenceWrapper({ children }: Props) {
|
||||
const { state: nightMode } = usePreference('night-mode', false);
|
||||
const { data: aboutData, isSuccess } = useGetAbout();
|
||||
const { data: aboutData } = useGetAbout();
|
||||
|
||||
// بررسی اینکه آیا باید اسپلش نمایش داده بشه
|
||||
const [showSplash, setShowSplash] = useState(() => {
|
||||
@@ -90,6 +90,7 @@ function PreferenceWrapper({ children }: Props) {
|
||||
|
||||
applyPrimaryColor(aboutData.data.menuColor);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [aboutData?.data?.menuColor]);
|
||||
|
||||
// اعمال تم تاریک/روشن
|
||||
|
||||
Reference in New Issue
Block a user