Skip to content

Commit 033b532

Browse files
committed
️🚡🛰️ ↝ [SSM-179]: PlanetHunters Density calculator integrated into Post Card
1 parent 9c4a001 commit 033b532

File tree

9 files changed

+167
-70
lines changed

9 files changed

+167
-70
lines changed

app/research/page.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use client';
2+
3+
import GameNavbar from "@/components/Layout/Tes";
4+
import TotalPoints from "@/components/Structures/Missions/Stardust/Total";
5+
import { AdvancedTechTreeComponent } from "@/components/Structures/Research/OldTechTree";
6+
import { Button } from "@/components/ui/button";
7+
import MySettlementsLocations from "@/content/Classifications/UserLocations";
8+
import React, { useEffect, useState } from "react";
9+
10+
export default function TechTreeResearchPage() {
11+
return (
12+
<div className="relative w-full py-10 bg-black text-white">
13+
<GameNavbar />
14+
Available: <TotalPoints />
15+
<h2 className="text-lg text-white">Available upgrades</h2>
16+
<h3 className="text-md text-white">Astronomy</h3>
17+
<Button
18+
variant='ghost'
19+
>
20+
Probecount ++
21+
</Button>
22+
<h3 className="text-md text-white">Meteorology</h3>
23+
<Button
24+
variant='ghost'
25+
>
26+
Probecount ++
27+
</Button>
28+
<h3 className="text-md text-white">Biology</h3>
29+
<Button
30+
variant='ghost'
31+
>
32+
Cameracount++
33+
</Button>
34+
<Button
35+
variant='ghost'
36+
>
37+
Station Count - select [show available/ready]
38+
</Button>
39+
<h2 className="text-lg text-white">[temporarily] Unavailable upgrades</h2>
40+
<h3 className="text-md text-white">Astronomy</h3>
41+
<Button
42+
variant='ghost'
43+
>
44+
Probedistance ++
45+
</Button>
46+
<h3 className="text-md text-white">Meteorology</h3>
47+
<MySettlementsLocations /> - Show weather balloons on Settlements
48+
<h3 className="text-md text-white">Biology</h3>
49+
<Button
50+
variant='ghost'
51+
>
52+
Heat/Motion Sensors ++
53+
</Button>
54+
{/* <AdvancedTechTreeComponent /> */}
55+
</div>
56+
);
57+
};

