Skip to content

Commit

Permalink
r comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinVn committed Oct 27, 2024
1 parent 38a3cee commit 8e74971
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/database/music/deleteMP3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { firestore } from "../../firebase"; // Firestore instance import
import { firestore } from "../../firebase";
import { doc, deleteDoc } from "firebase/firestore";

export async function deleteMP3(user, item, toast) {
Expand Down
6 changes: 2 additions & 4 deletions src/database/music/refreshMP3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { firestore } from "../../firebase"; // Firestore import
import { firestore } from "../../firebase";
import { doc, updateDoc } from "firebase/firestore";
import { auth } from "../../firebase";

Expand All @@ -10,12 +10,10 @@ export async function refreshMP3(youtubeID, updatedFields) {
throw new Error("User is not logged in.");
}

const userId = user.uid; // Get user's UID
const userId = user.uid;

// Reference to the specific MP3 document in the user's 'mp3s' collection
const mp3Ref = doc(firestore, `users/${userId}/mp3s`, youtubeID);

// Update the document with the new fields (only the keys in updatedFields will be changed)
await updateDoc(mp3Ref, updatedFields);
console.log(`MP3 with ID ${youtubeID} updated successfully!`);
} catch (error) {
Expand Down
4 changes: 1 addition & 3 deletions src/database/music/saveMP3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ export async function saveMP3(mp3) {
throw new Error("User is not logged in.");
}

const userId = user.uid; // Get user's UID
// Create a document reference in Firestore for this user's MP3
const userId = user.uid;
const mp3Ref = doc(firestore, `users/${userId}/mp3s`, mp3.youtubeID);
// Save MP3 data under the user's 'mp3s' collection
await setDoc(mp3Ref, mp3);
console.log("MP3 saved successfully for user:", userId);
} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions src/pages/BugReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ const BugReport = () => {
e.preventDefault();
const { name, email, message } = formData;

// Create a mailto link with pre-filled data
const mailtoLink = `mailto:[email protected]?subject=Bug Report from ${name}&body=Name: ${name}%0AEmail: ${email}%0AMessage: ${message}`;

// Open the user's email client
window.location.href = mailtoLink;
};

Expand Down
1 change: 0 additions & 1 deletion src/pages/EditAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const EditProfile = () => {

const isSaveButtonDisabled = !displayName || displayName === initialDisplayName;

// Show loading state while user data is being fetched
if (loadingUser) {
return <PageFallback />;
}
Expand Down
3 changes: 0 additions & 3 deletions src/utils/ConvertErrorMsg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// src/utils/errorMessages.js

export const getErrorMessage = (code) => {
switch (code) {
case "auth/invalid-ceredential":
Expand All @@ -10,7 +8,6 @@ export const getErrorMessage = (code) => {
return "The password is too weak. It should be at least 6 characters.";
case "auth/invalid-email":
return "Invalid email address.";
// Add more cases as needed
default:
return "An unexpected error occurred. Please try again.";
}
Expand Down
20 changes: 8 additions & 12 deletions src/utils/ConvertToMP4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { saveMP4, getAllMP4s } from "./mp4DB";
import { youtube_parser } from "./YoutubeParser";
import "react-toastify/dist/ReactToastify.css";

// Calculate total size of MP4s for a specific user
const calculateTotalSizeInMB = async (mp4s) => {
const totalSizeInBytes = mp4s.reduce((total, mp4) => total + mp4.fileSize, 0);
return totalSizeInBytes / 1048576; // Convert bytes to MB
return totalSizeInBytes / 1048576;
};

// Check if adding a new MP4 exceeds the storage limit
const checkStorageLimit = (totalSizeInMB, fileSizeInMB, storageLimit, triggerTheModal, isModalOpened) => {
if (totalSizeInMB + fileSizeInMB > storageLimit) {
if (!isModalOpened) {
Expand All @@ -20,7 +18,6 @@ const checkStorageLimit = (totalSizeInMB, fileSizeInMB, storageLimit, triggerThe
return true;
};

// Main function to fetch MP4 data from the API
export const fetchMP4Data = async (
e,
setLoading,
Expand All @@ -30,7 +27,7 @@ export const fetchMP4Data = async (
storageLimit,
triggerTheModal,
isModalOpened,
userID // Added userID parameter
userID
) => {
e.preventDefault();
setLoading(true);
Expand Down Expand Up @@ -72,8 +69,8 @@ export const fetchMP4Data = async (
"360p": response.data.link[18][0],
"720p": response.data.link[22][0],
},
userID, // Include userID in the MP4 data
fileSize: response.data.fileSize, // Assume this value is available in the response
userID,
fileSize: response.data.fileSize,
};

if (!mp4Data.links) {
Expand All @@ -83,8 +80,8 @@ export const fetchMP4Data = async (
return;
}

const existingMp4s = await getAllMP4s(); // Fetch all MP4s for the user
const userMp4s = existingMp4s.filter((mp4) => mp4.userID === userID); // Filter by userID
const existingMp4s = await getAllMP4s();
const userMp4s = existingMp4s.filter((mp4) => mp4.userID === userID);

const isDuplicate = userMp4s.some((mp4) => mp4.title === mp4Data.title);

Expand All @@ -96,13 +93,12 @@ export const fetchMP4Data = async (
}

const totalSizeInMB = await calculateTotalSizeInMB(userMp4s);
const fileSizeInMB = mp4Data.fileSize / 1048576; // Convert bytes to MB
const fileSizeInMB = mp4Data.fileSize / 1048576;

// Check if the storage limit is exceeded
const canSave = checkStorageLimit(totalSizeInMB, fileSizeInMB, storageLimit, triggerTheModal, isModalOpened);

if (canSave) {
await saveMP4(mp4Data); // Save MP4 for the user
await saveMP4(mp4Data);
setMp4List((prevList) => ({
...prevList,
[youtubeID]: mp4Data,
Expand Down

0 comments on commit 8e74971

Please sign in to comment.