Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change category on Video Manger #258

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const MediaItemChange: React.FC<IMediaItemChange> = ({

const closeModal = useCallback(() => {
setModalIsOpen(false);
}, [setModalIsOpen]);
getMediaList();
}, [setModalIsOpen, getMediaList]);

const [titleValue, setTitleValue] = useState<string>(item.title);
const [disabledBtn, setDisabledBtn] = useState<boolean>(false);
Expand Down Expand Up @@ -104,25 +105,13 @@ const MediaItemChange: React.FC<IMediaItemChange> = ({
className="media-item-title">
{textFlag ? (
<div>
<p className="col-12">
{item.title.length > 15
? item.title.slice(0, 6) +
'...' +
item.title.slice(item.title.length - 10, 10)
: item.title}
</p>
<p className="col-12">{item.title}</p>
</div>
) : (
<div>
{!editTitleVideo ? (
<>
<p className="col-12">
{item.title.length > 15
? item.title.slice(0, 6) +
'...' +
item.title.slice(item.title.length - 10, 10)
: item.title}
</p>
<p className="col-12">{item.title}</p>
{newUserStatus ? (
<button
disabled={!newUserStatus}
Expand All @@ -143,7 +132,7 @@ const MediaItemChange: React.FC<IMediaItemChange> = ({
onClick={() => {
openModal();
}}>
<FontAwesomeIcon icon={faPencilAlt} />
<FontAwesomeIcon icon={faPencilAlt} /> Edit
</button>
</span>
</TooltipBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
const [categoryList, setCategoryList] = useState<OptionsType[] | undefined>(
undefined
);
const [itemCategory, setItemCategory] = useState(item.category);
const [itemCategory, setItemCategory] = useState(item.category._id);

const getCategory = useCallback(async () => {
if (categories) {
Expand All @@ -42,7 +42,7 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
return {
id: item._id,
label: item.name,
value: item.name,
value: item._id,
disabled: false
};
})
Expand All @@ -69,16 +69,12 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
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}`, {
Expand All @@ -99,14 +95,14 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
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);
}
}
Expand Down Expand Up @@ -173,7 +169,7 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
if (defaultCategory) {
setItemCategory(defaultCategory.value);
} else {
setItemCategory(item.category);
setItemCategory(item.category._id);
}
}
}
Expand Down Expand Up @@ -213,7 +209,7 @@ const PopUpChangeVideo: React.FC<IPopUpChangeVideo> = ({
{...selectCommonInfoNFT}
/>
<button
onClick={() => updateVideoData()}
onClick={updateVideoData}
disabled={title === '' || desc === '' || itemCategory === ''}
style={{
marginTop: 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ const UploadedListBox: React.FC<IUploadedListBox> = ({
className="medialist-box"
key={index}
style={{
backgroundColor: isDarkMode ? `color-mix(in srgb, ${primaryColor}, #888888)` : 'var(--rhyno)',
backgroundColor: isDarkMode
? `color-mix(in srgb, ${primaryColor}, #888888)`
: 'var(--rhyno)',
color: textColor,
borderRadius: '15px',
marginTop: '20px'
Expand Down
179 changes: 132 additions & 47 deletions rair-front/src/components/videoManager/VideoManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,56 @@ 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';

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<any[]>([]);
const [unlockData, setUnlockData] = useState([]);
const [refresh, setRefresh] = useState(false);
const [hiddenFlag, setHiddenFlag] = useState(false);
const [categoryOptions, setCategoryOptions] = useState<Array<OptionsType>>(
[]
);

const [filter, setFilter] = useState('');
const [selectedFile, setSelectedFile] = useState<any>({});
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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,53 +251,106 @@ const VideoManager = () => {
}
/>
</div>
<div className="col-8 py-5">
<small>{selectedFile.type}</small>
<h3>{selectedFile.title}</h3>
<h5>
<AnalyticsPopUp videoId={selectedFile._id} />
</h5>
<span>{selectedFile?.category?.name}</span>
<br />
<button
onClick={updateDemoStatus}
style={{
background: secondaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.demo ? 'Demo' : 'Unlockable'}
</button>
<button
onClick={updateAgeRestriction}
style={{
background: primaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.ageRestricted
? 'Age Restricted'
: 'NOT Age Restricted'}
</button>
<button
onClick={updateHiddenStatus}
style={{
background: secondaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.hidden ? 'Hidden' : 'Visible'}
</button>
<br />
<small>{selectedFile.duration}</small>
<br />
<span>{selectedFile.description}</span>
<br />
<br />
<div className="col-8 pb-5">
<table
style={{ backgroundColor: primaryColor }}
className="table-responsive">
<tbody>
{[
{
label: 'Type',
value: selectedFile.type
},
{
label: 'Title',
value: selectedFile.title
},
{
label: 'Category',
value: (
<InputSelect
options={categoryOptions}
placeholder="Please select"
getter={selectedFile.category?._id || 'null'}
setter={updateCategory}
customClass="form-control rounded-rair"
customCSS={{
backgroundColor: primaryColor,
color: textColor
}}
/>
)
},
{
label: 'Views',
value: <AnalyticsPopUp videoId={selectedFile._id} />
},
{
label: 'Unlockable',
value: (
<button
onClick={updateDemoStatus}
style={{
background: secondaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.demo ? 'Demo' : 'Unlockable'}
</button>
)
},
{
label: 'Age Restriction',
value: (
<button
onClick={updateAgeRestriction}
style={{
background: primaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.ageRestricted
? 'Age Restricted'
: 'NOT Age Restricted'}
</button>
)
},
{
label: 'Visibility',
value: (
<button
onClick={updateHiddenStatus}
style={{
background: secondaryButtonColor,
color: textColor
}}
className="btn rair-button">
{selectedFile.hidden ? 'Hidden' : 'Visible'}
</button>
)
},
{
label: 'Duration',
value: selectedFile.duration
},
{
label: 'Description',
value: selectedFile.description
}
].map((item, index) => {
return (
<tr key={index}>
<th>{item.label}</th>
<th>{item.value}</th>
</tr>
);
})}
</tbody>
</table>
<button
onClick={deleteFile}
className="btn btn-outline-danger">
<FontAwesomeIcon icon={faTrash} /> Delete
className="btn float-end btn-outline-danger">
<FontAwesomeIcon icon={faTrash} /> Delete Media File
</button>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions rair-node/bin/api/files/files.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ module.exports = {
},
{
$match: matchData,
}, {
$lookup: {
from: 'Category',
localField: 'category',
foreignField: '_id',
as: 'category',
},
}, {
$unwind: {
path: '$category',
preserveNullAndEmptyArrays: true,
},
},
{
$project: {
Expand Down
2 changes: 1 addition & 1 deletion rair-node/bin/api/users/users.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ router
updateUserByUserAddress,
);

module.exports = router;
module.exports = router;
1 change: 1 addition & 0 deletions rair-node/bin/api/users/users.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down