This commit is contained in:
payacom
2026-09-19 12:28:28 +03:30
parent 76d5652252
commit 3b89bbfec3
18 changed files with 275 additions and 145 deletions

View File

@@ -28,6 +28,7 @@ export function usePostSocialState(postData: Post) {
savesCount: initialSaves = 0,
sendsCount: initialSends = 0,
sharesCount: initialShares = 0,
offersCount: initialOffers = 0,
is_saved: initialSaved = false,
is_following: initialFollowing = false,
type: postType,
@@ -39,6 +40,7 @@ export function usePostSocialState(postData: Post) {
const [savesCount, setSavesCount] = useState(initialSaves);
const [sendsCount, setSendsCount] = useState(initialSends);
const [sharesCount, setSharesCount] = useState(initialShares);
const [offersCount, setOffersCount] = useState(initialOffers);
const [following, setFollowing] = useState(() => coerceBool(initialFollowing));
useEffect(() => {
@@ -48,6 +50,7 @@ export function usePostSocialState(postData: Post) {
setSavesCount(initialSaves);
setSendsCount(initialSends);
setSharesCount(initialShares);
setOffersCount(initialOffers);
setFollowing(coerceBool(initialFollowing));
}, [
postId,
@@ -57,6 +60,7 @@ export function usePostSocialState(postData: Post) {
initialSaves,
initialSends,
initialShares,
initialOffers,
initialFollowing,
]);
@@ -230,6 +234,27 @@ export function usePostSocialState(postData: Post) {
}
}, [postId, user_id, postType, request]);
// برخلافِ share/send، درخواستِ همکاری endpoint اختصاصیِ برگردوننده‌ی شمارشِ تازه
// نداره — فقط رویدادِ ExploreInteraction(action:"offer") ثبت می‌شه (همونی که
// postEngagement.js سمتِ بک‌اند برای offersCount می‌شمردش) و شمارش سمتِ کلاینت
// خوش‌بینانه +۱ می‌شه
const trackOffer = useCallback(() => {
const token = Cookies.get("token") || "";
if (!token || !postId) return;
setOffersCount((c) => c + 1);
trackExploreInteraction(
{
targetType: "post",
targetId: postId,
authorId: user_id,
contentType: postType === "video" ? "video" : "image",
action: "offer",
},
token
);
}, [postId, user_id, postType]);
return {
liked,
likesCountState,
@@ -237,6 +262,7 @@ export function usePostSocialState(postData: Post) {
savesCount,
sendsCount,
sharesCount,
offersCount,
setSendsCount,
following,
commentCount,
@@ -247,6 +273,7 @@ export function usePostSocialState(postData: Post) {
toggleSave,
toggleFollow,
trackShare,
trackOffer,
};
}