components/Layout/Navigation/MissionDropdown.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function MissionsPopover({
3535
<PopoverTrigger asChild>
3636
<Button variant="ghost" className="text-white px-2">
3737
<Trophy className="h-5 w-5 text-amber-400 group-hover:text-amber-300 transition-colors" />
38-
<span className="ml-2 text-white">Missions</span>
38+
<span className="ml-2 text-white">Milestones</span>
3939
<Badge className="ml-1 bg-amber-600 hover:bg-amber-600 text-white">3</Badge>
4040
</Button>
4141
</PopoverTrigger>
@@ -44,6 +44,9 @@ export function MissionsPopover({
4444
<h3 className="text-xl sm:text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-[#22d3ee] to-[#a855f7] mb-4">
4545
Weekly Milestones
4646
</h3>
47+
<p className="text-sm text-gray-500 mb-2">
48+
Use the points you earn from these milestones to unlock new tech & upgrade your structures
49+
</p>
4750
<div className="flex flex-wrap items-center justify-between mb-4 gap-2">
4851
<Button
4952
variant='outline'

components/Layout/Navigation/StardustDisplay.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import TotalPoints from "@/components/Structures/Missions/Stardust/Total";
2+
import { Button } from "@/components/ui/button";
3+
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
4+
import { Sparkle, Star, Trophy } from "lucide-react"
5+
6+
interface PointsDisplayProps {
7+
stardust: number
8+
achievements: number
9+
};
10+
11+
export function StardustDropdown() {
12+
return (
13+
<Popover>
14+
<PopoverTrigger asChild>
15+
<Button variant='ghost' className="relative group">
16+
<Star className="h-5 w-5 text-yellow-400 group-hover:text-yellow-300 transition-colors" />
17+
<span className="text-yellow-100 font-medium"><TotalPoints /></span>
18+
</Button>
19+
</PopoverTrigger>
20+
<PopoverContent className="w-80 p-0 bg-black/80 backdrop-blur-md border border-yellow-500/20">
21+
<div className="p-4 space-y-4">
22+
<h3 className="text-lg font-bold text-purple-400">
23+
Points breakdown
24+
</h3>
25+
</div>
26+
</PopoverContent>
27+
</Popover>
28+
);
29+
};

components/Layout/Tes.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Menu, Transition } from "@headlessui/react"
2424
import TotalPoints from "../Structures/Missions/Stardust/Total"
2525
import { MissionsPopover } from "./Navigation/MissionDropdown"
2626
import AlertsDropdown from "./Navigation/AlertsDropdown"
27+
import { StardustDropdown } from "./Navigation/StardustDropdown"
2728

2829
// Sample data - replace with actual data in your implementation
2930
const techTree = [
@@ -277,10 +278,7 @@ export default function GameNavbar() {
277278
{/* Desktop Navigation */}
278279
<div className="hidden md:flex items-center space-x-4">
279280
{/* Stardust Balance */}
280-
<div className="flex items-center bg-white/5 rounded-full px-3 py-1 border border-yellow-500/30">
281-
<Star className="h-4 w-4 text-yellow-400 mr-1" />
282-
<span className="text-yellow-100 font-medium"><TotalPoints /></span>
283-
</div>
281+
<StardustDropdown />
284282

285283
<MissionsPopover
286284
userProgress={userProgress}

components/Structures/Missions/Milestones/Alerts/Alerts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const AlertComponent = () => {
8686
setAlertMessage(message);
8787
} else {
8888
setAlertMessage("You've completed all classification goals this week!");
89-
}
89+
};
9090
};
9191

9292
fetchAlert();

components/Structures/Missions/Stardust/Total.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const TotalPoints: React.FC<TotalPointsProps> = ({ onPointsUpdate, onExport }) =
5656
.eq("author", userId);
5757
total += count || 0;
5858
}
59-
59+
6060
setMilestonePoints(total);
6161
} catch (error) {
6262
console.error("Error fetching milestone points:", error);

content/Classifications/UserLocations.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ClassificationConfiguration {
1515
};
1616
temperature?: string;
1717
parentPlanetLocation?: number;
18-
}
18+
};
1919

2020
interface Classification {
2121
author: string;
@@ -29,7 +29,7 @@ interface Classification {
2929
images?: string[];
3030
anomalyContent?: string;
3131
relatedClassifications?: Classification[];
32-
}
32+
};
3333

