- {resource.type === 'folder' &&
}
- {resource.type === 'file' &&
}
- {resource.type === 'book' &&
}
-
-
{resource.name}
- {resource.type === 'folder' && (
-
{resource.itemCount} items
- )}
- {resource.type === 'file' && (
-
{resource.size}
- )}
- {resource.type === 'book' && (
-
By {resource.author}
+
+
+ {resources.map((resource) => (
+
+
+
+ {resource.resource_type === 'file' ? (
+
+ ) : (
+
)}
+
{resource.title}
+
+
+
))}
+
+ {resources.length === 0 && (
+
+ No resources found. Start by uploading some materials!
+
+ )}
);
}
-
-export default StudyResources;
diff --git a/src/pages/dashboard/upload.tsx b/src/pages/dashboard/upload.tsx
index 7075cd0..b2c966c 100644
--- a/src/pages/dashboard/upload.tsx
+++ b/src/pages/dashboard/upload.tsx
@@ -1,25 +1,156 @@
-import React from 'react';
-import { Upload } from 'lucide-react';
+import { useState, ChangeEvent } from 'react';
+import { useSupabaseClient, useUser } from '@supabase/auth-helpers-react';
+import { toast } from 'react-hot-toast';
import { Button } from '../../components/ui/Button';
+import { Card } from '../../components/ui/card';
+
+type UploadType = 'file' | 'link';
+
+export default function UploadPage() {
+ const [uploadType, setUploadType] = useState
('file');
+ const [title, setTitle] = useState('');
+ const [url, setUrl] = useState('');
+ const [file, setFile] = useState(null);
+ const [isUploading, setIsUploading] = useState(false);
+
+ const supabase = useSupabaseClient();
+ const user = useUser();
+
+ const handleFileChange = (e: ChangeEvent) => {
+ if (e.target.files && e.target.files[0]) {
+ setFile(e.target.files[0]);
+ }
+ };
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ if (!user) return;
+
+ try {
+ setIsUploading(true);
+
+ if (uploadType === 'file' && file) {
+ // Upload file to Supabase Storage
+ const fileExt = file.name.split('.').pop();
+ const fileName = `${Math.random()}.${fileExt}`;
+ const filePath = `${user.id}/${fileName}`;
+
+ const { error: uploadError } = await supabase.storage
+ .from('study-materials')
+ .upload(filePath, file);
+
+ if (uploadError) throw uploadError;
+
+ // Create database entry
+ const { error: dbError } = await supabase
+ .from('study_resources')
+ .insert({
+ user_id: user.id,
+ title,
+ resource_type: 'file',
+ file_path: filePath,
+ file_type: file.type,
+ file_size: file.size
+ });
+
+ if (dbError) throw dbError;
+ } else if (uploadType === 'link') {
+ // Create database entry for link
+ const { error: dbError } = await supabase
+ .from('study_resources')
+ .insert({
+ user_id: user.id,
+ title,
+ resource_type: 'link',
+ url
+ });
+
+ if (dbError) throw dbError;
+ }
+
+ toast.success('Resource uploaded successfully!');
+ // Reset form
+ setTitle('');
+ setUrl('');
+ setFile(null);
+ } catch (error) {
+ console.error('Upload error:', error);
+ toast.error('Failed to upload resource');
+ } finally {
+ setIsUploading(false);
+ }
+ };
-function UploadMaterials() {
return (
Upload Study Materials
-
-
-
-
-
Drop your files here
-
- or click to browse from your computer
-
+
+
+
+
+
-
+
+
-
+
);
}
-
-export default UploadMaterials;