diff --git a/components/Content/ClassificationFeed.tsx b/components/Content/ClassificationFeed.tsx index 12d3c441..ac94f9d7 100644 --- a/components/Content/ClassificationFeed.tsx +++ b/components/Content/ClassificationFeed.tsx @@ -85,7 +85,7 @@ export function ClassificationFeedForIndividualPlanet(planetId) { const postsResponse = await supabase .from("classifications") // .select("id, content, created_at, author, anomaly, basePlanets, profiles(id, avatar_url, full_name, username)") - .select("id, created_at, content, anomaly, profiles(id, avatar_url, full_name, username)") + .select("id, created_at, content, anomaly, media, profiles(id, avatar_url, full_name, username)") .eq('anomaly', planetId.planetId.id) .order('created_at', { ascending: false }); diff --git a/components/Content/Classify/AnomalyPostFormCard.tsx b/components/Content/Classify/AnomalyPostFormCard.tsx index 5ea7ddb5..493359b2 100644 --- a/components/Content/Classify/AnomalyPostFormCard.tsx +++ b/components/Content/Classify/AnomalyPostFormCard.tsx @@ -1,6 +1,7 @@ import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import { ClimbingBoxLoader } from "react-spinners"; export default function PostFormCardAnomalyTag({ onPost, planetId }) { const supabase = useSupabaseClient(); @@ -9,9 +10,9 @@ export default function PostFormCardAnomalyTag({ onPost, planetId }) { const [content, setContent] = useState(''); const profile = session?.user?.id; const [avatar_url, setAvatarUrl] = useState(null); - /* const [uploads, setUploads] = useState([]); + const [uploads, setUploads] = useState([]); const [isUploading, setIsUploading] = useState(false); - const [userExperience, setUserExperience] = useState(); + /* const [userExperience, setUserExperience] = useState(); const [hasRequiredItem, setHasRequiredItem] = useState(false); */ const router = useRouter(); @@ -28,7 +29,7 @@ export default function PostFormCardAnomalyTag({ onPost, planetId }) { .insert({ author: profile, content, - // media: uploads + media: uploads, // planets2: planetId, anomaly: planetId, // Set this to multiple anomaly types/foreign key options }).then(response => { @@ -57,6 +58,26 @@ export default function PostFormCardAnomalyTag({ onPost, planetId }) { }, [session]); */ // Function to add media to the publication + async function addMedia ( e ) { + const files = e.target.files; + if (files.length > 0) { + setIsUploading(true); + for (const file of files) { + const fileName = Date.now() + session?.user?.id + file.name; + const result = await supabase.storage + .from('media') + .upload(fileName, file); + + if (result.data) { + const url = process.env.NEXT_PUBLIC_SUPABASE_URL + '/storage/v1/object/public/media/' + result.data.path; + setUploads(prevUploads => [...prevUploads, url]); + } else { + console.log(result); + } + } + setIsUploading(false); + }; + }; // Frontend output return ( @@ -71,6 +92,30 @@ export default function PostFormCardAnomalyTag({ onPost, planetId }) { className="grow p-3 h-24 rounded-xl" placeholder={`What do you think about this planet candidate, ${profile}?`} /> + {isUploading && ( +
{content}
+