Skip to content

Commit

Permalink
💫🧑🏽‍🔧 ↝ [SSG-39 SSG-40 SSG-41 SSG-43 SSG-44]: UI improvements (toward…
Browse files Browse the repository at this point in the history
…s the end of sprint)
  • Loading branch information
Gizmotronn committed Oct 18, 2024
1 parent 5c958c4 commit 54526eb
Show file tree
Hide file tree
Showing 25 changed files with 416 additions and 479 deletions.
1 change: 0 additions & 1 deletion app/scenes/mining/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum Step {
export default function Mining() {
return (
<main className="container mx-auto px-4 py-8 relative z-10">
<h1 className="text-5xl font-bold text-center mb-12 text-[#F7F5E9]">Mining UI</h1>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">

</div>
Expand Down
1 change: 0 additions & 1 deletion app/scenes/travel/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SwitchPlanet from "@/components/(scenes)/travel/SolarSystem";
export default function Travel() {
return (
<main className="container mx-auto px-4 py-6 relative z-8">
<h1 className="text-5xl font-bold text-center mb-12 text-[#F7F5E9]">Travel UI</h1>
<center><SwitchPlanet /></center>
</main>
)
Expand Down
6 changes: 3 additions & 3 deletions app/tests/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import MissionPathway from "@/components/Missions/Pathway";

export default function TestPage() {
return (
<div className="1">
<MissionPathway />
</div>
<div className="1">
<MissionPathway />
</div>
);
};
42 changes: 22 additions & 20 deletions components/(scenes)/travel/SolarSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Star, MapPin, Clock, ThermometerSun, Users, ChevronLeft, ChevronRight }
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
import { useActivePlanet } from "@/context/ActivePlanet";
import { lidarDataSources, physicsLabDataSources, roverDataSources, telescopeDataSources, zoodexDataSources } from "@/components/Data/ZoodexDataSources";
import InventoryList from "@/components/Inventory/items/ItemsOnPlanet";

type Exoplanet = {
id: number;
Expand Down Expand Up @@ -165,7 +166,6 @@ export default function SwitchPlanet() {
useEffect(() => {
const fetchExoplanets = async () => {
try {
// Fetch all exoplanets from the anomalies table where anomalySet is 'tess'
const { data: exoplanetData, error: exoplanetError } = await supabase
.from("anomalies")
.select("*")
Expand All @@ -175,7 +175,6 @@ export default function SwitchPlanet() {
if (exoplanetError) throw exoplanetError;

if (session?.user?.id) {
// Fetch classifications where author is the current user and anomaly is one of the exoplanets
const { data: classificationData, error: classificationError } = await supabase
.from("classifications")
.select("anomaly")
Expand All @@ -187,10 +186,8 @@ export default function SwitchPlanet() {

if (classificationError) throw classificationError;

// Extract anomaly IDs (exoplanet IDs) mentioned in classifications
const classifiedExoplanetIds = classificationData.map((classification) => classification.anomaly);

// Filter exoplanets based on classified exoplanet IDs
const filteredExoplanets = exoplanetData
.filter((exoplanet) => classifiedExoplanetIds.includes(exoplanet.id))
.map((exoplanet) => ({
Expand All @@ -199,22 +196,21 @@ export default function SwitchPlanet() {
color: "bg-purple-500",
stats: { gravity: "Unknown", temp: "Unknown" },
anomaly: exoplanet.id,
planetType: "Frozen", // Set default planet type as Frozen
planetType: "Frozen",
initialisationMissionId: null,
travelTime: "Unknown",
description: exoplanet.deepnote || "No description available",
image: exoplanet.avatar_url || '/assets/Planets/DefaultExoplanet.png',
}));

// Update state with the filtered exoplanets
setPlanets((prevState) => ({
...prevState,
exoplanets: filteredExoplanets as unknown as Exoplanet[],
}));
}
};
} catch (error: any) {
console.error("Error fetching exoplanets: ", error.message);
}
};
};

fetchExoplanets();
Expand Down Expand Up @@ -244,7 +240,7 @@ export default function SwitchPlanet() {
setVisitedPlanets(visited);
} catch (error: any) {
console.error("Error fetching visited planets: ", error.message);
}
};
};

const fetchPlanetStats = async () => {
Expand All @@ -254,7 +250,7 @@ export default function SwitchPlanet() {
setPlanetStats(data);
} catch (error) {
console.error("Error fetching planet stats:", error);
}
};
};

const fetchClassifications = async () => {
Expand Down Expand Up @@ -282,8 +278,8 @@ export default function SwitchPlanet() {
setClassificationsByPlanet(classificationsByPlanetTemp);
} catch (error: any) {
console.error("Error fetching classifications:", error.message);
}
}
};
};
};

const checkRocketInInventory = async () => {
Expand All @@ -301,8 +297,8 @@ export default function SwitchPlanet() {
setHasRocket(data.length > 0);
} catch (error: any) {
console.error("Error checking inventory:", error.message);
}
}
};
};
};

