-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit; reduced the size of repo
- Loading branch information
Showing
48 changed files
with
14,687 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_SUPABASE_URL= | ||
NEXT_PUBLIC_SUPABASE_ANON_KEY= |
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 |
---|---|---|
@@ -1,130 +1,4 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
dev | ||
node_modules | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
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,3 @@ | ||
{ | ||
"github-enterprise.uri": "sign 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 |
---|---|---|
@@ -1 +1,45 @@ | ||
# math_app_v3 | ||
|
||
# Math Solver • ![This is the badge image](https://img.shields.io/badge/license-MIT-blue.svg) | ||
|
||
## Table of Contents | ||
|
||
1. [Description](#description) | ||
2. [Technologies Used](#technologies) | ||
3. [Installation](#installation) | ||
4. [License](#license) | ||
5. [Future Developments](#future_developments) | ||
6. [Tests](#tests) | ||
7. [Questions](#questions) | ||
|
||
## [Description](#description) | ||
Math Solver is a powerful, user-friendly application designed to assist students in solving algebraic equations. By leveraging modern web technologies, the app provides step-by-step solutions to algebraic problems, helping users understand the process and improve their math skills. Users can log in to create personalized study guides and manage their algebra learning journey efficiently. | ||
|
||
Deployed App: | ||
|
||
![This is the badge image]() | ||
|
||
## [Technologies Used](#technologies) | ||
* Next.js | ||
* TypeScript | ||
* Math Steps API | ||
* Material UI | ||
* Supabase | ||
* Jest | ||
* TailwindCSS | ||
|
||
## [Installation](#installation) | ||
To install necessary dependencies, run the following command: npm i, to run npm run dev | ||
|
||
## [License](#license)![This is the badge image](https://img.shields.io/badge/license-MIT-blue.svg) | ||
This project is licensed under: | ||
[MIT](https://choosealicense.com/licenses/mit/) | ||
|
||
## [Future Developments](#future_developments) | ||
I plan to add step-by-step solutions for simple algebra equations by utilizing the mathsteps API and displaying the results through an accordian from Geist UI. | ||
|
||
## [Tests](#tests) | ||
Install Jest: npm install --save-dev jest @types/jest ts-jest, add test script to package.json, and run npm run test | ||
|
||
## [Questions](#questions) | ||
If you have questions, you can reach me at [email protected]. You can find more of my work at [[email protected]](https://github.com/[email protected]) | ||
|
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,84 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import Calcbar from '../components/Calcbar'; | ||
import mathsteps from 'mathsteps'; | ||
|
||
jest.mock('mathsteps'); | ||
|
||
describe('Calcbar', () => { | ||
const mockUserId = 'test-user-id'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders the Calcbar component', () => { | ||
render(<Calcbar userId={''} />); | ||
expect(screen.getByLabelText(/Enter an algebraic equation/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Solve/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the solution when a valid equation is solved', () => { | ||
const stepsMock = [ | ||
{ newEquation: { ascii: () => 'x = 1' }, changeType: 'SOLVE_EQUATION' }, | ||
]; | ||
(mathsteps.solveEquation as jest.Mock).mockReturnValue(stepsMock); | ||
|
||
render(<Calcbar userId={''} />); | ||
|
||
fireEvent.change(screen.getByLabelText(/Enter an algebraic equation/i), { target: { value: 'x + 1 = 2' } }); | ||
fireEvent.click(screen.getByText(/Solve/i)); | ||
|
||
expect(screen.getByText(/Solution: x = 1/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays "Invalid equation" when an invalid equation is entered', () => { | ||
(mathsteps.solveEquation as jest.Mock).mockImplementation(() => { throw new Error('Invalid equation'); }); | ||
|
||
render(<Calcbar userId={''} />); | ||
|
||
fireEvent.change(screen.getByLabelText(/Enter an algebraic equation/i), { target: { value: 'invalid equation' } }); | ||
fireEvent.click(screen.getByText(/Solve/i)); | ||
|
||
expect(screen.getByText(/Solution: Invalid equation/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays steps when a valid equation is solved', () => { | ||
const stepsMock = [ | ||
{ newEquation: { ascii: () => 'x + 1 = 2' }, changeType: 'ADD_CONSTANT' }, | ||
{ newEquation: { ascii: () => 'x = 1' }, changeType: 'SOLVE_EQUATION' }, | ||
]; | ||
(mathsteps.solveEquation as jest.Mock).mockReturnValue(stepsMock); | ||
|
||
render(<Calcbar userId={''} />); | ||
|
||
fireEvent.change(screen.getByLabelText(/Enter an algebraic equation/i), { target: { value: 'x + 1 = 2' } }); | ||
fireEvent.click(screen.getByText(/Solve/i)); | ||
|
||
expect(screen.getByText(/Steps/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Step 1/i)).toBeInTheDocument(); | ||
expect(screen.getAllByText(/x \+ 1 = 2/i)).toHaveLength(1); | ||
expect(screen.getByText(/add constant/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Step 2/i)).toBeInTheDocument(); | ||
expect(screen.getAllByText(/x = 1/i)).toHaveLength(2); | ||
expect(screen.getByText(/solve equation/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('opens the Add to Study Guide modal when AddButton is clicked', () => { | ||
const stepsMock = [ | ||
{ newEquation: { ascii: () => 'x = 1' }, changeType: 'SOLVE_EQUATION' }, | ||
]; | ||
(mathsteps.solveEquation as jest.Mock).mockReturnValue(stepsMock); | ||
|
||
render(<Calcbar userId={mockUserId} />); | ||
|
||
fireEvent.change(screen.getByLabelText(/Enter an algebraic equation/i), { target: { value: 'x + 1 = 2' } }); | ||
fireEvent.click(screen.getByText(/Solve/i)); | ||
fireEvent.click(screen.getByText(/Add to Study Guide/i)); | ||
|
||
expect(screen.getByText(/Add to Study Guide/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/New Title/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Existing Title/i)).toBeInTheDocument(); | ||
}); | ||
}); |
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,21 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import { createClient } from '../../utils/supabase/server' | ||
import { deleteCookie } from '../../utils/supabase/cookies' | ||
|
||
|
||
export async function POST(req: NextRequest) { | ||
const supabase = createClient() | ||
|
||
const { error } = await supabase.auth.signOut() | ||
|
||
if (error) { | ||
return NextResponse.redirect(new URL('/error', req.url)) | ||
} | ||
|
||
const response = NextResponse.redirect(new URL('/login', req.url)) | ||
// Delete cookies if needed | ||
deleteCookie(response, 'user-data') | ||
|
||
return response | ||
} |
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,40 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { createServerClient, type CookieOptions } from '@supabase/ssr'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const supabase = createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
get(name: string) { | ||
return req.cookies[name]; | ||
}, | ||
set(name: string, value: string, options: CookieOptions) { | ||
res.setHeader('Set-Cookie', `${name}=${value}; Path=/; HttpOnly`); | ||
}, | ||
remove(name: string, options: CookieOptions) { | ||
res.setHeader('Set-Cookie', `${name}=; Path=/; HttpOnly; Max-Age=0`); | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (req.method === 'POST') { | ||
const { user_id, equation } = req.body; | ||
|
||
const { data, error } = await supabase | ||
.from('study_guide') | ||
.insert([{ user_id, equation }]); | ||
|
||
if (error) { | ||
return res.status(500).json({ error: error.message }); | ||
} | ||
|
||
res.status(200).json(data); | ||
} else { | ||
res.setHeader('Allow', ['POST']); | ||
res.status(405).end(`Method ${req.method} Not Allowed`); | ||
} | ||
} |
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,19 @@ | ||
import { createClient } from "../../utils/supabase/server"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET(request: Request) { | ||
// The `/auth/callback` route is required for the server-side auth flow implemented | ||
// by the SSR package. It exchanges an auth code for the user's session. | ||
// https://supabase.com/docs/guides/auth/server-side/nextjs | ||
const requestUrl = new URL(request.url); | ||
const code = requestUrl.searchParams.get("code"); | ||
const origin = requestUrl.origin; | ||
|
||
if (code) { | ||
const supabase = createClient(); | ||
await supabase.auth.exchangeCodeForSession(code); | ||
} | ||
|
||
// URL to redirect to after sign up process completes | ||
return NextResponse.redirect(`${origin}/protected`); | ||
} |
Oops, something went wrong.