-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
πΉπ«₯ β Merge pull request #86 from Signal-K/FCDB-20
ππΉ β Complete read-access for Star Sailors data
- Loading branch information
Showing
10 changed files
with
346 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react"; | ||
|
||
interface Spaceship { | ||
id: number; | ||
name: string; | ||
image: string; | ||
hp: number; | ||
speed: number; | ||
attack: number; | ||
state: string; | ||
current_planet: string; | ||
}; | ||
|
||
const MySpaceships: React.FC = () => { | ||
const supabase = useSupabaseClient(); | ||
const session = useSession(); | ||
|
||
const [userSpaceships, setUserSpaceships] = useState<any[]>([]); | ||
|
||
useEffect(() => { | ||
const fetchUserSpaceships = async () => { | ||
if (session?.user) { | ||
const { data: userSpaceshipsData, error: userSpaceshipsError } = await supabase | ||
.from("inventorySPACESHIPS") | ||
.select("*") | ||
.eq("owner", session.user.id); | ||
|
||
if (userSpaceshipsError) { | ||
console.error("Error fetching user's spaceships:", userSpaceshipsError); | ||
} else { | ||
const spaceshipIds = userSpaceshipsData.map((userSpaceship) => userSpaceship.spaceship_id); | ||
|
||
const { data: spaceshipsData, error: spaceshipsError } = await supabase | ||
.from("spaceships") | ||
.select("*") | ||
.in("id", spaceshipIds); | ||
|
||
if (spaceshipsError) { | ||
console.error("Error fetching spaceship details:", spaceshipsError); | ||
} else { | ||
const combinedData = userSpaceshipsData.map((userSpaceship) => { | ||
const matchingSpaceship = spaceshipsData.find((spaceship) => spaceship.id === userSpaceship.spaceship_id); | ||
return { | ||
...userSpaceship, | ||
spaceship: matchingSpaceship, | ||
}; | ||
}); | ||
|
||
setUserSpaceships(combinedData); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
fetchUserSpaceships(); | ||
}, [session, supabase]); | ||
|
||
return ( | ||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4"> | ||
{userSpaceships.map((userSpaceship) => ( | ||
<div key={userSpaceship.id} className="bg-white p-4 rounded-lg shadow-md"> | ||
<h2 className="text-lg font-semibold"> | ||
{userSpaceship.spaceship?.name || "N/A"} {/* Handle potential null/undefined */} | ||
</h2> | ||
<img | ||
src={userSpaceship.spaceship?.image || ""} | ||
alt={userSpaceship.spaceship?.name || ""} | ||
className="mt-2 w-full h-40 object-cover" | ||
/> | ||
<p className="text-sm mt-2"> | ||
HP: {userSpaceship.spaceship?.hp || 0}, Speed: {userSpaceship.spaceship?.speed || 0}, Attack:{" "} | ||
{userSpaceship.spaceship?.attack || 0} | ||
</p> | ||
<p className="text-sm mt-2"> | ||
State: {userSpaceship.spaceship?.state || "N/A"}, Current Planet:{" "} | ||
{userSpaceship.spaceship?.current_planet || "N/A"} | ||
</p> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MySpaceships; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
|
||
interface Sector { | ||
id: number; | ||
metadata: string; | ||
}; | ||
|
||
interface PlanetSectorsProps { | ||
sectors: Sector[]; | ||
} | ||
|
||
const PlanetSector: React.FC<PlanetSectorsProps> = ({ sectors }) => { | ||
return ( | ||
<div className="sector-container"> | ||
{sectors.map((sector, index) => ( | ||
<div key={index} className="sector"> | ||
<div className="sector-number">{index + 1}</div> | ||
<div className="sector-metadata">{sector.metadata}</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PlanetSector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import axios from 'axios'; | ||
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react"; | ||
import RoverImageCard from "./RoverImageCard"; | ||
import { Form } from "react-hook-form"; | ||
|
||
const RoverImage = ({ date, rover }) => { | ||
const [imageUrl, setImageUrl] = useState(''); | ||
const apiKey = "iT0FQTZKpvadCGPzerqXdO5F4b62arNBOP0dtkXE" | ||
|
||
useEffect(() => { | ||
const apiUrl = `https://api.nasa.gov/mars-photos/api/v1/rovers/${rover}/photos?sol=${date}&api_key=${apiKey}`; | ||
axios.get(apiUrl) | ||
.then((response) => { | ||
if (response.data.photos && response.data.photos.length > 0) { | ||
const firstImage = response.data.photos[0].img_src; | ||
setImageUrl(firstImage); | ||
} else { | ||
setImageUrl("No images found for the given date and rover"); | ||
} | ||
}) | ||
.catch((error) => { | ||
setImageUrl(''); | ||
console.error(error); | ||
}); | ||
}, [date, rover]); | ||
|
||
return ( | ||
<div> | ||
<h2>Mars Rover Photo</h2> | ||
<p>Date: {date}</p> | ||
<p>Rover: {rover}</p> | ||
<img src={imageUrl} alt="Mars Rover" /> | ||
</div> | ||
); | ||
}; | ||
|
||
const RoverImagePage = () => { | ||
const randomDate = Math.floor(Math.random() * 1000); | ||
const selectedRover = 'perseverance'; | ||
|
||
return ( | ||
<div> | ||
<h1>Mars Rover Image</h1> | ||
<RoverImage date={randomDate} rover={selectedRover} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export function RoverGallerySingle({ inventoryPlanetId }) { | ||
const supabase = useSupabaseClient(); | ||
const session = useSession(); | ||
|
||
const [roverImage, setRoverImage] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const [metadata, setMetadata] = useState(''); | ||
const [imageMetadata, setImageMetadata] = useState(''); | ||
const [content, setContent] = useState(''); | ||
|
||
const fetchImage = async () => { | ||
const randomDate = Math.floor(Math.random() * 1000) + 1; | ||
const selectedRover = 'perseverance'; // You can change this to 'curiosity' or 'opportunity' as needed | ||
const apiUrl = `https://api.nasa.gov/mars-photos/api/v1/rovers/${selectedRover}/photos?sol=${randomDate}&api_key=iT0FQTZKpvadCGPzerqXdO5F4b62arNBOP0dtkXE`; | ||
|
||
try { | ||
const response = await axios.get(apiUrl); | ||
if (response.data.photos && response.data.photos.length > 0) { | ||
const firstImage = response.data.photos[0].img_src; | ||
setRoverImage(firstImage); | ||
|
||
// Set metadata from the fetched image | ||
const metadataText = JSON.stringify(response.data.photos[0], null, 2); | ||
setImageMetadata(metadataText); | ||
setMetadata('Metadata for the current image:'); | ||
} else { | ||
setRoverImage('No images found for the given date and rover.'); | ||
setMetadata('No image available.'); | ||
setImageMetadata(''); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
setRoverImage('An error occurred while fetching the image.'); | ||
setMetadata('Error fetching the image.'); | ||
setImageMetadata(''); | ||
} | ||
|
||
setLoading(false); // Set loading to false when the image is loaded | ||
}; | ||
|
||
const generateNewImage = () => { | ||
setLoading(true); | ||
fetchImage(); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchImage(); | ||
}, []); | ||
|
||
const handlePostSubmit = async () => { | ||
if (content) { | ||
const user = session?.user?.id; | ||
if (user) { | ||
const response = await supabase.from('contentROVERIMAGES').upsert([ | ||
{ | ||
author: user, | ||
metadata: imageMetadata, | ||
imageLink: roverImage, | ||
planet: inventoryPlanetId, | ||
content, | ||
media: null, | ||
}, | ||
]); | ||
|
||
if (response.error) { | ||
console.error(response.error); | ||
} else { | ||
setContent(''); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<RoverImageCard roverImage={{ id: '1', content: '', image: roverImage, planets2: '' }} /> // Form components to be placed in | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
interface Props { | ||
roverImage: { | ||
id: string; | ||
content: string; | ||
image: string; | ||
planets2: string; | ||
}; | ||
}; | ||
|
||
export default function RoverImageCard({ roverImage }: Props) { | ||
const { id, content, image, planets2 } = roverImage; | ||
return ( | ||
<div className="col-md-4 mb-4"> | ||
<div style={{ width: '100%', height: "200px", overflow: "hidden" }}> | ||
<img | ||
src={image} | ||
alt="Rover Image" | ||
className="w-100 h-auto" | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.