3434
export default function MySettlementsLocations() {
3535
const supabase = useSupabaseClient();

content/Posts/TestPostCard.tsx

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ export default function PostCard({
6666

6767
return { radius: radius.toFixed(2), planetType };
6868
};
69+
70+
const calculatePlanetDensity = (stellarRadius: string, fluxDifferential: string) => {
71+
const R_star = parseFloat(stellarRadius);
72+
const deltaF = parseFloat(fluxDifferential);
73+
74+
if (isNaN(R_star) || isNaN(deltaF) || deltaF <= 0) {
75+
return { density: "", unit: "kg/m³" };
76+
}
77+
78+
const K = 0.414; // empirical constant for gas giants
79+
const alpha = 2.06;
80+
const pi = Math.PI;
81+
82+
const M_earth = 5.972e24; // kg
83+
const R_earth = 6.371e6; // m
84+
const R_sun = 6.957e8; // m
85+
86+
const Rp_solar = R_star * Math.sqrt(deltaF);
87+
const Rp_meters = Rp_solar * R_sun;
88+
const mass_earth = K * Math.pow((Rp_meters / R_earth), alpha);
89+
const mass_kg = mass_earth * M_earth;
90+
const volume = (4 / 3) * pi * Math.pow(Rp_meters, 3);
91+
const density = mass_kg / volume;
92+
93+
return { density: density.toFixed(2), unit: "kg/m³" };
94+
};
6995

7096
const handleRadiusInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
7197
const value = e.target.value;
@@ -249,7 +275,45 @@ export default function PostCard({
249275
fetchComments();
250276
} catch (error: any) {
251277
console.error("Error inserting comment: ", error);
252-
}
278+
};
279+
};
280+
281+
const handleAddDensityComment = async () => {
282+
const densityInput1 = densityInputs[`${classificationId}-1`];
283+
const densityInput2 = densityInputs[`${classificationId}-2`];
284+
285+
if (!densityInput1?.trim() || !densityInput2?.trim()) {
286+
console.error("Both text areas must be filled");
287+
return;
288+
};
289+
290+
try {
291+
const { error } = await supabase
292+
.from("comments")
293+
.insert([
294+
{
295+
content: `${densityInput1}\n\n${densityInput2}`,
296+
classification_id: classificationId,
297+
author: session?.user?.id,
298+
configuration: { density: `${densityInput2}` },
299+
surveyor: "TRUE",
300+
value: densityInput2,
301+
category: "Density",
302+
},
303+
]);
304+
305+
if (error) throw error;
306+
307+
setDensityInputs((prev) => ({
308+
...prev,
309+
[`${classificationId}-1`]: "",
310+
[`${classificationId}-2`]: "",
311+
}));
312+
313+
fetchComments();
314+
} catch (error) {
315+
console.error("Error adding density comment:", error);
316+
};
253317
};
254318

255319
const handleAddTemperatureComment = async () => {
@@ -283,6 +347,7 @@ export default function PostCard({
283347
[`${classificationId}-1`]: "",
284348
[`${classificationId}-2`]: "",
285349
}));
350+
286351
fetchComments();
287352
} catch (error) {
288353
console.error("Error adding temperature comment:", error);
@@ -324,45 +389,6 @@ export default function PostCard({
324389
console.error("Error inserting comment: ", error);
325390
};
326391
};
327-
328-
const handleAddDensityComment = async () => {
329-
const densityInput1 = densityInputs[`${classificationId}-1`];
330-
const densityInput2 = densityInputs[`${classificationId}-2`];
331-
332-
if (!densityInput1?.trim() || !densityInput2?.trim()) {
333-
console.error("Both text areas must be filled");
334-
return;
335-
}
336-
337-
try {
338-
const { error } = await supabase
339-
.from("comments")
340-
.insert([
341-
{
342-
content: `${densityInput1}\n\n${densityInput2}`,
343-
classification_id: classificationId,
344-
author: session?.user?.id,
345-
configuration: { density: `${densityInput1}, ${densityInput2}` },
346-
surveyor: "TRUE",
347-
value: densityInput2,
348-
category: "Density",
349-
},
350-
]);
351-
352-
if (error) throw error;
353-
354-
setDensityInputs((prev) => ({
355-
...prev,
356-
[`${classificationId}-1`]: "",
357-
[`${classificationId}-2`]: "",
358-
}));
359-
360-
fetchComments();
361-
} catch (error) {
362-
console.error("Error adding density comment:", error);
363-
};
364-
};
365-
366392
// For sharing
367393
const [dropdownOpen, setDropdownOpen] = useState<boolean>(false);
368394
const dropdownRef = useRef<HTMLDivElement | null>(null);
@@ -602,6 +628,9 @@ export default function PostCard({
602628
<SelectItem value="period" className="focus:bg-[#1e2834] focus:text-black">
603629
Planet Orbital Period
604630
</SelectItem>
631+
<SelectItem value="density" className="focus:bg-[#1e2834] focus:text-black">
632+
Planet Density
633+
</SelectItem>
605634
</SelectContent>
606635
</Select>
607636

@@ -730,6 +759,8 @@ export default function PostCard({
730759
? handleAddTemperatureComment
731760
: selectedCalculator === "radius"
732761
? handleAddRadiusComment
762+
: selectedCalculator === "density"
763+
? handleAddDensityComment
733764
: selectedCalculator === 'period'
734765
? handleAddPeriodComment
735766
: handleAddComment

0 commit comments

Comments
 (0)