decord/source/modules/polls/useCreatePollFormData.tsx

392 lines
13 KiB
TypeScript
Raw Normal View History

// Module ID: 12295
// Function ID: 12296
// Name: useCreatePollFormData
// Dependencies: [5, 32, 19, 7901, 7833, 12296, 11807, 12297, 12298, 12299, 1114, 11813, 2]
2026-07-20 16:05:17 +00:00
// Exports: default
// Module 12295 (useCreatePollFormData)
import util from "util" /* 1114 */;
import PollsUtils from "PollsUtils" /* 7833 */;
import PollsActionCreatorsDefault from "PollsActionCreators" /* 11807 */;
import useRequestDefault from "useRequest" /* 12296 */;
import PollUploadAttachmentActionCreatorsAll from "PollUploadAttachmentActionCreators" /* 12297 */;
import PollAttachmentUtils from "PollAttachmentUtils" /* 12298 */;
import PollTypes from "PollTypes" /* 12299 */;
import asyncGeneratorStep from "asyncGeneratorStep" /* 5 */;
import _slicedToArray from "module_32" /* 32 */;
import noop from "module_19" /* 19 */;
2026-07-23 10:11:24 +00:00
require = fn;
2026-07-20 16:05:17 +00:00
function createPollCreationImageForMedia(mediaURL, status) {
const obj = { mediaAttachmentState: { status, mediaURL }, emoji: "Array", stickerId: "isArray" };
return obj;
2026-07-20 16:05:17 +00:00
}
const PollsConstants = fn(7901);
({ MAX_NUMBER_OF_ANSWERS_PER_POLL: closure_7, MIN_NUMBER_OF_ANSWERS_PER_POLL: closure_8, PollDurations: closure_9 } = PollsConstants);
const size = fn(2);
let result = size.fileFinishedImporting("modules/polls/useCreatePollFormData.tsx");
2026-07-20 16:05:17 +00:00
export default function useCreatePollCommonData(id, arg1, arg2, initialQuestion) {
2026-08-24 06:08:38 +00:00
closure_0 = id;
importDefault = arg1;
closure_2 = arg2;
dependencyMap = initialQuestion;
2026-07-20 16:05:17 +00:00
id = id.id;
const tmp2 = answers(noop.useState(() => {
2026-07-20 16:05:17 +00:00
let mapped;
2026-07-29 08:29:29 +00:00
if (initialQuestion != null) {
2026-07-23 10:11:24 +00:00
const initialAnswers = initialQuestion.initialAnswers;
2026-07-29 08:29:29 +00:00
if (initialAnswers != null) {
mapped = initialAnswers.map((item) => {
const merged = Object.assign(closure_1_0(initialQuestion[4]).generateEmptyPollAnswer());
const merged1 = Object.assign(item);
2026-07-20 16:05:17 +00:00
return {};
});
}
}
2026-07-29 08:29:29 +00:00
if (mapped == null) {
const items = [PollsUtils.generateEmptyPollAnswer(), ];
items[1] = PollsUtils.generateEmptyPollAnswer();
2026-07-20 16:05:17 +00:00
mapped = items;
}
return mapped;
}), 2);
answers = tmp2[0];
noop = tmp2[1];
2026-07-29 08:29:29 +00:00
let str;
if (initialQuestion != null) {
str = initialQuestion.initialQuestion;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (str == null) {
str = "";
2026-07-20 16:05:17 +00:00
}
const tmpResult = answers(noop.useState(str), 2);
2026-07-29 08:29:29 +00:00
const first1 = tmpResult[0];
2026-08-24 06:08:38 +00:00
closure_8 = tmp4;
const tmpResult7 = answers(noop.useState(false), 2);
const first2 = tmpResult7[0];
2026-07-20 16:05:17 +00:00
let initialDuration;
2026-07-29 08:29:29 +00:00
if (initialQuestion != null) {
2026-07-20 16:05:17 +00:00
initialDuration = initialQuestion.initialDuration;
}
2026-07-29 08:29:29 +00:00
if (initialDuration == null) {
2026-07-20 16:05:17 +00:00
initialDuration = first2.ONE_DAY;
}
const tmpResult8 = answers(noop.useState(initialDuration), 2);
const first3 = tmpResult8[0];
const tmpResult9 = answers(noop.useState(), 2);
const first4 = tmpResult9[0];
[tmp14, closure_12] = answers(noop.useState({}), 2);
const tmpResult11 = answers(noop.useState(false), 2);
2026-08-28 06:19:39 +00:00
closure_13 = tmp16;
const found = answers.filter((item) => closure_0(initialQuestion[4]).isAnswerFilled(item));
2026-08-28 06:19:39 +00:00
let tmp17 = first1.length > 0;
const found1 = answers.filter((item) => closure_0(initialQuestion[4]).isIncompleteAnswer(item));
2026-08-28 06:19:39 +00:00
if (tmp17) {
tmp17 = found.length >= closure_8;
2026-07-20 16:05:17 +00:00
}
2026-08-28 06:19:39 +00:00
if (tmp17) {
tmp17 = 0 === found1.length;
2026-07-20 16:05:17 +00:00
}
const tmpResult10 = answers(noop.useState({}), 2);
const tmpResult12 = answers(useRequestDefault(PollsActionCreatorsDefault.createPoll), 2);
const first5 = tmpResult12[0];
2026-08-28 06:19:39 +00:00
const loading = tmp22.loading;
closure_17 = tmp23;
closure_18 = tmp24;
const callback = obj.useCallback((arg0) => {
closure_1_12((arg0) => {
2026-07-20 16:05:17 +00:00
const merged = Object.assign(arg0);
2026-07-29 08:29:29 +00:00
delete tmp[tmp2];
2026-07-20 16:05:17 +00:00
return {};
});
closure_8(arg0);
2026-07-20 16:05:17 +00:00
}, []);
2026-07-29 08:29:29 +00:00
const callback1 = obj.useCallback((arg0) => {
2026-07-20 16:05:17 +00:00
({ text: closure_0, index: closure_1, localCreationAnswerId: closure_2 } = arg0);
closure_1_12((arg0) => {
2026-07-20 16:05:17 +00:00
const merged = Object.assign(arg0);
const combined = "answer-" + closure_1_2;
2026-07-23 10:11:24 +00:00
delete tmp[tmp2];
2026-07-20 16:05:17 +00:00
return {};
});
closure_6((arg0) => {
2026-07-20 16:05:17 +00:00
const items = [...arg0];
const obj = {};
const merged = Object.assign(items[closure_1_1]);
obj.text = text;
items[closure_1_1] = obj;
2026-07-20 16:05:17 +00:00
return items;
});
}, []);
const callback2 = obj.useCallback((image, arg1) => {
2026-08-24 06:08:38 +00:00
closure_1 = arg1;
closure_6((arg0) => {
2026-07-20 16:05:17 +00:00
const items = [...arg0];
const obj = {};
const merged = Object.assign(items[closure_1]);
obj.image = image;
2026-07-23 10:11:24 +00:00
items[closure_1] = obj;
2026-07-20 16:05:17 +00:00
return items;
});
}, []);
let items = [answers];
2026-07-29 08:29:29 +00:00
const callback3 = obj.useCallback((arg0, arg1, arg2) => {
2026-07-20 16:05:17 +00:00
const image = tmp.image;
let mediaAttachmentState;
2026-07-29 08:29:29 +00:00
if (image != null) {
2026-07-20 16:05:17 +00:00
mediaAttachmentState = image.mediaAttachmentState;
}
let tmp3 = null != mediaAttachmentState;
if (tmp3) {
tmp3 = mediaAttachmentState.mediaURL !== arg2;
}
if (tmp3) {
const obj = PollUploadAttachmentActionCreatorsAll;
const result = obj.removePollUploadAttachment(arg0, tmp.localCreationAnswerId, PollAttachmentUtils.getFileNameFromGifUrl(tmp.localCreationAnswerId, mediaAttachmentState.mediaURL));
2026-07-20 16:05:17 +00:00
}
}, items);
closure_0 = id(function*(arg0, value, arg2) {
if (c6 === 2) {
c6 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
} else if (tmp5 === 3) {
if (arg0 === 1) {
throw value;
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c6 = 2;
if (0 === answers) {
if (arg0 === 1) {
2026-07-29 08:29:29 +00:00
c6 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c6 = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
closure_4 = tmp2;
closure_131_0 = closure_1;
closure_131_1 = closure_2;
callback3(closure_0, closure_1);
callback2(first3(closure_2, closure_0(tmp3[9]).PollMediaUploadAttachmentStatus.PREPARING), closure_1);
answers = 1;
c6 = 1;
const obj4 = { value: closure_2(tmp3[7]).handlePollGifAttachmentAdd(closure_0, answers[closure_1].localCreationAnswerId, closure_2), done: false };
return obj4;
}
} else if (arg0 === 1) {
c6 = 3;
throw value;
} else if (arg0 === 2) {
c6 = 3;
const obj = { value, done: true };
return obj;
} else {
if (null != value) {
callback2(first3(closure_131_1, closure_0(tmp3[9]).PollMediaUploadAttachmentStatus.READY_TO_UPLOAD), closure_131_0);
} else {
callback2(first3(closure_131_1, closure_0(tmp3[9]).PollMediaUploadAttachmentStatus.ERROR), closure_131_0);
2026-07-29 08:29:29 +00:00
}
c6 = 3;
2026-07-29 08:29:29 +00:00
}
} catch (tmp25) {
c6 = tmp;
throw tmp25;
2026-07-29 08:29:29 +00:00
}
}
2026-07-29 08:29:29 +00:00
});
const items1 = [answers, callback2, callback3];
const items2 = [answers, callback2, callback3];
2026-07-29 08:29:29 +00:00
const callback4 = obj.useCallback(function() {
const self = this;
const apply = closure_0.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}, items1);
2026-07-20 16:05:17 +00:00
const items3 = [id, callback2, callback3];
2026-07-29 08:29:29 +00:00
const callback5 = obj.useCallback((arg0, arg1, arg2) => {
2026-07-20 16:05:17 +00:00
const objectURL = URL.createObjectURL(arg2);
callback3(arg0, arg1);
const obj = { mediaAttachmentState: { status: PollTypes.PollMediaUploadAttachmentStatus.PREPARING, mediaURL: objectURL }, emoji: "Array", stickerId: "isArray" };
2026-07-29 08:29:29 +00:00
callback2(obj, arg1);
const obj2 = { status: PollTypes.PollMediaUploadAttachmentStatus.PREPARING, mediaURL: objectURL };
const result = PollUploadAttachmentActionCreatorsAll.handlePollMediaAttachmentAdd(arg0, first[arg1].localCreationAnswerId, arg2);
const obj4 = { mediaAttachmentState: null, emoji: "Array", stickerId: "isArray" };
obj4.mediaAttachmentState = { status: PollTypes.PollMediaUploadAttachmentStatus.READY_TO_UPLOAD, mediaURL: objectURL };
callback2(obj4, arg1);
2026-07-20 16:05:17 +00:00
}, items2);
const callback6 = obj.useCallback((emoji, arg1) => {
2026-07-20 16:05:17 +00:00
callback3(id, arg1);
callback2({ emoji, stickerId: "Array", mediaAttachmentState: "isArray" }, arg1);
2026-07-20 16:05:17 +00:00
}, items3);
const items4 = [answers.length < first1];
2026-07-29 08:29:29 +00:00
const callback7 = obj.useCallback((arg0) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
closure_6((arg0) => {
2026-07-20 16:05:17 +00:00
const items = [...arg0];
const obj = {};
const merged = Object.assign(items[closure_0]);
2026-07-29 08:29:29 +00:00
obj.image = undefined;
2026-07-23 10:11:24 +00:00
items[closure_0] = obj;
2026-07-20 16:05:17 +00:00
return items;
});
}, []);
const items5 = [answers.length, answers.length > closure_8, id, arg2, callback3];
2026-07-29 08:29:29 +00:00
const callback8 = obj.useCallback(() => {
2026-08-28 06:19:39 +00:00
if (closure_17) {
closure_6((arg0) => {
2026-07-20 16:05:17 +00:00
const items = [...arg0];
items[tmp] = closure_1_0(initialQuestion[4]).generateEmptyPollAnswer();
2026-07-20 16:05:17 +00:00
return items;
});
}
}, items4);
const items6 = [id];
const callback9 = obj.useCallback((indexToRemove) => {
closure_0 = indexToRemove;
2026-08-28 06:19:39 +00:00
if (closure_18) {
callback3(id, indexToRemove);
closure_6((arg0) => {
2026-07-20 16:05:17 +00:00
const items = [...arg0];
2026-07-23 10:11:24 +00:00
items.splice(closure_0, 1);
2026-07-20 16:05:17 +00:00
return items;
});
2026-07-29 08:29:29 +00:00
if (closure_2 != null) {
const obj = { indexToRemove, numberOfAnswers: first.length };
2026-07-29 08:29:29 +00:00
tmp7(obj);
2026-07-20 16:05:17 +00:00
}
}
}, items5);
2026-07-29 08:29:29 +00:00
const effect = obj.useEffect(() => () => {
const result = closure_2(closure_3[7]).removeAllPollUploadAttachments(id);
2026-07-20 16:05:17 +00:00
}, items6);
const items7 = [answers, first1];
2026-07-29 08:29:29 +00:00
const callback10 = obj.useCallback(() => {
2026-08-24 06:08:38 +00:00
c0 = true;
2026-07-23 10:11:24 +00:00
let obj = {};
2026-07-20 16:05:17 +00:00
if (0 === first1.trim().length) {
2026-07-23 10:11:24 +00:00
c0 = false;
let intl = util.intl;
obj.question = intl.string(util.t.gPX3oI);
2026-07-20 16:05:17 +00:00
}
if (first.filter((item) => c0(7833).isAnswerFilled(item)).length < React6) {
2026-07-23 10:11:24 +00:00
c0 = false;
let _HermesInternal = HermesInternal;
2026-07-29 08:29:29 +00:00
let combined = "answer-" + arr[0].localCreationAnswerId;
const intl2 = util.intl;
obj[combined] = intl2.string(util.t.fYvzEX);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const item = arr.forEach((localCreationAnswerId) => {
obj = closure_0(7833);
2026-07-20 16:05:17 +00:00
if (obj.isIncompleteAnswer(localCreationAnswerId)) {
c0 = false;
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal;
const combined = "answer-" + localCreationAnswerId.localCreationAnswerId;
const intl = tmp(1114).intl;
obj[combined] = intl.string(tmp(1114).t["8Qqkc+"]);
2026-07-20 16:05:17 +00:00
}
});
closure_1_12(obj);
closure_13(!c0);
2026-07-23 10:11:24 +00:00
return c0;
2026-07-20 16:05:17 +00:00
}, items7);
2026-08-28 06:19:39 +00:00
const items8 = [first1, found, first2, first3, first4, first5, id, arg1];
const callback11 = obj.useCallback(id(function*(arg0, value) {
if (channel === 2) {
channel = 3;
throw new TypeError("Generator functions may not be called on executing generators");
2026-07-29 08:29:29 +00:00
} else if (tmp3 === 3) {
if (arg0 === 1) {
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
channel = 2;
2026-07-29 08:29:29 +00:00
if (0 === c1) {
if (arg0 === 1) {
channel = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
channel = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
const obj4 = { channel, question: first1, answers: found, allowMultiSelect: first2, duration: first3, layout: channel(initialQuestion[11]).PollLayoutTypes.DEFAULT, onClose, scheduledTimestamp: first4 };
2026-07-29 08:29:29 +00:00
c1 = 1;
channel = 1;
const obj5 = { value: first5(obj4), done: false };
return obj5;
2026-07-29 08:29:29 +00:00
}
} else if (arg0 === 1) {
channel = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
channel = 3;
const obj = { value, done: true };
2026-07-29 08:29:29 +00:00
return obj;
} else {
channel = 3;
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} catch (tmp5) {
channel = tmp;
2026-07-29 08:29:29 +00:00
throw tmp5;
}
}
}), items8);
2026-07-20 16:05:17 +00:00
const items9 = [callback11, loading, callback10];
return {
answers,
2026-07-20 16:05:17 +00:00
question: first1,
setQuestion: tmpResult[1],
2026-07-20 16:05:17 +00:00
allowMultiSelect: first2,
setAllowMultiSelect: tmpResult7[1],
2026-07-20 16:05:17 +00:00
duration: first3,
setDuration: tmpResult8[1],
2026-08-28 06:19:39 +00:00
scheduledTimestamp: first4,
setScheduledTimestamp: tmpResult9[1],
2026-08-28 06:19:39 +00:00
canPost: tmp17,
canAddMoreAnswers: answers.length < first1,
canRemoveMoreAnswers: answers.length > closure_8,
2026-07-20 16:05:17 +00:00
handleQuestionChange: callback,
handleAnswerTextChange: callback1,
handleGifSelect: callback4,
handleEmojiSelect: callback6,
handleCustomUpload: callback5,
handleAddAnswer: callback8,
handleRemoveAnswer: callback9,
handleRemoveAnswerImage: callback7,
2026-08-28 06:19:39 +00:00
fieldErrors: tmp14,
2026-07-20 16:05:17 +00:00
createPoll: callback11,
handleSubmitPoll: noop.useCallback(() => {
2026-07-20 16:05:17 +00:00
let tmp = !loading;
2026-07-29 08:29:29 +00:00
if (!loading) {
2026-07-20 16:05:17 +00:00
tmp = callback10();
}
if (tmp) {
callback11();
}
}, items9),
submitting: loading,
createPollError: tmpResult12[1].error,
shouldFocusOnInvalidField: tmpResult11[0],
setShouldFocusOnInvalidField: tmpResult11[1]
2026-07-20 16:05:17 +00:00
};
};