fetchVisitedPlanets();
Expand Down Expand Up @@ -341,7 +337,7 @@ export default function SwitchPlanet() {
};

filterCompatibleMissions();
}
};
}, [currentPlanet]);

const nextPlanet = () => {
Expand Down Expand Up @@ -381,7 +377,7 @@ export default function SwitchPlanet() {
if (missionsError) {
console.error("Error inserting mission data:", missionsError);
return;
}
};

if (selectedMission?.activeStructure) {
const structureId = selectedMission.activeStructure;
Expand Down Expand Up @@ -442,15 +438,15 @@ export default function SwitchPlanet() {
if (updateError) {
console.error("Error updating inventory configuration:", updateError);
return;
}
}
}
};
};
};

const validAnomaly = currentPlanet?.anomaly ?? 0;

await moveItemsToNewPlanet(validAnomaly);
updatePlanetLocation(validAnomaly);
}
};
};

const [missionSelected, setMissionSelected] = useState<boolean>(false);
Expand Down Expand Up @@ -581,6 +577,12 @@ export default function SwitchPlanet() {
</button>
</div>
)}

{!missionSelected && (
<div className="p-4">
<InventoryList anomaly={currentPlanetAnomaly} />
</div>
)}
</div>
</motion.div>
)}
Expand Down
102 changes: 102 additions & 0 deletions components/Inventory/items/ItemsOnPlanet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useEffect, useState } from 'react';
import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react';

interface InventoryItem {
id: number;
name: string;
description: string;
icon_url: string;
ItemCategory: string;
}

interface SupabaseInventoryItem {
id: number;
item: number;
owner: string;
quantity: number;
anomaly: number;
};

interface InventoryListProps {
anomaly: number;
}

const InventoryList = ({ anomaly }: InventoryListProps) => {
const supabase = useSupabaseClient();
const session = useSession();

const [inventoryItems, setInventoryItems] = useState<InventoryItem[]>([]);
const [filteredItems, setFilteredItems] = useState<SupabaseInventoryItem[]>([]);

useEffect(() => {
const fetchInventoryItems = async () => {
try {
const response = await fetch('/api/gameplay/inventory');
const items = await response.json();
setInventoryItems(items);
} catch (error) {
console.error('Error fetching inventory items from API:', error);
};
};

fetchInventoryItems();
}, []);

useEffect(() => {
if (session?.user?.id && anomaly !== null) {
const fetchFilteredInventory = async () => {
try {
const { data: inventoryData, error } = await supabase
.from('inventory')
.select('*')
.eq('owner', session.user.id)
.eq('anomaly', anomaly)
.not('item', 'lte', 100);

if (error) {
console.error('Error fetching from Supabase:', error);
return;
};

const ownedItems = inventoryData?.filter((inventoryItem: SupabaseInventoryItem) =>
inventoryItems.some((apiItem) =>
apiItem.id === inventoryItem.item &&
(apiItem.ItemCategory === 'Structure' || apiItem.ItemCategory === 'Automaton')
)
);

setFilteredItems(ownedItems || []);
} catch (error) {
console.error('Error fetching filtered inventory:', error);
};
};

fetchFilteredInventory();
}
}, [anomaly, session, supabase, inventoryItems]);

if (!session?.user) {
return <p>Please log in to view your inventory.</p>;
};

return (
<div className="grid grid-cols-3 gap-4">
{filteredItems.length > 0 ? (
filteredItems.map((item) => {
const apiItem = inventoryItems.find(apiItem => apiItem.id === item.item);
return (
<div key={item.id} className="flex flex-col items-center p-4 border rounded">
<img src={apiItem?.icon_url || '/default-icon.png'} alt={apiItem?.name || 'Item'} className="w-16 h-16 mb-2" />
<h3 className="text-lg font-bold">{apiItem?.name || 'Unknown Item'}</h3>
<p>{apiItem?.description || 'No description available'}</p>
</div>
);
})
) : (
<p>No items found for this anomaly.</p>
)}
</div>
);
};

