Upload 20 files
Browse files- Dockerfile +69 -0
- README.md +36 -12
- app/favicon.ico +0 -0
- app/globals.css +3 -0
- app/layout.tsx +19 -0
- app/page.tsx +9 -0
- components/MathQuizApp.tsx +114 -0
- eslint.config.mjs +16 -0
- next-env.d.ts +5 -0
- next.config.ts +7 -0
- package-lock.json +0 -0
- package.json +28 -0
- postcss.config.mjs +8 -0
- public/file.svg +1 -0
- public/globe.svg +1 -0
- public/next.svg +1 -0
- public/vercel.svg +1 -0
- public/window.svg +1 -0
- tailwind.config.ts +18 -0
- tsconfig.json +27 -0
Dockerfile
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# syntax=docker/dockerfile:1.4
|
2 |
+
|
3 |
+
# Adapted from https://github.com/vercel/next.js/blob/e60a1e747c3f521fc24dfd9ee2989e13afeb0a9b/examples/with-docker/Dockerfile
|
4 |
+
# For more information, see https://nextjs.org/docs/pages/building-your-application/deploying#docker-image
|
5 |
+
|
6 |
+
FROM node:18 AS base
|
7 |
+
|
8 |
+
# Install dependencies only when needed
|
9 |
+
FROM base AS deps
|
10 |
+
WORKDIR /app
|
11 |
+
|
12 |
+
# Install dependencies based on the preferred package manager
|
13 |
+
COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
14 |
+
RUN \
|
15 |
+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
16 |
+
elif [ -f package-lock.json ]; then npm ci; \
|
17 |
+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
18 |
+
else echo "Lockfile not found." && exit 1; \
|
19 |
+
fi
|
20 |
+
|
21 |
+
|
22 |
+
# Rebuild the source code only when needed
|
23 |
+
FROM base AS builder
|
24 |
+
WORKDIR /app
|
25 |
+
COPY --from=deps --link /app/node_modules ./node_modules
|
26 |
+
COPY --link . .
|
27 |
+
|
28 |
+
# Next.js collects completely anonymous telemetry data about general usage.
|
29 |
+
# Learn more here: https://nextjs.org/telemetry
|
30 |
+
# Uncomment the following line in case you want to disable telemetry during the build.
|
31 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
32 |
+
|
33 |
+
RUN npm run build
|
34 |
+
|
35 |
+
# If using yarn comment out above and use below instead
|
36 |
+
# RUN yarn build
|
37 |
+
|
38 |
+
# Production image, copy all the files and run next
|
39 |
+
FROM base AS runner
|
40 |
+
WORKDIR /app
|
41 |
+
|
42 |
+
ENV NODE_ENV production
|
43 |
+
# Uncomment the following line in case you want to disable telemetry during runtime.
|
44 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
45 |
+
|
46 |
+
RUN \
|
47 |
+
addgroup --system --gid 1001 nodejs; \
|
48 |
+
adduser --system --uid 1001 nextjs
|
49 |
+
|
50 |
+
COPY --from=builder --link /app/public ./public
|
51 |
+
|
52 |
+
# Automatically leverage output traces to reduce image size
|
53 |
+
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
54 |
+
COPY --from=builder --link --chown=1001:1001 /app/.next/standalone ./
|
55 |
+
COPY --from=builder --link --chown=1001:1001 /app/.next/static ./.next/static
|
56 |
+
|
57 |
+
USER nextjs
|
58 |
+
|
59 |
+
EXPOSE 3000
|
60 |
+
|
61 |
+
ENV PORT 3000
|
62 |
+
ENV HOSTNAME 0.0.0.0
|
63 |
+
|
64 |
+
# Allow the running process to write model files to the cache folder.
|
65 |
+
# NOTE: In practice, you would probably want to pre-download the model files to avoid having to download them on-the-fly.
|
66 |
+
RUN mkdir -p /app/node_modules/@xenova/.cache/
|
67 |
+
RUN chmod 777 -R /app/node_modules/@xenova/
|
68 |
+
|
69 |
+
CMD ["node", "server.js"]
|
README.md
CHANGED
@@ -1,12 +1,36 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
2 |
+
|
3 |
+
## Getting Started
|
4 |
+
|
5 |
+
First, run the development server:
|
6 |
+
|
7 |
+
```bash
|
8 |
+
npm run dev
|
9 |
+
# or
|
10 |
+
yarn dev
|
11 |
+
# or
|
12 |
+
pnpm dev
|
13 |
+
# or
|
14 |
+
bun dev
|
15 |
+
```
|
16 |
+
|
17 |
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
18 |
+
|
19 |
+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
20 |
+
|
21 |
+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
22 |
+
|
23 |
+
## Learn More
|
24 |
+
|
25 |
+
To learn more about Next.js, take a look at the following resources:
|
26 |
+
|
27 |
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
28 |
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
29 |
+
|
30 |
+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
31 |
+
|
32 |
+
## Deploy on Vercel
|
33 |
+
|
34 |
+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
35 |
+
|
36 |
+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
app/favicon.ico
ADDED
app/globals.css
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
@tailwind base;
|
2 |
+
@tailwind components;
|
3 |
+
@tailwind utilities;
|
app/layout.tsx
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Metadata } from "next";
|
2 |
+
import "./globals.css";
|
3 |
+
|
4 |
+
export const metadata: Metadata = {
|
5 |
+
title: "Math Quiz App",
|
6 |
+
description: "A simple math quiz application",
|
7 |
+
};
|
8 |
+
|
9 |
+
export default function RootLayout({
|
10 |
+
children,
|
11 |
+
}: Readonly<{
|
12 |
+
children: React.ReactNode;
|
13 |
+
}>) {
|
14 |
+
return (
|
15 |
+
<html lang="en">
|
16 |
+
<body>{children}</body>
|
17 |
+
</html>
|
18 |
+
);
|
19 |
+
}
|
app/page.tsx
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import MathQuizApp from "@/components/MathQuizApp";
|
2 |
+
|
3 |
+
export default function Home() {
|
4 |
+
return (
|
5 |
+
<main className="min-h-screen bg-gray-100">
|
6 |
+
<MathQuizApp />
|
7 |
+
</main>
|
8 |
+
);
|
9 |
+
}
|
components/MathQuizApp.tsx
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use client';
|
2 |
+
|
3 |
+
import { useState } from 'react';
|
4 |
+
import { Check, X } from 'lucide-react';
|
5 |
+
|
6 |
+
const operations = ['+', '-', '*', '/'];
|
7 |
+
const difficulties = ['easy', 'medium', 'hard'];
|
8 |
+
|
9 |
+
const generateQuestion = (difficulty: string) => {
|
10 |
+
const operation = operations[Math.floor(Math.random() * operations.length)];
|
11 |
+
let num1 = 0;
|
12 |
+
let num2 = 0;
|
13 |
+
|
14 |
+
switch (difficulty) {
|
15 |
+
case 'easy':
|
16 |
+
num1 = Math.floor(Math.random() * 10) + 1;
|
17 |
+
num2 = Math.floor(Math.random() * 10) + 1;
|
18 |
+
break;
|
19 |
+
case 'medium':
|
20 |
+
num1 = Math.floor(Math.random() * 50) + 1;
|
21 |
+
num2 = Math.floor(Math.random() * 50) + 1;
|
22 |
+
break;
|
23 |
+
case 'hard':
|
24 |
+
num1 = Math.floor(Math.random() * 100) + 1;
|
25 |
+
num2 = Math.floor(Math.random() * 100) + 1;
|
26 |
+
break;
|
27 |
+
}
|
28 |
+
|
29 |
+
return {
|
30 |
+
num1,
|
31 |
+
num2,
|
32 |
+
operation,
|
33 |
+
answer: eval(`${num1} ${operation} ${num2}`),
|
34 |
+
};
|
35 |
+
};
|
36 |
+
|
37 |
+
const MathQuizApp = () => {
|
38 |
+
const [question, setQuestion] = useState(generateQuestion('easy'));
|
39 |
+
const [userAnswer, setUserAnswer] = useState('');
|
40 |
+
const [result, setResult] = useState('');
|
41 |
+
const [score, setScore] = useState(0);
|
42 |
+
const [difficulty, setDifficulty] = useState('easy');
|
43 |
+
|
44 |
+
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
45 |
+
e.preventDefault();
|
46 |
+
if (Number(userAnswer) === question.answer) {
|
47 |
+
setResult('Correct!');
|
48 |
+
setScore(score + 1);
|
49 |
+
} else {
|
50 |
+
setResult(`Incorrect. The correct answer is ${question.answer}.`);
|
51 |
+
}
|
52 |
+
setUserAnswer('');
|
53 |
+
setQuestion(generateQuestion(difficulty));
|
54 |
+
};
|
55 |
+
|
56 |
+
const handleDifficultyChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
57 |
+
setDifficulty(e.target.value);
|
58 |
+
setQuestion(generateQuestion(e.target.value));
|
59 |
+
setScore(0);
|
60 |
+
};
|
61 |
+
|
62 |
+
return (
|
63 |
+
<div className="max-w-md mx-auto p-4 mt-10 bg-white rounded-lg shadow-md">
|
64 |
+
<h1 className="text-3xl font-bold mb-4">Math Quiz App</h1>
|
65 |
+
<form onSubmit={handleSubmit}>
|
66 |
+
<div className="flex justify-between mb-4">
|
67 |
+
<select
|
68 |
+
value={difficulty}
|
69 |
+
onChange={handleDifficultyChange}
|
70 |
+
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
71 |
+
>
|
72 |
+
{difficulties.map((difficulty) => (
|
73 |
+
<option key={difficulty} value={difficulty}>
|
74 |
+
{difficulty.charAt(0).toUpperCase() + difficulty.slice(1)}
|
75 |
+
</option>
|
76 |
+
))}
|
77 |
+
</select>
|
78 |
+
<p className="text-lg font-bold">Score: {score}</p>
|
79 |
+
</div>
|
80 |
+
<p className="text-2xl font-bold mb-4">
|
81 |
+
What is {question.num1} {question.operation} {question.num2}?
|
82 |
+
</p>
|
83 |
+
<input
|
84 |
+
type="number"
|
85 |
+
value={userAnswer}
|
86 |
+
onChange={(e) => setUserAnswer(e.target.value)}
|
87 |
+
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
88 |
+
/>
|
89 |
+
<button
|
90 |
+
type="submit"
|
91 |
+
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center mt-4"
|
92 |
+
>
|
93 |
+
Submit
|
94 |
+
</button>
|
95 |
+
{result && (
|
96 |
+
<p
|
97 |
+
className={`text-lg font-bold mt-4 ${
|
98 |
+
result === 'Correct!' ? 'text-green-500' : 'text-red-500'
|
99 |
+
}`}
|
100 |
+
>
|
101 |
+
{result}{' '}
|
102 |
+
{result === 'Correct!' ? (
|
103 |
+
<Check className="inline-block w-6 h-6" />
|
104 |
+
) : (
|
105 |
+
<X className="inline-block w-6 h-6" />
|
106 |
+
)}
|
107 |
+
</p>
|
108 |
+
)}
|
109 |
+
</form>
|
110 |
+
</div>
|
111 |
+
);
|
112 |
+
};
|
113 |
+
|
114 |
+
export default MathQuizApp;
|
eslint.config.mjs
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { dirname } from "path";
|
2 |
+
import { fileURLToPath } from "url";
|
3 |
+
import { FlatCompat } from "@eslint/eslintrc";
|
4 |
+
|
5 |
+
const __filename = fileURLToPath(import.meta.url);
|
6 |
+
const __dirname = dirname(__filename);
|
7 |
+
|
8 |
+
const compat = new FlatCompat({
|
9 |
+
baseDirectory: __dirname,
|
10 |
+
});
|
11 |
+
|
12 |
+
const eslintConfig = [
|
13 |
+
...compat.extends("next/core-web-vitals", "next/typescript"),
|
14 |
+
];
|
15 |
+
|
16 |
+
export default eslintConfig;
|
next-env.d.ts
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/// <reference types="next" />
|
2 |
+
/// <reference types="next/image-types/global" />
|
3 |
+
|
4 |
+
// NOTE: This file should not be edited
|
5 |
+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
next.config.ts
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { NextConfig } from "next";
|
2 |
+
|
3 |
+
const nextConfig: NextConfig = {
|
4 |
+
/* config options here */
|
5 |
+
};
|
6 |
+
|
7 |
+
export default nextConfig;
|
package-lock.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
package.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "math-quiz",
|
3 |
+
"version": "0.1.0",
|
4 |
+
"private": true,
|
5 |
+
"scripts": {
|
6 |
+
"dev": "next dev --turbopack",
|
7 |
+
"build": "next build",
|
8 |
+
"start": "next start",
|
9 |
+
"lint": "next lint"
|
10 |
+
},
|
11 |
+
"dependencies": {
|
12 |
+
"lucide-react": "^0.469.0",
|
13 |
+
"next": "15.1.3",
|
14 |
+
"react": "^19.0.0",
|
15 |
+
"react-dom": "^19.0.0"
|
16 |
+
},
|
17 |
+
"devDependencies": {
|
18 |
+
"@eslint/eslintrc": "^3",
|
19 |
+
"@types/node": "^20",
|
20 |
+
"@types/react": "^19",
|
21 |
+
"@types/react-dom": "^19",
|
22 |
+
"eslint": "^9",
|
23 |
+
"eslint-config-next": "15.1.3",
|
24 |
+
"postcss": "^8",
|
25 |
+
"tailwindcss": "^3.4.1",
|
26 |
+
"typescript": "^5"
|
27 |
+
}
|
28 |
+
}
|
postcss.config.mjs
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/** @type {import('postcss-load-config').Config} */
|
2 |
+
const config = {
|
3 |
+
plugins: {
|
4 |
+
tailwindcss: {},
|
5 |
+
},
|
6 |
+
};
|
7 |
+
|
8 |
+
export default config;
|
public/file.svg
ADDED
public/globe.svg
ADDED
public/next.svg
ADDED
public/vercel.svg
ADDED
public/window.svg
ADDED
tailwind.config.ts
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Config } from "tailwindcss";
|
2 |
+
|
3 |
+
export default {
|
4 |
+
content: [
|
5 |
+
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
|
6 |
+
"./components/**/*.{js,ts,jsx,tsx,mdx}",
|
7 |
+
"./app/**/*.{js,ts,jsx,tsx,mdx}",
|
8 |
+
],
|
9 |
+
theme: {
|
10 |
+
extend: {
|
11 |
+
colors: {
|
12 |
+
background: "var(--background)",
|
13 |
+
foreground: "var(--foreground)",
|
14 |
+
},
|
15 |
+
},
|
16 |
+
},
|
17 |
+
plugins: [],
|
18 |
+
} satisfies Config;
|
tsconfig.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"target": "ES2017",
|
4 |
+
"lib": ["dom", "dom.iterable", "esnext"],
|
5 |
+
"allowJs": true,
|
6 |
+
"skipLibCheck": true,
|
7 |
+
"strict": true,
|
8 |
+
"noEmit": true,
|
9 |
+
"esModuleInterop": true,
|
10 |
+
"module": "esnext",
|
11 |
+
"moduleResolution": "bundler",
|
12 |
+
"resolveJsonModule": true,
|
13 |
+
"isolatedModules": true,
|
14 |
+
"jsx": "preserve",
|
15 |
+
"incremental": true,
|
16 |
+
"plugins": [
|
17 |
+
{
|
18 |
+
"name": "next"
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"paths": {
|
22 |
+
"@/*": ["./*"]
|
23 |
+
}
|
24 |
+
},
|
25 |
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
26 |
+
"exclude": ["node_modules"]
|
27 |
+
}
|