diff --git a/client/src/App.tsx b/client/src/App.tsx index e377e99..cc41b06 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -10,6 +10,8 @@ import EditProfileForm from './pages/EditProfileForm'; import { MessagePage } from './pages/MessagePage'; import Projects from './pages/Projects'; import Visualization from './pages/Visualization'; +import PrivacyPolicy from './pages/Privacypolicy'; +import ProjectDisplay from './pages/ProjectDisplay'; const App = () => { @@ -24,8 +26,10 @@ const App = () => { } /> } /> } /> + } /> } /> } /> + } /> 404} /> diff --git a/client/src/components/Footer/Footer.tsx b/client/src/components/Footer/Footer.tsx index 266ce47..4bad2e9 100644 --- a/client/src/components/Footer/Footer.tsx +++ b/client/src/components/Footer/Footer.tsx @@ -24,12 +24,12 @@ const Footer = () => { @@ -63,7 +63,7 @@ const Footer = () => {
  • - + Privacy Policy
  • diff --git a/client/src/components/Projects/AddProject.tsx b/client/src/components/Projects/AddProject.tsx index bc99aef..85e2a2b 100644 --- a/client/src/components/Projects/AddProject.tsx +++ b/client/src/components/Projects/AddProject.tsx @@ -6,7 +6,6 @@ import { AlertDialogContent, AlertDialogDescription, AlertDialogHeader, - AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Cross1Icon } from "@radix-ui/react-icons"; @@ -16,6 +15,7 @@ import { toast } from 'sonner'; import { Button } from "@/components/ui/button"; import { Icons } from "@/components/ui/icons"; import { Textarea } from '../ui/textarea'; +import UploadComponent from './UploadComponent'; const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:5000'; @@ -24,6 +24,7 @@ interface Project { description: string; repoLink: string; tags: Tag[]; + imageUrl?: string; } interface Tag { @@ -37,8 +38,10 @@ const AddProject: React.FC<{ onProjectChange: () => void }> = ({ onProjectChange description: '', repoLink: '', tags: [], + imageUrl: '', // Add image URL state }); + const [imageFile, setImageFile] = useState(null); // State for handling image file const username = localStorage.getItem('devhub_username'); const [isLoading, setIsLoading] = useState(false); @@ -50,16 +53,39 @@ const AddProject: React.FC<{ onProjectChange: () => void }> = ({ onProjectChange })); }; + // Function to upload image to Cloudinary via the backend + const uploadImage = async () => { + if (!imageFile) return ''; // Return empty string if no image is uploaded + + const formData = new FormData(); + formData.append('image', imageFile); + + try { + const response = await axios.post(`${backendUrl}/project/upload`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); + + return response.data.imageUrl; // Return the image URL + } catch (error) { + console.error('Image upload failed:', error); + toast.error('Failed to upload image'); + return ''; + } + }; + const handleAddProject = async () => { if (!username) { toast.error('Username not found'); return; } - setIsLoading(true); + setIsLoading(true); try { - // Convert tags array to a comma-separated string + const imageUrl = await uploadImage(); // Upload the image and get the URL + const tagsString = newProject.tags.map((tag) => tag.value).join(','); const response = await axios.post( @@ -68,14 +94,16 @@ const AddProject: React.FC<{ onProjectChange: () => void }> = ({ onProjectChange title: newProject.title, description: newProject.description, repo_link: newProject.repoLink, - tags: tagsString, // Send as comma-separated string + tags: tagsString, // Send as comma-separated string + imageUrl, // Include the uploaded image URL }, { withCredentials: true }, ); if (response.status === 200 || response.status === 201) { toast.success('Project added successfully'); - setNewProject({ title: '', description: '', repoLink: '', tags: [] }); // Reset form + setNewProject({ title: '', description: '', repoLink: '', tags: [], imageUrl: '' }); // Reset form + setImageFile(null); // Reset the image file onProjectChange(); } else { toast.error('Failed to add project'); @@ -84,13 +112,10 @@ const AddProject: React.FC<{ onProjectChange: () => void }> = ({ onProjectChange console.error('Failed to add project:', error); toast.error('An error occurred while adding the project'); } finally { - setIsLoading(false); // Reset loading state + setIsLoading(false); // Reset loading state } }; - - - return ( @@ -98,66 +123,67 @@ const AddProject: React.FC<{ onProjectChange: () => void }> = ({ onProjectChange
    - Add New Project + Add New Project
    - +
    - - -
    -
    - -
    -
    -