From 2b677d95008fc9a65dfc521f2018d891512df3a3 Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Mon, 14 Oct 2024 13:45:14 -0400 Subject: [PATCH 1/2] Change category --- .../components/videoManager/VideoManager.tsx | 179 +++++++++++++----- rair-node/bin/api/files/files.Service.js | 12 ++ rair-node/bin/api/users/users.Controller.js | 2 +- rair-node/bin/api/users/users.Service.js | 1 + 4 files changed, 146 insertions(+), 48 deletions(-) diff --git a/rair-front/src/components/videoManager/VideoManager.tsx b/rair-front/src/components/videoManager/VideoManager.tsx index 80e376fff..2dba0e59b 100644 --- a/rair-front/src/components/videoManager/VideoManager.tsx +++ b/rair-front/src/components/videoManager/VideoManager.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from 'react'; import { Provider, useStore } from 'react-redux'; import { faTrash } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { formatEther } from 'ethers'; import OfferSelector from './OfferSelector'; @@ -9,26 +10,48 @@ import { useAppSelector } from '../../hooks/useReduxHooks'; import useServerSettings from '../../hooks/useServerSettings'; import useSwal from '../../hooks/useSwal'; import { rFetch } from '../../utils/rFetch'; +import { OptionsType } from '../common/commonTypes/InputSelectTypes.types'; import InputField from '../common/InputField'; +import InputSelect from '../common/InputSelect'; import AnalyticsPopUp from '../DemoMediaUpload/UploadedListBox/AnalyticsPopUp/AnalyticsPopUp'; -import { formatEther } from 'ethers'; const VideoManager = () => { const [uploads, setUploads] = useState([]); const [unlockData, setUnlockData] = useState([]); const [refresh, setRefresh] = useState(false); const [hiddenFlag, setHiddenFlag] = useState(false); + const [categoryOptions, setCategoryOptions] = useState>( + [] + ); const [filter, setFilter] = useState(''); const [selectedFile, setSelectedFile] = useState({}); const { currentUserAddress } = useAppSelector((store) => store.web3); - const { textColor, primaryButtonColor, secondaryButtonColor } = + const { primaryColor, textColor, primaryButtonColor, secondaryButtonColor } = useAppSelector((store) => store.colors); const { getBlockchainData } = useServerSettings(); const reactSwal = useSwal(); + const loadCategories = useCallback(async () => { + const { success, result } = await rFetch('/api/categories'); + if (success) { + setCategoryOptions( + result.map((item) => { + return { + label: item.name, + value: item._id + }; + }) + ); + } + }, []); + + useEffect(() => { + loadCategories(); + }, [loadCategories]); + useEffect(() => { setUnlockData([]); if (!selectedFile._id) { @@ -120,6 +143,15 @@ const VideoManager = () => { }); }, [selectedFile, refreshFileList, reactSwal]); + const updateCategory = useCallback( + async (categoryId) => { + await updateFile({ + category: categoryId + }); + }, + [updateFile] + ); + const updateDemoStatus = useCallback(async () => { await updateFile({ demo: !selectedFile.demo @@ -219,53 +251,106 @@ const VideoManager = () => { } /> -
- {selectedFile.type} -

{selectedFile.title}

-
- -
- {selectedFile?.category?.name} -
- - - -
- {selectedFile.duration} -
- {selectedFile.description} -
-
+
+ + + {[ + { + label: 'Type', + value: selectedFile.type + }, + { + label: 'Title', + value: selectedFile.title + }, + { + label: 'Category', + value: ( + + ) + }, + { + label: 'Views', + value: + }, + { + label: 'Unlockable', + value: ( + + ) + }, + { + label: 'Age Restriction', + value: ( + + ) + }, + { + label: 'Visibility', + value: ( + + ) + }, + { + label: 'Duration', + value: selectedFile.duration + }, + { + label: 'Description', + value: selectedFile.description + } + ].map((item, index) => { + return ( + + + + + ); + })} + +
{item.label}{item.value}
diff --git a/rair-node/bin/api/files/files.Service.js b/rair-node/bin/api/files/files.Service.js index db860e326..f1e13720d 100644 --- a/rair-node/bin/api/files/files.Service.js +++ b/rair-node/bin/api/files/files.Service.js @@ -115,6 +115,18 @@ module.exports = { }, { $match: matchData, + }, { + $lookup: { + from: 'Category', + localField: 'category', + foreignField: '_id', + as: 'category', + }, + }, { + $unwind: { + path: '$category', + preserveNullAndEmptyArrays: true, + }, }, { $project: { diff --git a/rair-node/bin/api/users/users.Controller.js b/rair-node/bin/api/users/users.Controller.js index 5ff4359d4..8aab57134 100644 --- a/rair-node/bin/api/users/users.Controller.js +++ b/rair-node/bin/api/users/users.Controller.js @@ -49,4 +49,4 @@ router updateUserByUserAddress, ); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/rair-node/bin/api/users/users.Service.js b/rair-node/bin/api/users/users.Service.js index d66d0822c..4f46673eb 100644 --- a/rair-node/bin/api/users/users.Service.js +++ b/rair-node/bin/api/users/users.Service.js @@ -140,6 +140,7 @@ exports.createUser = async (req, res, next) => { next(e); } }; + exports.getUserByAddress = async (req, res, next) => { try { const publicAddress = req.params.publicAddress.toLowerCase(); From dadeb78c84ef8be1b1e937c97ae8ea0df65debd8 Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Tue, 15 Oct 2024 00:26:38 -0400 Subject: [PATCH 2/2] Fix demo page --- .../MediaItemChange/MediaItemChange.tsx | 21 +++++-------------- .../PopUpChangeVideo/PopUpChangeVideo.tsx | 18 +++++++--------- .../UploadedListBox/UploadedListBox.tsx | 4 +++- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/rair-front/src/components/DemoMediaUpload/MediaItemChange/MediaItemChange.tsx b/rair-front/src/components/DemoMediaUpload/MediaItemChange/MediaItemChange.tsx index cb172ca1d..7361db549 100644 --- a/rair-front/src/components/DemoMediaUpload/MediaItemChange/MediaItemChange.tsx +++ b/rair-front/src/components/DemoMediaUpload/MediaItemChange/MediaItemChange.tsx @@ -41,7 +41,8 @@ const MediaItemChange: React.FC = ({ const closeModal = useCallback(() => { setModalIsOpen(false); - }, [setModalIsOpen]); + getMediaList(); + }, [setModalIsOpen, getMediaList]); const [titleValue, setTitleValue] = useState(item.title); const [disabledBtn, setDisabledBtn] = useState(false); @@ -104,25 +105,13 @@ const MediaItemChange: React.FC = ({ className="media-item-title"> {textFlag ? (
-

- {item.title.length > 15 - ? item.title.slice(0, 6) + - '...' + - item.title.slice(item.title.length - 10, 10) - : item.title} -

+

{item.title}

) : (
{!editTitleVideo ? ( <> -

- {item.title.length > 15 - ? item.title.slice(0, 6) + - '...' + - item.title.slice(item.title.length - 10, 10) - : item.title} -

+

{item.title}

{newUserStatus ? ( diff --git a/rair-front/src/components/DemoMediaUpload/PopUpChangeVideo/PopUpChangeVideo.tsx b/rair-front/src/components/DemoMediaUpload/PopUpChangeVideo/PopUpChangeVideo.tsx index 32d26655b..8bb1b36c7 100644 --- a/rair-front/src/components/DemoMediaUpload/PopUpChangeVideo/PopUpChangeVideo.tsx +++ b/rair-front/src/components/DemoMediaUpload/PopUpChangeVideo/PopUpChangeVideo.tsx @@ -33,7 +33,7 @@ const PopUpChangeVideo: React.FC = ({ const [categoryList, setCategoryList] = useState( undefined ); - const [itemCategory, setItemCategory] = useState(item.category); + const [itemCategory, setItemCategory] = useState(item.category._id); const getCategory = useCallback(async () => { if (categories) { @@ -42,7 +42,7 @@ const PopUpChangeVideo: React.FC = ({ return { id: item._id, label: item.name, - value: item.name, + value: item._id, disabled: false }; }) @@ -69,16 +69,12 @@ const PopUpChangeVideo: React.FC = ({ setMediaList(newMediaList); closeModal(); } else { - const choiceCategory: any = - categoryList && - categoryList.find((item: any) => item.value === itemCategory); - setUploadSuccess(true); const updatedVideo = { description: desc, title: title, - category: choiceCategory.id + category: itemCategory }; try { const request = await rFetch(`/api/files/update/${item._id}`, { @@ -99,14 +95,14 @@ const PopUpChangeVideo: React.FC = ({ closeModal(); setDesc(item.description); setTitle(item.title); - setItemCategory(item.category); + setItemCategory(item.category._id); setUploadSuccess(null); } } catch (e) { closeModal(); setDesc(item.description); setTitle(item.title); - setItemCategory(item.category); + setItemCategory(item.category._id); setUploadSuccess(null); } } @@ -173,7 +169,7 @@ const PopUpChangeVideo: React.FC = ({ if (defaultCategory) { setItemCategory(defaultCategory.value); } else { - setItemCategory(item.category); + setItemCategory(item.category._id); } } } @@ -213,7 +209,7 @@ const PopUpChangeVideo: React.FC = ({ {...selectCommonInfoNFT} />