Skip to content

Commit

Permalink
🔍🌁 ↝ [SSP-37 SSG-78 SSC-45 SSC-43]: Fixing telescope issue & some mor…
Browse files Browse the repository at this point in the history
…e exploration
  • Loading branch information
Gizmotronn committed Dec 5, 2024
1 parent e84fc15 commit e1a9874
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 139 deletions.
2 changes: 1 addition & 1 deletion components/(scenes)/planetScene/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const EarthViewLayout: React.FC<PlanetViewLayoutProps> = ({
/>

<div className="relative flex flex-1 z-10">
<VerticalToolbar />
{/* <VerticalToolbar /> */}

<div className="relative flex flex-col flex-1">
{children.slice(0, 2).map((child, index) => (
Expand Down
15 changes: 10 additions & 5 deletions components/Projects/Telescopes/DailyMinorPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ export function DailyMinorPlanet() {

useEffect(() => {
if (!hasMission20000003 || missionLoading || !session) return;

const fetchAnomaly = async () => {
try {
const { data: anomalyData, error: anomalyError } = await supabase
.from("anomalies")
.select("*")
.eq("anomalySet", "telescope-minorPlanet");

if (anomalyError) {
throw anomalyError;
};

const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
setAnomaly(randomAnomaly);

Expand All @@ -218,17 +218,22 @@ export function DailyMinorPlanet() {
`${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/3.png`,
`${supabaseUrl}/storage/v1/object/public/telescope/telescope-dailyMinorPlanet/${randomAnomaly.id}/4.png`
];

setImageUrls(imageUrls);

// Log the anomaly ID and image URLs in the console
console.log("Anomaly ID:", randomAnomaly.id);
console.log("Image URLs:", imageUrls);
} catch (error: any) {
console.error("Error fetching anomaly ", error.message);
setAnomaly(null);
} finally {
setLoading(false);
};
};

fetchAnomaly();
}, [hasMission20000003, missionLoading, session, supabase]);
}, [hasMission20000003, missionLoading, session, supabase]);

const handlePrevious = () => {
setCurrentImageIndex((prevIndex) => (prevIndex === 0 ? imageUrls.length - 1 : prevIndex - 1));
Expand Down
181 changes: 60 additions & 121 deletions components/Projects/Telescopes/Transiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export interface Anomaly {
export function StarterTelescope() {
const supabase = useSupabaseClient();
const session = useSession();

const { activePlanet } = useActivePlanet();

const [anomaly, setAnomaly] = useState<Anomaly | null>(null);
const [anomalies, setAnomalies] = useState<Anomaly[]>([]);
const [selectedAnomaly, setSelectedAnomaly] = useState<Anomaly | null>(null);
const [userChoice, setUserChoice] = useState<string | null>(null);
const [imageUrl, setImageUrl] = useState<string | null>(null);
const [configuration, setConfiguration] = useState<any | null>(null);
Expand All @@ -30,20 +30,13 @@ export function StarterTelescope() {
useEffect(() => {
const checkTutorialMission = async () => {
if (!session) return;

try {
const { data: missionData, error: missionError } = await supabase
.from('missions')
.select('id')
.eq('user', session.user.id)
.eq('mission', 3000001);

if (missionError) throw missionError;

// Log data for debugging
console.log('Mission Data:', missionData);

// Check if any rows exist
setHasMission3000001(missionData && missionData.length > 0);
} catch (error: any) {
console.error('Error checking user mission: ', error.message || error);
Expand All @@ -52,15 +45,12 @@ export function StarterTelescope() {
setMissionLoading(false);
}
};

checkTutorialMission();
}, [session, supabase]);
}, [session, supabase]);

// Fetch structure configuration
useEffect(() => {
const fetchStructureConfiguration = async () => {
if (!session) return;

try {
const { data: inventoryData, error: inventoryError } = await supabase
.from('inventory')
Expand All @@ -71,168 +61,117 @@ export function StarterTelescope() {
.order('id', { ascending: true })
.limit(1)
.single();

if (inventoryError) throw inventoryError;

if (inventoryData && inventoryData.configuration) {
console.log("Raw configuration data:", inventoryData.configuration);
setConfiguration(inventoryData.configuration);
} else {
setConfiguration(null);
}
setConfiguration(inventoryData?.configuration || null);
} catch (error: any) {
console.error('Error fetching structure config:', error.message);
setError('Error fetching structure configuration: ' + (error.message || JSON.stringify(error)));
setConfiguration(null);
};
}
};

fetchStructureConfiguration();
}, [session, supabase, activePlanet]);

useEffect(() => {
const fetchAnomaly = async () => {
const fetchAnomalies = async () => {
if (!session || !userChoice) {
setLoading(false);
return;
};

}
try {
const { data: anomalyData, error: anomalyError } = await supabase
.from("anomalies")
.select("*")
.eq("anomalySet", userChoice)

.eq("anomalySet", userChoice);
if (anomalyError) throw anomalyError;

if (!anomalyData) {
setAnomaly(null);
setLoading(false);
return;
};

const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)] as Anomaly;
setAnomaly(randomAnomaly);
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
setImageUrl(`${supabaseUrl}/storage/v1/object/public/anomalies/${randomAnomaly.id}/Binned.png`);

setAnomalies(anomalyData || []);
console.log("Fetched anomalies:", anomalyData);

if (anomalyData?.length > 0) {
const randomAnomaly = anomalyData[Math.floor(Math.random() * anomalyData.length)];
console.log("Random anomaly selected:", randomAnomaly);

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://your-default-supabase-url.com';
if (randomAnomaly?.id) {
const constructedUrl = `${supabaseUrl}/storage/v1/object/public/anomalies/${randomAnomaly.id}/Binned.png`;
console.log("Constructed image URL:", constructedUrl);
setImageUrl(constructedUrl);
} else {
console.error("Random anomaly ID is null or undefined.");
}
setSelectedAnomaly(randomAnomaly);
} else {
console.log("No anomalies found.");
setSelectedAnomaly(null);
}
} catch (error: any) {
console.error('Error fetching anomaly: ', error.message);
setAnomaly(null);
console.error("Error fetching anomalies:", error.message || error);
} finally {
setLoading(false);
};
}
};

fetchAnomaly();
}, [session, supabase, userChoice, activePlanet]);
fetchAnomalies();
}, [session, supabase, userChoice]);


const handleChoice = (choice: string) => {
setUserChoice(choice);
};

if (error) {
return (
<div>
<p>{error}</p>
</div>
);
};

if (error) return <div><p>{error}</p></div>;
if (missionLoading || hasMission3000001 === null) return <div>Loading...</div>;
if (!configuration) {
return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg overflow-y-auto max-h-[90vh] rounded-lg">
<p className="text-sm font-bold">Fetching structure configuration...</p>
</div>
);
};

}
if (!hasMission3000001) {
return (
<div>
<FirstTelescopeClassification
anomalyid={"6"}
/>
<FirstTelescopeClassification anomalyid={"6"} />
</div>
);
};

