${editVideoProperties?.fullDescription}
` + if (editFileProperties) { + setTitle(editFileProperties?.title || ""); + setFiles(editFileProperties?.files || []); + if (editFileProperties?.htmlDescription) { + setDescription(editFileProperties?.htmlDescription); + } else if (editFileProperties?.fullDescription) { + const paragraph = `${editFileProperties?.fullDescription}
`; setDescription(paragraph); - } - - if (editVideoProperties?.category) { - const selectedOption = categories.find( - (option) => option.id === +editVideoProperties.category - ); - setSelectedCategoryVideos(selectedOption || null); - } - if ( - editVideoProperties?.category && - editVideoProperties?.subcategory && - subCategories[+editVideoProperties?.category] - ) { - const selectedOption = subCategories[ - +editVideoProperties?.category - ]?.find((option) => option.id === +editVideoProperties.subcategory); - setSelectedSubCategoryVideos(selectedOption || null); - } - if ( - editVideoProperties?.category && - editVideoProperties?.subcategory2 && - subCategories2[+editVideoProperties?.subcategory] - ) { - const selectedOption = subCategories2[ - +editVideoProperties?.subcategory - ]?.find((option) => option.id === +editVideoProperties.subcategory2); - setSelectedSubCategoryVideos2(selectedOption || null); - } - if ( - editVideoProperties?.category && - editVideoProperties?.subcategory3 && - subCategories3[+editVideoProperties?.subcategory2] - ) { - - const selectedOption = subCategories3[ - +editVideoProperties?.subcategory2 - ]?.find((option) => option.id === +editVideoProperties.subcategory3); - setSelectedSubCategoryVideos3(selectedOption || null); - } - - + setEditCategories(getCategoriesFromObject(editFileProperties)); } - }, [editVideoProperties]); - + }, [editFileProperties]); const onClose = () => { - dispatch(setEditVideo(null)); + dispatch(setEditFile(null)); setVideoPropertiesToSetToRedux(null); setFile(null); setTitle(""); @@ -232,12 +135,13 @@ export const EditFile = () => { async function publishQDNResource() { try { + const categoryList = categoryListRef.current?.getSelectedCategories(); if (!title) throw new Error("Please enter a title"); if (!description) throw new Error("Please enter a description"); - if (!selectedCategoryVideos) throw new Error("Please select a category"); - if (!editVideoProperties) return; + if (!categoryList[0]) throw new Error("Please select a category"); + if (!editFileProperties) return; if (!userAddress) throw new Error("Unable to locate user address"); - if(files.length === 0) throw new Error("Add at least one file"); + if (files.length === 0) throw new Error("Add at least one file"); let errorMsg = ""; let name = ""; @@ -249,7 +153,7 @@ export const EditFile = () => { "Cannot publish without access to your name. Please authenticate."; } - if (editVideoProperties?.user !== username) { + if (editFileProperties?.user !== username) { errorMsg = "Cannot publish another user's resource"; } @@ -262,44 +166,37 @@ export const EditFile = () => { ); return; } - let fileReferences = [] + let fileReferences = []; let listOfPublishes = []; const fullDescription = extractTextFromHTML(description); - const category = selectedCategoryVideos.id; - const subcategory = selectedSubCategoryVideos?.id || ""; - const subcategory2 = selectedSubCategoryVideos2?.id || ""; - const subcategory3 = selectedSubCategoryVideos3?.id || ""; const sanitizeTitle = title - .replace(/[^a-zA-Z0-9\s-]/g, "") - .replace(/\s+/g, "-") - .replace(/-+/g, "-") - .trim() - .toLowerCase(); - + .replace(/[^a-zA-Z0-9\s-]/g, "") + .replace(/\s+/g, "-") + .replace(/-+/g, "-") + .trim() + .toLowerCase(); for (const publish of files) { - if(publish?.identifier){ - fileReferences.push(publish) - continue + if (publish?.identifier) { + fileReferences.push(publish); + continue; } const file = publish.file; const id = uid(); const identifier = `${QSHARE_FILE_BASE}${sanitizeTitle.slice(0, 30)}_${id}`; - - let fileExtension = ""; const fileExtensionSplit = file?.name?.split("."); if (fileExtensionSplit?.length > 1) { fileExtension = fileExtensionSplit?.pop() || ""; } - let firstPartName = fileExtensionSplit[0] + let firstPartName = fileExtensionSplit[0]; let filename = firstPartName.slice(0, 15); - + // Step 1: Replace all white spaces with underscores // Replace all forms of whitespace (including non-standard ones) with underscores @@ -311,18 +208,16 @@ export const EditFile = () => { "" ); - if(fileExtension){ - filename = `${alphanumericString.trim()}.${fileExtension}` + if (fileExtension) { + filename = `${alphanumericString.trim()}.${fileExtension}`; } else { - filename = alphanumericString + filename = alphanumericString; } - - let metadescription = - `**cat:${category};sub:${subcategory};sub2:${subcategory2};sub3:${subcategory3}**` + + `**${categoryListRef.current?.getCategoriesFetchString()}**` + fullDescription.slice(0, 150); - + const requestBodyVideo: any = { action: "PUBLISH_QDN_RESOURCE", name: name, @@ -339,27 +234,24 @@ export const EditFile = () => { filename: file.name, identifier, name, - service: 'FILE', + service: "FILE", mimetype: file.type, - size: file.size - }) + size: file.size, + }); } const fileObject: any = { title, - version: editVideoProperties.version, + version: editFileProperties.version, fullDescription, htmlDescription: description, - commentsId: editVideoProperties.commentsId, - category, - subcategory, - subcategory2, - subcategory3, - files: fileReferences + commentsId: editFileProperties.commentsId, + ...categoryListRef.current?.categoriesToObject(), + files: fileReferences, }; let metadescription = - `**cat:${category};sub:${subcategory};sub2:${subcategory2}**` + + `**${categoryListRef.current?.getCategoriesFetchString()}**` + fullDescription.slice(0, 150); const crowdfundObjectToBase64 = await objectToBase64(fileObject); @@ -372,7 +264,7 @@ export const EditFile = () => { data64: crowdfundObjectToBase64, title: title.slice(0, 50), description: metadescription, - identifier: editVideoProperties.id, + identifier: editFileProperties.id, tag1: QSHARE_FILE_BASE, filename: `video_metadata.json`, }; @@ -385,7 +277,7 @@ export const EditFile = () => { setPublishes(multiplePublish); setIsOpenMultiplePublish(true); setVideoPropertiesToSetToRedux({ - ...editVideoProperties, + ...editFileProperties, ...fileObject, }); } catch (error: any) { @@ -429,52 +321,10 @@ export const EditFile = () => { // }); }; - const handleOptionCategoryChangeVideos = ( - event: SelectChangeEvent${editVideoProperties?.description}
` + } else if (editVideoProperties?.description) { + const paragraph = `${editVideoProperties?.description}
`; setDescription(paragraph); - } setCoverImage(editVideoProperties?.image || ""); setVideos(editVideoProperties?.videos || []); if (editVideoProperties?.category) { - const selectedOption = categories.find( - (option) => option.id === +editVideoProperties.category + const selectedOption = firstCategories.find( + option => option.id === +editVideoProperties.category ); setSelectedCategoryVideos(selectedOption || null); } @@ -197,11 +201,11 @@ export const EditPlaylist = () => { if ( editVideoProperties?.category && editVideoProperties?.subcategory && - subCategories[+editVideoProperties?.category] + secondCategories[+editVideoProperties?.category] ) { - const selectedOption = subCategories[ + const selectedOption = secondCategories[ +editVideoProperties?.category - ]?.find((option) => option.id === +editVideoProperties.subcategory); + ]?.find(option => option.id === +editVideoProperties.subcategory); setSelectedSubCategoryVideos(selectedOption || null); } @@ -212,24 +216,22 @@ export const EditPlaylist = () => { }, [editVideoProperties]); const onClose = () => { - setTitle("") - setDescription("") - setVideos([]) - setPlaylistData(null) - setSelectedCategoryVideos(null) - setSelectedSubCategoryVideos(null) - setCoverImage("") + setTitle(""); + setDescription(""); + setVideos([]); + setPlaylistData(null); + setSelectedCategoryVideos(null); + setSelectedSubCategoryVideos(null); + setCoverImage(""); dispatch(setEditPlaylist(null)); - }; async function publishQDNResource() { try { - - if(!title) throw new Error('Please enter a title') - if(!description) throw new Error('Please enter a description') - if(!coverImage) throw new Error('Please select cover image') - if(!selectedCategoryVideos) throw new Error('Please select a category') + if (!title) throw new Error("Please enter a title"); + if (!description) throw new Error("Please enter a description"); + if (!coverImage) throw new Error("Please select cover image"); + if (!selectedCategoryVideos) throw new Error("Please select a category"); if (!editVideoProperties) return; if (!userAddress) throw new Error("Unable to locate user address"); @@ -259,7 +261,7 @@ export const EditPlaylist = () => { const category = selectedCategoryVideos.id; const subcategory = selectedSubCategoryVideos?.id || ""; - const videoStructured = playlistData.videos.map((item) => { + const videoStructured = playlistData.videos.map(item => { const descriptionVid = item?.metadata?.description; if (!descriptionVid) throw new Error("cannot find video code"); @@ -287,13 +289,12 @@ export const EditPlaylist = () => { }); const id = uid(); - let commentsId = editVideoProperties?.id - - if(isNew){ - commentsId = `${QSHARE_PLAYLIST_BASE}_cm_${id}` - } - const stringDescription = extractTextFromHTML(description) + let commentsId = editVideoProperties?.id; + if (isNew) { + commentsId = `${QSHARE_PLAYLIST_BASE}_cm_${id}`; + } + const stringDescription = extractTextFromHTML(description); const playlistObject: any = { title, @@ -304,10 +305,10 @@ export const EditPlaylist = () => { videos: videoStructured, commentsId: commentsId, category, - subcategory + subcategory, }; - const codes = videoStructured.map((item) => `c:${item.code};`).join(""); + const codes = videoStructured.map(item => `c:${item.code};`).join(""); let metadescription = `**category:${category};subcategory:${subcategory};${codes}**` + stringDescription.slice(0, 120); @@ -315,14 +316,14 @@ export const EditPlaylist = () => { const crowdfundObjectToBase64 = await objectToBase64(playlistObject); // Description is obtained from raw data - let identifier = editVideoProperties?.id + let identifier = editVideoProperties?.id; const sanitizeTitle = title .replace(/[^a-zA-Z0-9\s-]/g, "") .replace(/\s+/g, "-") .replace(/-+/g, "-") .trim() .toLowerCase(); - if(isNew){ + if (isNew) { identifier = `${QSHARE_PLAYLIST_BASE}${sanitizeTitle.slice(0, 30)}_${id}`; } const requestBodyJson: any = { @@ -337,24 +338,20 @@ export const EditPlaylist = () => { }; await qortalRequest(requestBodyJson); - if(isNew){ + if (isNew) { const objectToStore = { title: title.slice(0, 50), description: metadescription, id: identifier, service: "PLAYLIST", name: username, - ...playlistObject - } - dispatch( - updateVideo(objectToStore) - ); - dispatch( - updateInHashMap(objectToStore) - ); + ...playlistObject, + }; + dispatch(updateFile(objectToStore)); + dispatch(updateInHashMap(objectToStore)); } else { dispatch( - updateVideo({ + updateFile({ ...editVideoProperties, ...playlistObject, }) @@ -366,8 +363,6 @@ export const EditPlaylist = () => { }) ); } - - onClose(); } catch (error: any) { @@ -415,7 +410,9 @@ export const EditPlaylist = () => { event: SelectChangeEvent