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

Create filter for age ratings, will also enable filtering out NSFW content by default #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
51 changes: 47 additions & 4 deletions src/components/Publish/EditPlaylist/EditPlaylist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
} from "../../../state/features/videoSlice.ts";
import ImageUploader from "../../common/ImageUploader.tsx";
import { categories, subCategories } from "../../../constants/Categories.ts";
import { ratings } from "../../../constants/Ratings.ts";
import { Playlists } from "../../Playlists/Playlists.tsx";
import { PlaylistListEdit } from "../PlaylistListEdit/PlaylistListEdit.tsx";
import { TextEditor } from "../../common/TextEditor/TextEditor.tsx";
Expand Down Expand Up @@ -90,6 +91,8 @@ export const EditPlaylist = () => {
useState<any>(null);
const [selectedSubCategoryVideos, setSelectedSubCategoryVideos] =
useState<any>(null);
const [selectedRatingVideos, setSelectedRatingVideos] =
useState<any>(null);

const isNew = useMemo(() => {
return editVideoProperties?.mode === "new";
Expand Down Expand Up @@ -121,8 +124,8 @@ export const EditPlaylist = () => {
// // Split the extracted string into key-value pairs
// const keyValuePairs = extractedString.split(";");

// // Initialize variables to hold the category and subcategory values
// let category, subcategory;
// // Initialize variables to hold the category, subcategory, and rating values
// let category, subcategory, rating;

// // Loop through each key-value pair
// keyValuePairs.forEach((pair) => {
Expand All @@ -133,6 +136,8 @@ export const EditPlaylist = () => {
// category = value;
// } else if (key === "subcategory") {
// subcategory = value;
// } else if (key === "rating") {
// rating = value;
// }
// });

Expand All @@ -146,6 +151,11 @@ export const EditPlaylist = () => {
// setSelectedCategoryVideos(selectedOption || null);
// }

// if(rating){
// const selectedOption = ratings.find((option) => option.id === +rating);
// setSelectedRatingVideos(selectedOption || null);
// }

// }
// }, [editVideoProperties]);

Expand Down Expand Up @@ -206,6 +216,13 @@ export const EditPlaylist = () => {
setSelectedSubCategoryVideos(selectedOption || null);
}

if (editVideoProperties?.rating) {
const selectedOption = ratings.find(
option => option.id === +editVideoProperties.rating
);
setSelectedRatingVideos(selectedOption || null);
}

if (editVideoProperties?.videos) {
checkforPlaylist(editVideoProperties?.videos);
}
Expand All @@ -219,6 +236,7 @@ export const EditPlaylist = () => {
setPlaylistData(null);
setSelectedCategoryVideos(null);
setSelectedSubCategoryVideos(null);
setSelectedRatingVideos(null);
setCoverImage("");
dispatch(setEditPlaylist(null));
};
Expand All @@ -229,6 +247,7 @@ export const EditPlaylist = () => {
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 (!selectedRatingVideos) throw new Error("Please select a rating");

if (!editVideoProperties) return;
if (!userAddress) throw new Error("Unable to locate user address");
Expand Down Expand Up @@ -257,6 +276,7 @@ export const EditPlaylist = () => {
}
const category = selectedCategoryVideos.id;
const subcategory = selectedSubCategoryVideos?.id || "";
const rating = selectedRatingVideos.id;

const videoStructured = playlistData.videos.map(item => {
const descriptionVid = item?.metadata?.description;
Expand Down Expand Up @@ -303,15 +323,16 @@ export const EditPlaylist = () => {
commentsId: commentsId,
category,
subcategory,
rating,
};

const codes = videoStructured
.map(item => `c:${item.code};`)
.slice(0, 10)
.join("");
let metadescription =
`**category:${category};subcategory:${subcategory};${codes}**` +
stringDescription.slice(0, 120);
`**category:${category};subcategory:${subcategory};rating:${rating};${codes}**` +
stringDescription.slice(0, 110);

const crowdfundObjectToBase64 = await objectToBase64(playlistObject);
// Description is obtained from raw data
Expand Down Expand Up @@ -417,6 +438,13 @@ export const EditPlaylist = () => {
);
setSelectedSubCategoryVideos(selectedOption || null);
};
const handleOptionRatingChangeVideos = (
event: SelectChangeEvent<string>
) => {
const optionId = event.target.value;
const selectedOption = ratings.find(option => option.id === +optionId);
setSelectedRatingVideos(selectedOption || null);
};

const removeVideo = index => {
const copyData = structuredClone(playlistData);
Expand Down Expand Up @@ -497,6 +525,21 @@ export const EditPlaylist = () => {
</Select>
</FormControl>
)}
<FormControl fullWidth sx={{ marginBottom: 2 }}>
<InputLabel id="Rating">Select a Rating</InputLabel>
<Select
labelId="Rating"
input={<OutlinedInput label="Select a Rating" />}
value={selectedRatingVideos?.id || ""}
onChange={handleOptionRatingChangeVideos}
>
{ratings.map(option => (
<MenuItem key={option.id} value={option.id}>
{option.name}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
<React.Fragment>
{!coverImage ? (
Expand Down
50 changes: 46 additions & 4 deletions src/components/Publish/EditVideo/EditVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from "../../../state/features/videoSlice.ts";
import ImageUploader from "../../common/ImageUploader.tsx";
import { categories, subCategories } from "../../../constants/Categories.ts";
import { ratings } from "../../../constants/Ratings.ts";
import { MultiplePublish } from "../MultiplePublish/MultiplePublishAll.tsx";
import { TextEditor } from "../../common/TextEditor/TextEditor.tsx";
import { extractTextFromHTML } from "../../common/TextEditor/utils.ts";
Expand Down Expand Up @@ -96,6 +97,8 @@ export const EditVideo = () => {
useState<any>(null);
const [selectedSubCategoryVideos, setSelectedSubCategoryVideos] =
useState<any>(null);
const [selectedRatingVideos, setSelectedRatingVideos] =
useState<any>(null);
const [imageExtracts, setImageExtracts] = useState<any>([]);

const { getRootProps, getInputProps } = useDropzone({
Expand Down Expand Up @@ -148,8 +151,8 @@ export const EditVideo = () => {
// // Split the extracted string into key-value pairs
// const keyValuePairs = extractedString.split(";");

// // Initialize variables to hold the category and subcategory values
// let category, subcategory;
// // Initialize variables to hold the category, subcategory, and rating values
// let category, subcategory, rating;

// // Loop through each key-value pair
// keyValuePairs.forEach((pair) => {
Expand All @@ -160,6 +163,8 @@ export const EditVideo = () => {
// category = value;
// } else if (key === "subcategory") {
// subcategory = value;
// } else if (key === "rating") {
// rating = value;
// }
// });

Expand All @@ -173,6 +178,11 @@ export const EditVideo = () => {
// setSelectedCategoryVideos(selectedOption || null);
// }

// if(rating){
// const selectedOption = ratings.find((option) => option.id === +rating);
// setSelectedRatingVideos(selectedOption || null);
// }

// }
// }, [editVideoProperties]);

Expand Down Expand Up @@ -204,6 +214,13 @@ export const EditVideo = () => {
]?.find(option => option.id === +editVideoProperties.subcategory);
setSelectedSubCategoryVideos(selectedOption || null);
}

if (editVideoProperties?.rating) {
const selectedOption = ratings.find(
option => option.id === +editVideoProperties.rating
);
setSelectedRatingVideos(selectedOption || null);
}
}
}, [editVideoProperties]);

Expand All @@ -223,6 +240,7 @@ export const EditVideo = () => {
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 (!selectedRatingVideos) throw new Error("Please select a rating");
if (!editVideoProperties) return;
if (!userAddress) throw new Error("Unable to locate user address");
let errorMsg = "";
Expand Down Expand Up @@ -251,6 +269,7 @@ export const EditVideo = () => {
let listOfPublishes = [];
const category = selectedCategoryVideos.id;
const subcategory = selectedSubCategoryVideos?.id || "";
const rating = selectedRatingVideos.id;

const fullDescription = extractTextFromHTML(description);
let fileExtension = "mp4";
Expand Down Expand Up @@ -282,14 +301,15 @@ export const EditVideo = () => {
commentsId: editVideoProperties.commentsId,
category,
subcategory,
rating,
code: editVideoProperties.code,
videoType: file?.type || "video/mp4",
filename: `${alphanumericString.trim()}.${fileExtension}`,
};

let metadescription =
`**category:${category};subcategory:${subcategory};code:${editVideoProperties.code}**` +
description.slice(0, 150);
`**category:${category};subcategory:${subcategory};rating:${rating};code:${editVideoProperties.code}**` +
description.slice(0, 140);

const crowdfundObjectToBase64 = await objectToBase64(videoObject);
// Description is obtained from raw data
Expand Down Expand Up @@ -374,6 +394,13 @@ export const EditVideo = () => {
);
setSelectedSubCategoryVideos(selectedOption || null);
};
const handleOptionRatingChangeVideos = (
event: SelectChangeEvent<string>
) => {
const optionId = event.target.value;
const selectedOption = ratings.find(option => option.id === +optionId);
setSelectedRatingVideos(selectedOption || null);
};

const onFramesExtracted = async imgs => {
try {
Expand Down Expand Up @@ -493,6 +520,21 @@ export const EditVideo = () => {
</Select>
</FormControl>
)}
<FormControl fullWidth sx={{ marginBottom: 2 }}>
<InputLabel id="Rating">Select a Rating</InputLabel>
<Select
labelId="Rating"
input={<OutlinedInput label="Select a Rating" />}
value={selectedRatingVideos?.id || ""}
onChange={handleOptionRatingChangeVideos}
>
{ratings.map(option => (
<MenuItem key={option.id} value={option.id}>
{option.name}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
{file && (
<FrameExtractor
Expand Down
Loading