export default InventoryList;
4 changes: 2 additions & 2 deletions components/Projects/Auto/AI4Mars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function StarterAiForMars({ anomalyid }: Props) {
};

const tutorialContent = (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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 bg-[#2C3A4A] border border-[#85DDA2] rounded-md shadow-md relative w-full">
<div className="relative">
<div className="absolute top-1/2 left-[-16px] transform -translate-y-1/2 w-0 h-0 border-t-8 border-t-[#2C3A4A] border-r-8 border-r-transparent"></div>
Expand Down Expand Up @@ -226,7 +226,7 @@ export function AiForMarsProject() {
};

return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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">
{imageUrl && (
<img src={imageUrl} alt="Anomaly" className="w-64 h-64 contained" />
Expand Down
4 changes: 2 additions & 2 deletions components/Projects/Lidar/Clouds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function StarterLidar() {
</div>
);
};

if (!anomaly) {
return (
<div>
Expand All @@ -125,7 +125,7 @@ export function StarterLidar() {
};

return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg overflow-y-auto max-h-[90vh]">
<div className="p-4 rounded-md relative w-full">
{imageUrl && (
<img src={imageUrl} alt={anomaly.content} className="w-full h-64 object-cover" />
Expand Down
6 changes: 3 additions & 3 deletions components/Projects/Lidar/cloudspottingOnMars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const CloudspottingOnMars: React.FC<LidarProps> = ({
const nextPart = () => {
setPart(2);
setLine(1);
};
};

const tutorialContent = (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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="flex items-center">
<img
src="/assets/Captn.jpg"
Expand Down Expand Up @@ -193,7 +193,7 @@ export const CloudspottingOnMars: React.FC<LidarProps> = ({
);

return (
<div className="rounded-lg">
<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="flex flex-col items-center">
{part === 1 && (
<div className="mb-2">
Expand Down
4 changes: 2 additions & 2 deletions components/Projects/Satellite/PlanetFour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function StarterPlanetFour({
};

const tutorialContent = (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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 bg-[#2C3A4A] border border-[#85DDA2] rounded-md shadow-md relative w-full">
<div className="relative">
<div className="absolute top-1/2 left-[-16px] transform -translate-y-1/2 w-0 h-0 border-t-8 border-t-[#2C3A4A] border-r-8 border-r-transparent"></div>
Expand Down Expand Up @@ -262,7 +262,7 @@ export function PlanetFourProject() {
};

return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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">
{imageUrl && (
<Card className="w-full max-w-3xl mx-auto">
Expand Down
4 changes: 2 additions & 2 deletions components/Projects/Telescopes/DailyMinorPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function StarterDailyMinorPlanet({
};

const tutorialContent = (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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 bg-[#2C3A4A] border border-[#85DDA2] rounded-md shadow-md relative w-full">
<div className="relative">
<div className="absolute top-1/2 left-[-16px] transform -translate-y-1/2 w-0 h-0 border-t-8 border-t-[#2C3A4A] border-r-8 border-r-transparent"></div>
Expand Down Expand Up @@ -251,7 +251,7 @@ export function DailyMinorPlanet() {
};

return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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">
{imageUrls.length > 0 && (
<div className="relative">
Expand Down
4 changes: 2 additions & 2 deletions components/Projects/Telescopes/DiskDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const DiskDetectorTutorial: React.FC<TelescopeProps> = ({
};

const tutorialContent = (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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="flex items-center">
<img
src="/assets/Captn.jpg"
Expand Down Expand Up @@ -319,7 +319,7 @@ export function TelescopeDiskDetector() {

// Render the tutorial or the main content based on the mission status
return (
<div className="flex flex-col items-start gap-4 pb-4 relative w-full max-w-lg">
<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">
{hasMission3000009 ? (
<div className="p-4 rounded-md relative w-full">
{imageUrl && (
Expand Down
Loading

0 comments on commit 54526eb

Please sign in to comment.