Skip to content

Commit

Permalink
🦁🐾 ↝ Working microservice, just few alterations needed [ GP-13 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Mar 11, 2024
1 parent 6d8cfb9 commit 84c17bb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
11 changes: 8 additions & 3 deletions components/Content/Planets/Base/IndividualBasePlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function IndividualBasePlanetDesktop({ id }: { id: string }) {
const [selectedStructure, setSelectedStructure] = useState(null);

const handleStructureClick = (structureName) => {
setSelectedStructure(structureName);
};
setSelectedStructure(planetId); // Set selectedStructure to planetId
};

const handleClosePopup = () => {
setSelectedStructure(null);
Expand Down Expand Up @@ -431,7 +431,12 @@ export function IndividualBasePlanetDesktop({ id }: { id: string }) {
>
Close
</button>
<LightkurveBaseGraph planetId={selectedStructure} />
{!planetData?.lightkurve && (
<LightkurveBaseGraph planetId={{ planetId: id }} />
)}
{planetData?.lightkurve && (
<img src={planetData?.lightkurve} />
)}
</div>
</div>
)}
Expand Down
12 changes: 9 additions & 3 deletions components/Content/Planets/PlanetData/ContentPlaceholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ export function ActivateButton(planetIdDeepnote) {
);
}

export function LightkurveBaseGraph(planetId) {
export function LightkurveBaseGraph({ planetId }: { planetId: { planetId: string } }) {
const supabase = useSupabaseClient();

const [planetData, setPlanetData] = useState(null);

// Extract the planetId from the object
const extractedPlanetId = planetId.planetId;

useEffect(() => {
console.log("planetId:", extractedPlanetId); // Check the value of extractedPlanetId
}, [extractedPlanetId]);

// const { content, avatar_url, type, deepnote, cover, temperatureEq, smaxis, mass } = planetData;

return (
Expand All @@ -104,7 +110,7 @@ export function LightkurveBaseGraph(planetId) {

<div className="text-gray-700">
<div className="pt-10">
<LightcurveGenerator planetId={planetId} />
<LightcurveGenerator planetId={extractedPlanetId} />
</div>
</div>
</div>
Expand Down
31 changes: 27 additions & 4 deletions components/Content/Planets/PlanetData/PopulatePlanetData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,52 @@ import React, { useState } from "react";
import axios from "axios";
import { useSupabaseClient } from "@supabase/auth-helpers-react";

// LightcurveGenerator component
const LightcurveGenerator = ({ planetId }: { planetId: string }) => {
const supabase = useSupabaseClient();

const [planetData, setPlanetData] = useState(null);
const [ticId, setTicId] = useState('');
const [imageURL, setImageUrl] = useState('');

const handleSubmit = async (e) => {
e.preventDefault();

try {
const response = await axios.post('http://127.0.0.1:5000/generate_lightcurve_image', {
tic_id: ticId,
}, { responseType: 'arraybuffer' });
const blob = new Blob([response.data], { type: 'image/png' });
const url = URL.createObjectURL(blob);
setImageUrl(url);

// Convert planetId to string before constructing the file name
const fileName = `_${Date.now()}`;

// Upload the image to Supabase storage
const result = await supabase.storage
.from('planetsss')
.upload(fileName, blob);

if (result.data) {
// If upload successful, get the URL of the uploaded image
const imageURL = process.env.NEXT_PUBLIC_SUPABASE_URL + '/storage/v1/object/public/planetsss/' + result.data.path;

// Update the 'lightkurve' column in the 'basePlanets' table with the image URL
console.log("planetId:", planetId); // Check the value of planetId
await supabase
.from('basePlanets')
.update({ lightkurve: imageURL })
.eq('id', parseInt(planetId)); // Ensure planetId is parsed as integer

// Set the image URL to display the generated image
setImageUrl(url);
} else {
console.log("Error uploading image to Supabase.");
}
} catch (error) {
console.error(error.message);
};
};


return (
<div>
<form onSubmit={handleSubmit}>
Expand Down

0 comments on commit 84c17bb

Please sign in to comment.