84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
// Metro module 14058 (f14059).
|
|
import { useState, useRef, useCallback } from "react";
|
|
import BountyStore from "../../BountyStore";
|
|
import { QuestsExperimentLocations } from "../../QuestConstants";
|
|
import { useBountiesExperience } from "../../experiments/useBountiesExperience";
|
|
import { BountyVideoEndMode } from "./useBountiesModalTiming";
|
|
import { setBountyVideoProgress } from "../../BountyActionCreators";
|
|
let c9830_6 = {
|
|
timestampSec: 0,
|
|
maxTimestampSec: 0,
|
|
duration: 0
|
|
};
|
|
export function useBountyVideoProgressPersistence({ bountyId, endMode }) {
|
|
let ref, ref2, ref3, ref4;
|
|
ref = void 0;
|
|
ref2 = void 0;
|
|
ref3 = void 0;
|
|
ref4 = void 0;
|
|
const bountiesExperience = useBountiesExperience(QuestsExperimentLocations.VIDEO_MODAL_MOBILE);
|
|
let ownedByVerticalScrollExperiment = bountiesExperience.ownedByVerticalScrollExperiment;
|
|
const stage1Enabled2 = bountiesExperience.stage1Enabled;
|
|
if (!ownedByVerticalScrollExperiment) {
|
|
ownedByVerticalScrollExperiment = stage1Enabled2;
|
|
}
|
|
const stage1Enabled = ownedByVerticalScrollExperiment;
|
|
const [initialProgress] = useState(() => {
|
|
let r10;
|
|
if (stage1Enabled) {
|
|
L9: {
|
|
L8: {
|
|
r10 = BountyStore.getBountyVideoProgress(bountyId);
|
|
if (r10 != null) {
|
|
if (endMode === BountyVideoEndMode.LOOP) {
|
|
const { maxTimestampSec, duration } = r10;
|
|
if (duration > 0 && maxTimestampSec >= duration - 1) {
|
|
break L8;
|
|
}
|
|
}
|
|
if (!(r10.timestampSec <= 5)) {
|
|
break L9;
|
|
}
|
|
}
|
|
}
|
|
r10 = c9830_6;
|
|
}
|
|
return r10;
|
|
}
|
|
return c9830_6;
|
|
});
|
|
ref = useRef(0);
|
|
ref2 = useRef(initialProgress.timestampSec);
|
|
ref3 = useRef(initialProgress.maxTimestampSec);
|
|
ref4 = useRef(initialProgress.duration);
|
|
return {
|
|
initialProgress,
|
|
handleProgress: useCallback((a0, a1, a2) => {
|
|
ref2.current = a2;
|
|
ref3.current = a0;
|
|
ref4.current = a1;
|
|
let r11 = stage1Enabled;
|
|
if (stage1Enabled) {
|
|
r11 = a2 >= ref.current;
|
|
}
|
|
if (r11) {
|
|
ref.current = a2 + 1;
|
|
setBountyVideoProgress(bountyId, {
|
|
timestampSec: a2,
|
|
maxTimestampSec: a0,
|
|
duration: a1
|
|
});
|
|
}
|
|
}, [stage1Enabled, bountyId]),
|
|
flushProgress: useCallback(() => {
|
|
if (stage1Enabled) {
|
|
setBountyVideoProgress(bountyId, {
|
|
timestampSec: ref2.current,
|
|
maxTimestampSec: ref3.current,
|
|
duration: ref4.current
|
|
});
|
|
}
|
|
}, [stage1Enabled, bountyId])
|
|
};
|
|
}
|