Skip to content

Commit

Permalink
completed the lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bduran04 committed Sep 17, 2024
1 parent e66c258 commit e0f13c6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 80 deletions.
6 changes: 3 additions & 3 deletions app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const Login: React.FC = () => {
container
justifyContent="center"
alignItems="center"
sx={{ minHeight: "calc(100vh - 64px - 100px)", backgroundColor: '#fbf7ef', padding: 2 }}
sx={{ minHeight: "calc(100vh - 64px - 100px)", backgroundColor: "#fbf7ef", padding: 2 }}
className="login"
>
<Box
sx={{ maxWidth: "400px", width: "100%", textAlign: 'center' }}
sx={{ maxWidth: "400px", width: "100%", textAlign: "center" }}
>
<Typography variant="h1" component="h1">
Hello!
Expand Down Expand Up @@ -97,7 +97,7 @@ const Login: React.FC = () => {
<Grid container direction="column" alignItems="center" sx={{ mb: 2 }}>
<Grid item>
<Link legacyBehavior href="/register" passHref>
<a style={{ color: "#2c2e33" }}>Don't have an account? Sign Up</a>
<a style={{ color: "#2c2e33" }}>Don&apos;st have an account? Sign Up</a>
</Link>
</Grid>
</Grid>
Expand Down
18 changes: 15 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ const HomePage: React.FC = () => {
Meet Math Solver
</Typography>
<Typography variant="h5" className="mt-2">
Your Personal Math Tutor - Anytime, Anywhere
Your Personal Math Tutor - Anytime, Anywhere
</Typography>
</Box>
</Grid>
{/* Right-hand side container for the image */}
<Grid item xs={12} sm={6} md={6} lg={6} className="flex items-center justify-center">
<Box className="p-4 flex justify-center items-center">
<img src={calculator.src} alt="Calculator" className="max-w-md h-auto object-contain" />
<Box
sx={{
p: 4,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
component="img"
src={calculator.src}
alt="Calculator"
sx={{ maxWidth: '100%', height: 'auto', objectFit: 'contain' }}
/>
</Box>
</Grid>
</Grid>
Expand Down
137 changes: 69 additions & 68 deletions app/study-guide/[equations]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,88 @@
"use client";

import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback } from "react";
import { useRouter } from "next/navigation";
import { Box, Typography, List, ListItem, ListItemText, CircularProgress, Button } from "@mui/material";
import { createClient } from "../../utils/supabase/client"; // Adjust the path as needed

interface Equations {
id: number;
title: string;
equation: string;
solution: string;
steps: string[];
id: number;
title: string;
equation: string;
solution: string;
steps: string[];
}

const Equations = ( { params }: { params: { equations: string } } ) => {
const studyGuide = params.equations
const [problems, setProblems] = useState<Equations[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const router = useRouter();
const supabase = createClient();
const Equations = ({ params }: { params: { equations: string } }) => {
const studyGuide = params.equations;
const [problems, setProblems] = useState<Equations[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const router = useRouter();
const supabase = createClient();

// Fetch the specific study guide's equations and details
const fetchEquationsDetails = async () => {
if (!studyGuide) return;
setLoading(true);
const { data, error } = await supabase
.from("study_guide")
.select("id, title, equation, solution, steps")
// Memoized fetchEquationsDetails function to avoid re-creation on every render
const fetchEquationsDetails = useCallback(async () => {
if (!studyGuide) return;
setLoading(true);
const { data, error } = await supabase
.from("study_guide")
.select("id, title, equation, solution, steps");

if (error) {
console.error("Error fetching study guide details:", error.message);
} else {
setProblems(data);
}
if (error) {
console.error("Error fetching study guide details:", error.message);
} else {
setProblems(data);
}

setLoading(false);
};
setLoading(false);
}, [studyGuide, supabase]); // Include 'studyGuide' and 'supabase' as dependencies

useEffect(() => {
fetchEquationsDetails();
}, [studyGuide]);
useEffect(() => {
fetchEquationsDetails();
}, [fetchEquationsDetails]); // Now safe to include fetchEquationsDetails in dependency array

// Go back to the list of study guides
const handleBackClick = () => {
router.push("/study-guide");
};
// Go back to the list of study guides
const handleBackClick = () => {
router.push("/study-guide");
};

return (
<Box sx={{ p: 4 }}>
<h1>
The study guide ID is <b>{studyGuide}</b>
</h1>
<Typography variant="h4" gutterBottom>
Study Guide Details
</Typography>
<Button variant="contained" onClick={handleBackClick} sx={{ mb: 2 }}>
Back to Study Guides
</Button>
return (
<Box sx={{ p: 4 }}>
<h1>
The study guide ID is <b>{studyGuide}</b>
</h1>
<Typography variant="h4" gutterBottom>
Study Guide Details
</Typography>
<Button variant="contained" onClick={handleBackClick} sx={{ mb: 2 }}>
Back to Study Guides
</Button>

{loading ? (
<CircularProgress />
) : problems.length > 0 ? (
<List>
{problems.map((problem) => (
<ListItem key={problem.id} sx={{ mb: 2, border: "1px solid #ccc", borderRadius: 1, p: 2 }}>
<ListItemText
primary={`Title: ${problem.title}`}
secondary={
<>
<Typography variant="body2">Equation: {problem.equation}</Typography>
<Typography variant="body2">Solution: {problem.solution}</Typography>
<Typography variant="body2">Steps: {problem.steps.join(", ")}</Typography>
</>
}
/>
</ListItem>
))}
</List>
) : (
<Typography>No equations found for this study guide.</Typography>
)}
</Box>
);
{loading ? (
<CircularProgress />
) : problems.length > 0 ? (
<List>
{problems.map((problem) => (
<ListItem key={problem.id} sx={{ mb: 2, border: "1px solid #ccc", borderRadius: 1, p: 2 }}>
<ListItemText
primary={`Title: ${problem.title}`}
secondary={
<>
<Typography variant="body2">Equation: {problem.equation}</Typography>
<Typography variant="body2">Solution: {problem.solution}</Typography>
<Typography variant="body2">Steps: {problem.steps.join(", ")}</Typography>
</>
}
/>
</ListItem>
))}
</List>
) : (
<Typography>No equations found for this study guide.</Typography>
)}
</Box>
);
};

export default Equations;

11 changes: 5 additions & 6 deletions app/study-guide/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback } from "react";
import { Box, Typography, List, ListItem, Button, CircularProgress } from "@mui/material";
import { createClient } from "../utils/supabase/client"; // Adjust the path as needed
import { useRouter } from 'next/navigation';
Expand All @@ -15,8 +15,8 @@ const StudyGuide: React.FC = () => {
const supabase = createClient();
const router = useRouter();

// Fetch study guide titles from Supabase
const fetchStudyGuides = async () => {
// Memoized fetchStudyGuides function to avoid re-creation on every render
const fetchStudyGuides = useCallback(async () => {
const { data, error } = await supabase
.from("study_guide")
.select("id, title")
Expand All @@ -36,11 +36,11 @@ const StudyGuide: React.FC = () => {
}

setLoading(false);
};
}, [supabase]); // The supabase dependency ensures fetchStudyGuides is recreated only when supabase changes

useEffect(() => {
fetchStudyGuides();
}, []);
}, [fetchStudyGuides]); // Now safe to add fetchStudyGuides to dependency array

// Handler for clicking on a study guide title
const handleStudyGuideClick = (id: number) => {
Expand Down Expand Up @@ -75,4 +75,3 @@ const StudyGuide: React.FC = () => {
};

export default StudyGuide;

0 comments on commit e0f13c6

Please sign in to comment.