Skip to content

Commit

Permalink
πŸͺ€πŸš– ↝ [SSC-68 SSC-69]: Working on temp comment & component for PH
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Jan 18, 2025
1 parent bbc5aeb commit 32ad9a0
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 12 deletions.
2 changes: 1 addition & 1 deletion citizen
Submodule citizen updated 40 files
+70 βˆ’0 buckets/anomalies/periodCurve.py
+ βˆ’ content/anomalies/106997505/Sector1.png
+ βˆ’ content/anomalies/124709665/Sector1.png
+ βˆ’ content/anomalies/124709665/Sector2.png
+ βˆ’ content/anomalies/156115721/Sector1.png
+ βˆ’ content/anomalies/156115721/Sector2.png
+ βˆ’ content/anomalies/169904935/Sector1.png
+ βˆ’ content/anomalies/169904935/Sector2.png
+ βˆ’ content/anomalies/201175570/Sector1.png
+ βˆ’ content/anomalies/201175570/Sector2.png
+ βˆ’ content/anomalies/210904767/Sector1.png
+ βˆ’ content/anomalies/210904767/Sector2.png
+ βˆ’ content/anomalies/21720215/Sector1.png
+ βˆ’ content/anomalies/238597883/Sector1.png
+ βˆ’ content/anomalies/238597883/Sector2.png
+ βˆ’ content/anomalies/269343479/Sector1.png
+ βˆ’ content/anomalies/277039287/Sector1.png
+ βˆ’ content/anomalies/284300833/Sector1.png
+ βˆ’ content/anomalies/440801822/Sector1.png
+ βˆ’ content/anomalies/440801822/Sector2.png
+ βˆ’ content/anomalies/440801822/Sector3.png
+ βˆ’ content/anomalies/440801822/Sector33.png
+ βˆ’ content/anomalies/440801822/Sector4.png
+ βˆ’ content/anomalies/440801822/Sector44.png
+ βˆ’ content/anomalies/440801822/Sector45.png
+ βˆ’ content/anomalies/440801822/Sector5.png
+ βˆ’ content/anomalies/50365310/Sector1.png
+ βˆ’ content/anomalies/50365310/Sector2.png
+ βˆ’ content/anomalies/57299130/Sector1.png
+ βˆ’ content/anomalies/57299130/Sector2.png
+ βˆ’ content/anomalies/57299130/Sector3.png
+ βˆ’ content/anomalies/57299130/Sector4.png
+ βˆ’ content/anomalies/65212867/Sector1.png
+ βˆ’ content/anomalies/65212867/Sector2.png
+ βˆ’ content/anomalies/88863718/Sector1.png
+ βˆ’ content/anomalies/88863718/Sector2.png
+ βˆ’ content/anomalies/88863718/Sector3.png
+ βˆ’ content/anomalies/88863718/Sector4.png
+0 βˆ’114 content/anomalies/periodCurves.py
+80 βˆ’3 content/lk.ipynb
4 changes: 2 additions & 2 deletions components/Projects/Telescopes/Transiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function StarterTelescopeTess({ anomalyid }: SelectedAnomProps) {
setHasMission3000001(false);
} finally {
setMissionLoading(false);
}
};
};
checkTutorialMission();
}, [session, supabase]);
Expand Down Expand Up @@ -79,7 +79,7 @@ export function StarterTelescopeTess({ anomalyid }: SelectedAnomProps) {
const binnedUrl = `${supabaseUrl}/storage/v1/object/public/anomalies/${randomAnomaly.id}/Binned.png`;
const sectorUrl = `${supabaseUrl}/storage/v1/object/public/anomalies/${randomAnomaly.id}/Sector1.png`;
imageList.push(binnedUrl, sectorUrl);
}
};

