lang full
This commit is contained in:
@@ -27,6 +27,7 @@ export function usePostSocialState(postData: Post) {
|
||||
is_liked,
|
||||
savesCount: initialSaves = 0,
|
||||
sendsCount: initialSends = 0,
|
||||
sharesCount: initialShares = 0,
|
||||
is_saved: initialSaved = false,
|
||||
is_following: initialFollowing = false,
|
||||
type: postType,
|
||||
@@ -37,6 +38,7 @@ export function usePostSocialState(postData: Post) {
|
||||
const [saved, setSaved] = useState(() => coerceBool(initialSaved));
|
||||
const [savesCount, setSavesCount] = useState(initialSaves);
|
||||
const [sendsCount, setSendsCount] = useState(initialSends);
|
||||
const [sharesCount, setSharesCount] = useState(initialShares);
|
||||
const [following, setFollowing] = useState(() => coerceBool(initialFollowing));
|
||||
|
||||
useEffect(() => {
|
||||
@@ -45,6 +47,7 @@ export function usePostSocialState(postData: Post) {
|
||||
setSaved(coerceBool(initialSaved));
|
||||
setSavesCount(initialSaves);
|
||||
setSendsCount(initialSends);
|
||||
setSharesCount(initialShares);
|
||||
setFollowing(coerceBool(initialFollowing));
|
||||
}, [
|
||||
postId,
|
||||
@@ -53,6 +56,7 @@ export function usePostSocialState(postData: Post) {
|
||||
initialSaved,
|
||||
initialSaves,
|
||||
initialSends,
|
||||
initialShares,
|
||||
initialFollowing,
|
||||
]);
|
||||
|
||||
@@ -195,21 +199,36 @@ export function usePostSocialState(postData: Post) {
|
||||
}
|
||||
}, [requireAuth, user_id, isOwnPost, loading, following, request, t]);
|
||||
|
||||
const trackShare = useCallback(() => {
|
||||
const trackShare = useCallback(async () => {
|
||||
const token = Cookies.get("token") || "";
|
||||
if (token) {
|
||||
trackExploreInteraction(
|
||||
{
|
||||
targetType: "post",
|
||||
targetId: postId,
|
||||
authorId: user_id,
|
||||
contentType: postType === "video" ? "video" : "image",
|
||||
action: "share",
|
||||
},
|
||||
token
|
||||
if (!token) return;
|
||||
|
||||
trackExploreInteraction(
|
||||
{
|
||||
targetType: "post",
|
||||
targetId: postId,
|
||||
authorId: user_id,
|
||||
contentType: postType === "video" ? "video" : "image",
|
||||
action: "share",
|
||||
},
|
||||
token
|
||||
);
|
||||
|
||||
if (!postId) return;
|
||||
try {
|
||||
const response = await request<{ sharesCount?: number }>(
|
||||
"POST",
|
||||
"/posts/share",
|
||||
{ postId },
|
||||
{ noToast: true }
|
||||
);
|
||||
if (typeof response?.sharesCount === "number") {
|
||||
setSharesCount(response.sharesCount);
|
||||
}
|
||||
} catch {
|
||||
/* best-effort share count */
|
||||
}
|
||||
}, [postId, user_id, postType]);
|
||||
}, [postId, user_id, postType, request]);
|
||||
|
||||
return {
|
||||
liked,
|
||||
@@ -217,6 +236,7 @@ export function usePostSocialState(postData: Post) {
|
||||
saved,
|
||||
savesCount,
|
||||
sendsCount,
|
||||
sharesCount,
|
||||
setSendsCount,
|
||||
following,
|
||||
commentCount,
|
||||
|
||||
Reference in New Issue
Block a user