Skip to content

Commit

Permalink
💉🪮 ↝ [SSP-37 SSG-78 SSC-45 SSC-43]: General bug fixing attempts and d…
Browse files Browse the repository at this point in the history
…iscovery
  • Loading branch information
Gizmotronn committed Dec 4, 2024
1 parent 9300aac commit e84fc15
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ChevronLeft, ChevronRight } from 'lucide-react';

interface DiscoveryCardsByClassificationTypeProps {
classificationtype: string;
};
};

export function DiscoveryCardsByClassificationType({ classificationtype }: DiscoveryCardsByClassificationTypeProps) {
const supabase = useSupabaseClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro

setClassification(data);

// Get total votes from classificationConfiguration
const totalVotes = data?.classificationConfiguration?.votes || 0;
setVoteCount(totalVotes);

Expand All @@ -93,7 +92,6 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
setAnomaly(anomalyData);
}

// Fetch user's individual vote from the votes table
const { data: voteData } = await supabase
.from('votes')
.select('vote')
Expand All @@ -119,45 +117,36 @@ export function DiscoveryCardSingle({ classificationId }: DiscoveryCardSinglePro
if (!user) return alert('Please log in to vote');

try {
// Only allow voting if the user hasn't already voted
if (userVote !== null) {
return;
}

// Step 1: Insert a new row into the 'votes' table
if (userVote !== null) return; // Prevent duplicate votes

const { data: voteData, error: voteError } = await supabase
.from('votes')
.insert({
user_id: user.id,
classification_id: classification.id,
anomaly_id: classification.anomaly,
vote: 1,
classification_id: classification?.id || null,
anomaly_id: classification?.anomaly || null,
vote: 1,
});

if (voteError) throw voteError;

// Step 2: Increment the vote count in classificationConfiguration.votes

const updatedVotes = (classification.classificationConfiguration?.votes || 0) + 1;

const updatedConfiguration = {
...classification.classificationConfiguration,
votes: updatedVotes,
votes: updatedVotes,
};

const { data: updateData, error: updateError } = await supabase
const { error: updateError } = await supabase
.from('classifications')
.update({
classificationConfiguration: updatedConfiguration,
})
.update({ classificationConfiguration: updatedConfiguration })
.eq('id', classification.id);

if (updateError) throw updateError;

// Step 3: Update the UI

setVoteCount(updatedVotes);
setUserVote(1);
setUserVote(1);
setClassification({ ...classification, classificationConfiguration: updatedConfiguration });

} catch (error) {
console.error('Error updating vote:', error);
}
Expand Down
16 changes: 16 additions & 0 deletions components/Projects/(classifications)/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
PlanetFourOptions,
jvhOptions,
} from "@/content/Classifications/Options";
import { useRouter } from "next/navigation";
import { Button } from "antd";
import Link from "next/link";
// import UserAvatar, { UserAvatarNullUpload } from "@/components/Profile/Avatar";

interface ClassificationFormProps {
Expand Down Expand Up @@ -60,6 +63,8 @@ const ClassificationForm: React.FC<ClassificationFormProps> = ({
const [uses, setUses] = useState<number | null>(null);
const [postSubmitted, setPostSubmitted] = useState<boolean>(false);

const router = useRouter();

const placeholder = (() => {
switch (anomalyType) {
case "planet":
Expand Down Expand Up @@ -316,6 +321,7 @@ const ClassificationForm: React.FC<ClassificationFormProps> = ({
.eq("id", session?.user?.id);

if (updatePointsError) throw updatePointsError;
router.refresh();
} catch (error: any) {
console.error("Unexpected error:", error);
}
Expand All @@ -327,6 +333,16 @@ const ClassificationForm: React.FC<ClassificationFormProps> = ({
setShowModal(false);
};

if (postSubmitted) {
<Button
className="bg-[#5FCBC3] text-[#2E3440] rounded-md hover:bg-[#85DDA2]"
>
<Link href='/'>
Return
</Link>
</Button>
}

// if (postSubmitted && showResearch) {
// return (
// {showModal && <IntroduceUserToResearch closeModal={closeModal} />}
Expand Down
40 changes: 25 additions & 15 deletions components/Projects/Telescopes/Transiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,34 @@ export function StarterTelescope() {
const [hasMission3000001, setHasMission3000001] = useState<boolean | null>(null);
const [missionLoading, setMissionLoading] = useState<boolean>(true);

// Check tutorial mission
useEffect(() => {
const checkTutorialMission = async () => {
if (!session) return;

if (!session) return;
try {
const { data: missionData, error: missionError } = await supabase
.from('missions')
.select('id')
.eq('user', session.user.id)
.eq('mission', 3000001) // Changed to ensure integer comparison
.single();

.eq('mission', 3000001);

if (missionError) throw missionError;

// Log mission data and error for debugging
console.log({ missionData, missionError });

// Check if missionData contains valid data
setHasMission3000001(!!missionData?.id);
// 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);
setHasMission3000001(false);
} finally {
setMissionLoading(false);
};
}
};

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

// Fetch structure configuration
useEffect(() => {
Expand Down Expand Up @@ -198,6 +196,18 @@ export function StarterTelescope() {
);
};

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

if (!hasMission3000001) {
return (
<div>
<FirstTelescopeClassification anomalyid={"6"} />
</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">
Expand Down
14 changes: 7 additions & 7 deletions constants/Structures/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ export const StructuresConfig: StructureConfig = {
// Copy action/labels
],
buttons: [
// {
// icon: <TelescopeIcon className="w-6 h-6 text-[#5e81ac]" />,
// text: "Discover planets", // Transit events, microlensing, etc
// dynamicComponent: <StarterTelescope />,
// sizePercentage: 60,
// showInNoModal: true,
// },
{
icon: <TelescopeIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Discover planets", // Transit events, microlensing, etc
dynamicComponent: <StarterTelescope />,
sizePercentage: 60,
showInNoModal: true,
},
{
icon: <EarthIcon className="w-6 h-6 text-[#5e81ac]" />,
text: "Find new worlds",
Expand Down
6 changes: 2 additions & 4 deletions content/Posts/Uploads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Uploads() {
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
const [newComment, setNewComment] = useState<string>("");
const [voteCounts, setVoteCounts] = useState<{ [uploadId: number]: number }>({}); // State to store vote counts for each upload
const [voteCounts, setVoteCounts] = useState<{ [uploadId: number]: number }>({});

// Function to fetch uploads
const fetchUploads = () => {
Expand Down Expand Up @@ -58,7 +58,6 @@ export default function Uploads() {
});
};

// Function to fetch vote count for a specific upload
const fetchVotesCount = (uploadId: number) => {
return supabase
.from("votes")
Expand All @@ -78,13 +77,12 @@ export default function Uploads() {
const handleVote = (uploadId: number) => {
if (!session?.user) return;

// Insert a new vote into the 'votes' table
supabase
.from("votes")
.insert([
{
upload: uploadId,
user_id: session.user.id, // Associate the vote with the current user
user_id: session.user.id,
},
])
.then((result) => {
Expand Down

0 comments on commit e84fc15

Please sign in to comment.