// User choice handling
}
if (!userChoice) {
return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg overflow-y-auto max-h-[90vh] rounded-lg">
<p className="text-sm font-bold">Choose a target to observe using your Telescope:</p>
{configuration["missions unlocked"] && Array.isArray(configuration["missions unlocked"]) && configuration["missions unlocked"].length > 0 ? (
configuration["missions unlocked"].map((missionId: string) => (
<button
key={missionId}
onClick={() => handleChoice(missionId)}
className="bg-blue-500 text-white font-bold py-2 px-4 rounded-md shadow-sm hover:bg-blue-700"
>
{missionId}
</button>
))
) : (
<p>No missions unlocked.</p>
)}
</div>
);
};

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

// No anomaly found
if (!anomaly) {
return (
<div>
<p>No anomaly found.</p>
{configuration["missions unlocked"]?.map((missionId: string) => (
<button
key={missionId}
onClick={() => handleChoice(missionId)}
className="bg-blue-500 text-white font-bold py-2 px-4 rounded-md shadow-sm hover:bg-blue-700"
>
{missionId}
</button>
)) || <p>No missions unlocked.</p>}
</div>
);
};

if (missionLoading || hasMission3000001 === null) {
return <div>Loading...</div>;
}

if (!hasMission3000001) {
return (
<div>
<FirstTelescopeClassification anomalyid={"6"} />
</div>
);
};
if (loading) return <div><p>Loading...</p></div>;
if (!anomalies.length) return <div><p>No anomaly found.</p></div>;

// Main rendering
return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg overflow-y-auto max-h-[90vh] rounded-lg">
<div className="p-4 rounded-md relative w-full">
{anomaly.avatar_url && (
<img src={anomaly.avatar_url} alt="Anomaly Avatar" className='w-24 h-24' />
)}
{imageUrl && (
<img src={imageUrl} alt="Binned Anomaly" />
{selectedAnomaly?.avatar_url && <img src={selectedAnomaly.avatar_url} alt="Anomaly Avatar" />}
{imageUrl && <img src={imageUrl} alt="Anomaly Binned Image" />}
{selectedAnomaly && (
<ClassificationForm
anomalyId={selectedAnomaly.id.toString()}
anomalyType="planet"
missionNumber={1372001}
assetMentioned={selectedAnomaly?.id.toString()}
structureItemId={3103}
/>
)}
</div>
{imageUrl && (
<ClassificationForm
anomalyId={anomaly.id.toString()}
anomalyType='planet'
missionNumber={1372001}
assetMentioned={imageUrl}
structureItemId={3103}
/>
)}
</div>
);
};


interface TelescopeProps {
anomalyid: string;
};
Expand Down
24 changes: 12 additions & 12 deletions constants/Structures/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,24 @@ export const StructuresConfig: StructureConfig = {
sizePercentage: 60,
showInNoModal: true,
},
{
icon: <EarthIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Find new worlds",
dynamicComponent: <ExoplanetTransitHunter />,
sizePercentage: 80,
},
// {
// icon: <EarthIcon className="w-6 h-6 text-[#5e81ac]" />,
// text: "Find new worlds",
// dynamicComponent: <ExoplanetTransitHunter />,
// sizePercentage: 80,
// },
{
icon: <SunIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Sunspot data",
dynamicComponent: <TelescopeSunspotDetector />,
sizePercentage: 60,
},
// {
// icon: <TestTubeDiagonalIcon className="w-6 h-6 text-[#5e81ac]" />,
// text: "Find early solar systems",
// dynamicComponent: <TelescopeDiskDetector />,
// sizePercentage: 70,
// },
{
icon: <TestTubeDiagonalIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Find early solar systems",
dynamicComponent: <TelescopeDiskDetector />,
sizePercentage: 70,
},
{
icon: <MoonStarIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Discover asteroids",
Expand Down

0 comments on commit e1a9874

Please sign in to comment.