decord/source/modules/interaction_components/useFileUploadComponentState.tsx

55 lines
2.3 KiB
TypeScript
Raw Normal View History

// Module ID: 17510
// Function ID: 17511
2026-07-20 16:05:17 +00:00
// Name: useFileUploadComponentState
// Dependencies: [19, 4977, 4976, 8229, 38, 1894, 2]
2026-07-20 16:05:17 +00:00
// Exports: useFileUploadComponentState
// Module 17510 (useFileUploadComponentState)
import Server from "Server" /* 1894 */;
import noop from "module_19" /* 19 */;
import UploadAttachmentStore from "UploadAttachmentStore" /* 4976 */;
2026-07-23 10:11:24 +00:00
require = fn;
const DraftType = fn(4977).DraftType;
const size = fn(2);
const result = size.fileFinishedImporting("modules/interaction_components/useFileUploadComponentState.tsx");
2026-07-20 16:05:17 +00:00
export const useFileUploadComponentState = function useFileUploadComponentState(maxValues) {
2026-07-23 10:11:24 +00:00
const componentStateContext = state(uploadIds[3]).useComponentStateContext();
executeStateUpdate(uploadIds[4])(null != componentStateContext, "useFileUploadComponentState must be used within a ComponentStateContextProvider");
2026-07-20 16:05:17 +00:00
const channelId = componentStateContext.channelId;
2026-07-23 10:11:24 +00:00
executeStateUpdate(uploadIds[4])(null != channelId, "useFileUploadComponentState must be used inside a channel");
const error = componentStateContext.useComponentState(maxValues);
2026-07-23 10:11:24 +00:00
state = error.state;
executeStateUpdate = error.executeStateUpdate;
2026-07-20 16:05:17 +00:00
const items = [state];
2026-07-23 10:11:24 +00:00
uploadIds = uploads.useMemo(() => {
2026-07-20 16:05:17 +00:00
let type;
2026-07-29 08:29:29 +00:00
if (state != null) {
type = tmp.type;
2026-07-20 16:05:17 +00:00
}
return type === Server.ComponentType.FILE_UPLOAD ? state.uploadIds : [];
2026-07-20 16:05:17 +00:00
}, items);
2026-07-23 10:11:24 +00:00
uploads = setUploadIds.getUploads(channelId, currentUploads.InteractionModal);
2026-07-20 16:05:17 +00:00
const items1 = [uploadIds, uploads];
2026-07-23 10:11:24 +00:00
currentUploads = uploads.useMemo(() => {
const mapped = uploadIds.map((item) => {
closure_0 = item;
return uploads.find((id) => id.id === closure_0);
2026-07-23 10:11:24 +00:00
});
return mapped.filter((item) => null != item);
2026-07-20 16:05:17 +00:00
}, items1);
const items2 = [executeStateUpdate];
setUploadIds = uploads.useCallback((uploadIds) => executeStateUpdate({ type: Server.ComponentType.FILE_UPLOAD, uploadIds }), items2);
2026-07-20 16:05:17 +00:00
const items3 = [uploadIds, currentUploads, setUploadIds];
2026-07-23 10:11:24 +00:00
const effect = uploads.useEffect(() => {
2026-07-20 16:05:17 +00:00
if (uploadIds.length > currentUploads.length) {
setUploadIds(uploadIds.filter((item) => {
closure_0 = item;
return currentUploads.some((id) => id.id === closure_0);
2026-07-23 10:11:24 +00:00
}));
2026-07-20 16:05:17 +00:00
}
}, items3);
return { uploadIds, setUploadIds, currentUploads, error: error.error };
};