setImageUrls(imageList);
setSelectedAnomaly(randomAnomaly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PlanetTypeCommentForm from "./PlanetType";
import { StarterTelescopeTess } from "@/components/Projects/Telescopes/Transiting";
import VotePlanetClassifictions from "./PHVote";
import PHClassificationGenerator from "./PlanetMaker";
import PlanetTemperatureForm from "./PlanetTemperature";

interface MissionStep {
id: number;
Expand Down Expand Up @@ -156,6 +157,17 @@ const PlanetHuntersSteps = () => {
},
{
id: 5,
title: "Calculate planetary temperatures",
description: "Use satellite data to help determine the temperature of planets you've discovered",
action: () => {},
// completedCount: mission4CompletedCount
color: 'text-yellow-700',
chapter: 1,
icon: "symbol",
completedCount: 0
},
{
id: 6,
title: "Make your own planet design",
description: "You're now able to start creating visual representations of your discoveries. These will become more advanced and accurate the more data you discover",
icon: Paintbrush2,
Expand Down Expand Up @@ -194,7 +206,8 @@ const PlanetHuntersSteps = () => {
{selectedMission.id === 2 && <StarterTelescopeTess />}
{selectedMission.id === 3 && <PlanetTypeCommentForm />}
{selectedMission.id === 4 && <VotePlanetClassifictions />}
{selectedMission.id === 5 && <PHClassificationGenerator />}
{selectedMission.id === 5 && <PlanetTemperatureForm />}
{selectedMission.id === 6 && <PHClassificationGenerator />}
</center>
</div>
</div>
Expand All @@ -207,7 +220,7 @@ const PlanetHuntersSteps = () => {
const maxChapter = Math.max(...steps.map(step => step.chapter));

return (
<div className="flex flex-col items-center bg-[#1D2833]/90 width-[100%] text-white rounded-2xl p-6">
<div className="flex flex-col items-center width-[100%] text-white rounded-2xl p-6">
<div className="w-full mb-6">
<h1 className="text-xl font-bold mb-2">Chapter {currentChapter}</h1>
<div className="h-2 bg-gray-600 rounded-full w-full mb-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import React, { useEffect, useState } from "react";
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react";
import { SimplePostSingle } from "@/content/Posts/SimplePostSingle";
import { SciFiPanel } from "@/components/ui/styles/sci-fi/panel";

interface ClassificationConfiguration {
classificationOptions: { [key: string]: any };
temperature?: string;
votes?: number;
}

interface Classification {
author: string;
id: number;
content: string;
title: string;
classificationtype: string;
anomaly: number;
media: (string | { uploadUrl?: string })[] | null;
classificationConfiguration?: ClassificationConfiguration;
image_url?: string;
images?: string[];
votes?: number;
}

const PlanetTemperatureForm: React.FC = () => {
const supabase = useSupabaseClient();
const session = useSession();

const [loading, setLoading] = useState(true);
const [classifications, setClassifications] = useState<Classification[]>([]);
const [currentClassification, setCurrentClassification] = useState<Classification | null>(null);
const [commentInputs, setCommentInputs] = useState<{ comment: string; temperature: string }>({ comment: "", temperature: "" });

useEffect(() => {
const fetchClassifications = async () => {
try {
const { data, error } = await supabase
.from("classifications")
.select("*")
.eq("classificationtype", "planet");

if (error) {
throw new Error(`Error fetching classifications: ${error.message}`);
}

const processedData = data?.map((classification) => {
const media = classification.media;
let images: string[] = [];

if (Array.isArray(media)) {
media.forEach((item) => {
if (typeof item === "string" && item.startsWith("http")) {
images.push(item);
} else if (Array.isArray(item)) {
item.forEach((nested) => {
if (typeof nested === "string" && nested.startsWith("http")) {
images.push(nested);
}
});
} else if (typeof item === "object" && item.uploadUrl) {
images.push(item.uploadUrl);
}
});
}

const votes = classification.classificationConfiguration?.votes || 0;

return { ...classification, images, votes };
});

setClassifications(processedData || []);
setCurrentClassification(processedData?.[0] || null);
} catch (err) {
console.error(err);
} finally {
setLoading(false);
}
};

fetchClassifications();
}, [supabase]);

const fetchRandomClassification = () => {
if (classifications.length === 0) return;
const randomIndex = Math.floor(Math.random() * classifications.length);
setCurrentClassification(classifications[randomIndex]);
setCommentInputs({ comment: "", temperature: "" });
};

const handleProposeTempComment = async () => {
if (!currentClassification) return;
const { comment, temperature } = commentInputs;
if (!comment || !temperature) {
console.error("Both comment and temperature are required!");
return;
}

try {
const { error } = await supabase
.from("comments")
.insert([
{
content: comment,
classification_id: currentClassification.id,
author: session?.user?.id,
configuration: { temperature },
},
]);

if (error) {
throw error;
}

setCommentInputs({ comment: "", temperature: "" });
console.log("Comment inserted successfully with temperature value");
} catch (err) {
console.error("Error inserting comment: ", err);
}
};

const handleInputChange = (field: "comment" | "temperature", value: string) => {
setCommentInputs((prev) => ({ ...prev, [field]: value }));
};

if (loading) {
return <>Loading...</>;
}

return (
<div className="flex flex-col justify-center items-center">
{currentClassification ? (
<div className="w-full max-w-3xl p-4">
<SciFiPanel>
<SimplePostSingle
id={currentClassification.id.toString()}
title={`Planet discovery #${currentClassification.id}`}
author={currentClassification.author || "Unknown"}
content={currentClassification.content || ""}
category={currentClassification.classificationtype || "Planet"}
images={currentClassification.images || []}
// votes={currentClassification.votes || 0}
/>
</SciFiPanel>
<SciFiPanel>
<div className="flex flex-col items-center mt-4 gap-4">
<textarea
value={commentInputs.comment}
onChange={(e) => handleInputChange("comment", e.target.value)}
placeholder="Enter your comment"
className="w-full p-2 border text-gray-500 border-gray-300 rounded"
/>
<input
type="number"
value={commentInputs.temperature}
onChange={(e) => handleInputChange("temperature", e.target.value)}
placeholder="Temp (Β°C)"
className="w-full p-2 border text-gray-500 border-gray-300 rounded"
/>
<button
onClick={handleProposeTempComment}
className="px-4 py-2 text-white bg-blue-500 rounded"
>
Submit
</button>
<button
onClick={fetchRandomClassification}
className="px-4 py-2 text-white bg-gray-500 rounded mt-2"
>
Show Random Post
</button>
</div>
</SciFiPanel>
</div>
) : (
<div>No classifications found.</div>
)}
</div>
);
};

export default PlanetTemperatureForm;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Classification {
anomaly: number;
classificationtype: string;
media: any;
classificationConfiguration: {
classificationConfiguration: {
votes: number;
classificationOptions: { [key: string]: any };
};
Expand Down Expand Up @@ -58,7 +58,7 @@ const PlanetTypeCommentForm = () => {
setClassifications(processedData || []);
} catch (err) {
console.error(err);
}
};
};

const fetchComments = async () => {
Expand Down Expand Up @@ -86,7 +86,7 @@ const PlanetTypeCommentForm = () => {
setComments(data || []);
} catch (err) {
console.error(err);
}
};
};

const fetchData = async () => {
Expand Down Expand Up @@ -149,7 +149,7 @@ const PlanetTypeCommentForm = () => {
if (!commentInput) {
console.error("Comment input is required");
return;
}
};

try {
const { error } = await supabase
Expand All @@ -168,7 +168,7 @@ const PlanetTypeCommentForm = () => {
setCommentInputs((prev) => ({ ...prev, [classificationId]: "" }));
console.log("Comment inserted successfully with planet type.");
} catch (err) {
console.error("Error inserting comment:", err);
console.error("Error inserting comment: ", err);
}
};

Expand Down
7 changes: 5 additions & 2 deletions content/Posts/SimplePostSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import StructuresOnPlanet from '@/components/Structures/Structures';
import { AvatarGenerator } from '@/components/Account/Avatar';
import { Button } from '@/components/ui/button';
import { Share2 } from 'lucide-react';
import { Share2, ThumbsUpIcon } from 'lucide-react';
import PlanetGenerator from '@/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator';

interface SimplePostSingleProps {
Expand All @@ -14,6 +14,7 @@ interface SimplePostSingleProps {
content: string;
category: string;
images: string[];
votes?: number;
classificationConfiguration?: any;
};

Expand All @@ -24,6 +25,7 @@ export function SimplePostSingle({
content,
category,
images,
votes,
classificationConfiguration,
}: SimplePostSingleProps) {
const [currentIndex, setCurrentIndex] = useState(0);
Expand Down Expand Up @@ -129,11 +131,12 @@ export function SimplePostSingle({
</div>
</>
)}
{/* {votes &&<ThumbsUpIcon className='text-blue-500' /> {votes} Votes */}
</div>
)}
</CardContent>
{/* <PlanetGenerator classificationId={String(id)} classificationConfig={classificationConfiguration} author={author} /> */}
<StructuresOnPlanet author={author} />
{/* <StructuresOnPlanet author={author} /> */}
</Card>
</div>
);
Expand Down

0 comments on commit 32ad9a0

Please sign in to comment.