160 lines
5.4 KiB
TypeScript
160 lines
5.4 KiB
TypeScript
// Metro module 8699 (f8700).
|
|
import { useState, useEffect, useCallback } from "react";
|
|
import UserProfileStore from "../../user_profile/UserProfileStore";
|
|
import useAnalyticsLocations from "../../app_analytics/useAnalyticsLocations";
|
|
import { isNullOrEmpty } from "../../../utils/StringUtils";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import { useIsSkuInWishlist } from "../../wishlists/hooks/useWishlistHooks";
|
|
import WishlistActionCreators from "../../wishlists/WishlistActionCreators";
|
|
import { AccessibilityAnnouncer } from "../../../design/shared";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
export function useWishlistButtonState({ userId, skuId, location: location2, onAddSuccess, onRemoveSuccess, onError, skipAddAnnouncement }) {
|
|
let setState, state, setState2, state2;
|
|
setState = void 0;
|
|
state = void 0;
|
|
setState2 = void 0;
|
|
state2 = void 0;
|
|
const analyticsLocations = useAnalyticsLocations(isNullOrEmpty(location2) ? [] : [location2]).analyticsLocations;
|
|
const stateFromStores = useStateFromStores([UserProfileStore], () => UserProfileStore.getFirstWishlistId(userId));
|
|
let r37 = useIsSkuInWishlist(stateFromStores, skuId);
|
|
let state3;
|
|
[state3, setState] = useState(null);
|
|
[state, setState2] = useState(false);
|
|
if (state3 !== null) {
|
|
r37 = state3;
|
|
}
|
|
state2 = r37;
|
|
useEffect(() => {
|
|
setState(null);
|
|
setState2(false);
|
|
}, [skuId]);
|
|
return {
|
|
isWishlisted: state2,
|
|
isBusy: state,
|
|
handleToggle: useCallback(async () => {
|
|
let c26272_2;
|
|
let c26272_3 = 0;
|
|
let c29972_0, c29972_1;
|
|
L26: {
|
|
L18: {
|
|
try {
|
|
if (state) {
|
|
break L26;
|
|
}
|
|
setState2(true);
|
|
if (state2 && stateFromStores != null) {
|
|
setState(false);
|
|
c26272_3 = 3;
|
|
await WishlistActionCreators.removeSkuFromWishlist(stateFromStores, skuId, analyticsLocations);
|
|
AccessibilityAnnouncer.announce(intl.string(t.DSXOiP));
|
|
if (onRemoveSuccess != null) {
|
|
onRemoveSuccess();
|
|
}
|
|
c26272_3 = 1;
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
break L18;
|
|
}
|
|
setState(true);
|
|
c26272_3 = 4;
|
|
await WishlistActionCreators.addSkuToWishlist(skuId, analyticsLocations);
|
|
if (!skipAddAnnouncement) {
|
|
AccessibilityAnnouncer.announce(intl.string(t["3T2jbf"]));
|
|
}
|
|
if (onAddSuccess != null) {
|
|
onAddSuccess();
|
|
}
|
|
c26272_3 = 2;
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
} catch ($e) {
|
|
const r35 = $e;
|
|
let r7 = r35;
|
|
c26272_2 = r35;
|
|
let r36 = c26272_3;
|
|
if (r36 !== 0) {
|
|
while (true) {
|
|
if (r36 === 1) {
|
|
try {
|
|
const r212 = c26272_2;
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
throw r212;
|
|
} catch (r210) {
|
|
r7 = r210;
|
|
c26272_2 = r210;
|
|
r36 = c26272_3;
|
|
if (r36 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else if (r36 === 2) {
|
|
try {
|
|
const r202 = c26272_2;
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
throw r202;
|
|
} catch (r200) {
|
|
r7 = r200;
|
|
c26272_2 = r200;
|
|
r36 = c26272_3;
|
|
if (r36 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else if (r36 === 3) {
|
|
try {
|
|
const r186 = c26272_2;
|
|
c26272_3 = 1;
|
|
c29972_0 = r186;
|
|
if (onError != null) {
|
|
onError(c29972_0);
|
|
}
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
break L18;
|
|
} catch (r183) {
|
|
r7 = r183;
|
|
c26272_2 = r183;
|
|
r36 = c26272_3;
|
|
if (r36 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
const r169 = c26272_2;
|
|
c26272_3 = 2;
|
|
c29972_1 = r169;
|
|
if (onError != null) {
|
|
onError(c29972_1);
|
|
}
|
|
c26272_3 = 0;
|
|
(0, setState)(null);
|
|
(0, setState2)(false);
|
|
break L18;
|
|
} catch (r166) {
|
|
r7 = r166;
|
|
c26272_2 = r166;
|
|
r36 = c26272_3;
|
|
if (r36 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
}, [state, state2, stateFromStores, skuId, analyticsLocations, onAddSuccess, onRemoveSuccess, onError, skipAddAnnouncement])
|
|
};
|
|
}
|