fix favorite

This commit is contained in:
hamid zarghami
2025-07-23 16:29:06 +03:30
parent 1f3dcac623
commit ee3ea31ab2
2 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ VITE_BASE_URL = 'https://dmail-api.danakcorp.com'
VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e' VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e'
VITE_MAILBOXES = 'mailboxes' VITE_MAILBOXES = 'mailboxes'
+5 -2
View File
@@ -1,4 +1,4 @@
import { FC, useState } from 'react' import { FC, useEffect, useState } from 'react'
import { Star1 } from 'iconsax-react' import { Star1 } from 'iconsax-react'
import { useMoveToFavorite, useUnFavoriteMessage } from '../hooks/useEmailData'; import { useMoveToFavorite, useUnFavoriteMessage } from '../hooks/useEmailData';
@@ -11,7 +11,6 @@ const Favorite: FC<{ flagged: boolean, id: string, mailbox: string }> = ({ flagg
const handleFavoriteClick = (e: React.MouseEvent) => { const handleFavoriteClick = (e: React.MouseEvent) => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
console.log('Favorite clicked!', { isFavorite, id, mailbox })
if (isFavorite) { if (isFavorite) {
unFavoriteMessage({ messageId: id || '', mailbox: mailbox || '' }) unFavoriteMessage({ messageId: id || '', mailbox: mailbox || '' })
@@ -21,6 +20,10 @@ const Favorite: FC<{ flagged: boolean, id: string, mailbox: string }> = ({ flagg
setIsFavorite(!isFavorite) setIsFavorite(!isFavorite)
} }
useEffect(() => {
setIsFavorite(flagged)
}, [flagged])
return ( return (
<div className="inline-block mt-[3px] relative -right-6" onClick={handleFavoriteClick}> <div className="inline-block mt-[3px] relative -right-6" onClick={handleFavoriteClick}>
<Star1 <Star1