Vibed it... :(
This commit is contained in:
255
.gitignore
vendored
Normal file
255
.gitignore
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
# Dependencies
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# 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
|
||||
jspm_packages/
|
||||
|
||||
# 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
|
||||
.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/
|
||||
public
|
||||
|
||||
# Vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# 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.*
|
||||
|
||||
# React build output
|
||||
frontend/build/
|
||||
frontend/dist/
|
||||
|
||||
# Create React App
|
||||
frontend/.env.local
|
||||
frontend/.env.development.local
|
||||
frontend/.env.test.local
|
||||
frontend/.env.production.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Users Environment Variables
|
||||
.lock-wscript
|
||||
|
||||
# IDEs and editors (Atom, Sublime, Vim, Emacs, VS Code, etc.)
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.tmproj
|
||||
.vscode/
|
||||
|
||||
# Misc
|
||||
*.tgz
|
||||
*.tar.gz
|
||||
.cache
|
||||
.tmp
|
||||
.temp
|
||||
|
||||
# Database files (if using local SQLite)
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
*.db
|
||||
|
||||
# MongoDB dump files
|
||||
dump/
|
||||
|
||||
# Backup files
|
||||
*.bak
|
||||
*.backup
|
||||
*.old
|
||||
|
||||
# Mac files
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Windows files
|
||||
Desktop.ini
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Linux files
|
||||
*~
|
||||
|
||||
# Temporary folders
|
||||
tmp/
|
||||
temp/
|
||||
|
||||
# Local configuration files that shouldn't be shared
|
||||
config/local.json
|
||||
config/development.json
|
||||
config/production.json
|
||||
|
||||
# SSL certificates
|
||||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
*.cert
|
||||
|
||||
# Docker
|
||||
.dockerignore
|
||||
Dockerfile.dev
|
||||
|
||||
# Terraform
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
.terraform/
|
||||
|
||||
# AWS
|
||||
.aws/
|
||||
|
||||
# Package lock files (choose one based on your preference)
|
||||
# package-lock.json
|
||||
# yarn.lock
|
||||
|
||||
# Build artifacts
|
||||
build/
|
||||
dist/
|
||||
out/
|
||||
|
||||
# Test results
|
||||
test-results/
|
||||
coverage/
|
||||
.nyc_output/
|
||||
|
||||
# Storybook build outputs
|
||||
storybook-static/
|
||||
|
||||
# Temporary files created by editors
|
||||
.#*
|
||||
\#*#
|
||||
.*.swp
|
||||
.*.swo
|
||||
|
||||
# Local environment files
|
||||
.env.example
|
||||
170
README.md
Normal file
170
README.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# Recipe Management App
|
||||
|
||||
A full-stack recipe management application that allows users to browse recipes, select them for their menu, and automatically generate aggregated shopping lists.
|
||||
|
||||
## Features
|
||||
|
||||
- **User Authentication**: Register and login with secure JWT authentication
|
||||
- **Recipe Browsing**: Browse recipes with filtering by category, difficulty, and search
|
||||
- **Recipe Selection**: Add recipes to your personal menu with quantity control
|
||||
- **Ingredient Aggregation**: Automatically calculate total ingredient quantities across selected recipes
|
||||
- **Shopping List**: Generate comprehensive shopping lists from selected recipes
|
||||
- **Responsive Design**: Modern, mobile-friendly interface
|
||||
|
||||
## Tech Stack
|
||||
|
||||
### Backend
|
||||
- **Node.js** with Express.js
|
||||
- **MongoDB** with Mongoose ODM
|
||||
- **JWT** for authentication
|
||||
- **bcryptjs** for password hashing
|
||||
- **CORS** for cross-origin requests
|
||||
|
||||
### Frontend
|
||||
- **React 18** with TypeScript
|
||||
- **React Router** for navigation
|
||||
- **Axios** for API calls
|
||||
- **Context API** for state management
|
||||
- **CSS3** with responsive design
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
recipe-management-app/
|
||||
├── backend/
|
||||
│ ├── models/ # Database models
|
||||
│ ├── routes/ # API routes
|
||||
│ ├── server.js # Express server
|
||||
│ ├── seedData.js # Sample data seeder
|
||||
│ └── package.json
|
||||
├── frontend/
|
||||
│ ├── src/
|
||||
│ │ ├── components/ # React components
|
||||
│ │ ├── pages/ # Page components
|
||||
│ │ ├── context/ # React context
|
||||
│ │ ├── services/ # API services
|
||||
│ │ └── utils/ # Utility functions
|
||||
│ └── package.json
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### Prerequisites
|
||||
- Node.js (v14 or higher)
|
||||
- MongoDB (running locally or MongoDB Atlas)
|
||||
- npm or yarn
|
||||
|
||||
### Backend Setup
|
||||
|
||||
1. Navigate to the backend directory:
|
||||
```bash
|
||||
cd backend
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
3. Create a `.env` file with your configuration:
|
||||
```
|
||||
PORT=5000
|
||||
MONGODB_URI=mongodb://localhost:27017/recipe-management
|
||||
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
||||
```
|
||||
|
||||
4. Seed the database with sample recipes:
|
||||
```bash
|
||||
node seedData.js
|
||||
```
|
||||
|
||||
5. Start the backend server:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Frontend Setup
|
||||
|
||||
1. Navigate to the frontend directory:
|
||||
```bash
|
||||
cd frontend
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
3. Start the frontend development server:
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
The application will be available at:
|
||||
- Frontend: http://localhost:3000
|
||||
- Backend API: http://localhost:5000
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Authentication
|
||||
- `POST /api/users/register` - Register new user
|
||||
- `POST /api/users/login` - Login user
|
||||
- `GET /api/users/profile` - Get user profile (protected)
|
||||
|
||||
### Recipes
|
||||
- `GET /api/recipes` - Get all recipes (with optional filters)
|
||||
- `GET /api/recipes/:id` - Get recipe by ID
|
||||
- `POST /api/recipes` - Create new recipe
|
||||
- `PUT /api/recipes/:id` - Update recipe
|
||||
- `DELETE /api/recipes/:id` - Delete recipe
|
||||
|
||||
### User Selections
|
||||
- `GET /api/selections` - Get user's recipe selections (protected)
|
||||
- `POST /api/selections/add` - Add recipe to selection (protected)
|
||||
- `PUT /api/selections/update` - Update recipe quantity (protected)
|
||||
- `DELETE /api/selections/remove/:recipeId` - Remove recipe from selection (protected)
|
||||
- `DELETE /api/selections/clear` - Clear all selections (protected)
|
||||
|
||||
## Usage
|
||||
|
||||
1. **Register/Login**: Create an account or login to access the application
|
||||
2. **Browse Recipes**: Use the "Browse Recipes" tab to explore available recipes
|
||||
3. **Filter & Search**: Use category, difficulty filters and search to find specific recipes
|
||||
4. **Add to Menu**: Click "Add to Menu" on recipes you want to include
|
||||
5. **Manage Menu**: Switch to "My Menu & Shopping List" tab to manage selected recipes
|
||||
6. **Adjust Quantities**: Use +/- buttons to adjust recipe quantities
|
||||
7. **View Shopping List**: See aggregated ingredients with breakdown by recipe
|
||||
8. **Remove Items**: Remove individual recipes or clear entire menu
|
||||
|
||||
## Sample Data
|
||||
|
||||
The application comes with 5 sample recipes:
|
||||
- Classic Spaghetti Carbonara (Dinner, Medium)
|
||||
- Chocolate Chip Cookies (Dessert, Easy)
|
||||
- Caesar Salad (Lunch, Easy)
|
||||
- Pancakes (Breakfast, Easy)
|
||||
- Beef Stir Fry (Dinner, Medium)
|
||||
|
||||
## Development
|
||||
|
||||
### Adding New Recipes
|
||||
Recipes can be added through the API or by modifying the `seedData.js` file.
|
||||
|
||||
### Customization
|
||||
- Modify styles in component CSS files
|
||||
- Add new recipe categories in the Recipe model
|
||||
- Extend user functionality in the User model
|
||||
- Add new API endpoints in the routes directory
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make your changes
|
||||
4. Test thoroughly
|
||||
5. Submit a pull request
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the ISC License.
|
||||
64
backend/models/Recipe.js
Normal file
64
backend/models/Recipe.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const ingredientSchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
const recipeSchema = new mongoose.Schema({
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
ingredients: [ingredientSchema],
|
||||
instructions: [{
|
||||
step: Number,
|
||||
description: String
|
||||
}],
|
||||
servings: {
|
||||
type: Number,
|
||||
default: 4
|
||||
},
|
||||
prepTime: {
|
||||
type: Number, // in minutes
|
||||
required: true
|
||||
},
|
||||
cookTime: {
|
||||
type: Number, // in minutes
|
||||
required: true
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
enum: ['breakfast', 'lunch', 'dinner', 'dessert', 'snack', 'appetizer'],
|
||||
required: true
|
||||
},
|
||||
difficulty: {
|
||||
type: String,
|
||||
enum: ['easy', 'medium', 'hard'],
|
||||
default: 'medium'
|
||||
},
|
||||
imageUrl: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Recipe', recipeSchema);
|
||||
49
backend/models/User.js
Normal file
49
backend/models/User.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const mongoose = require('mongoose');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
trim: true,
|
||||
minlength: 3,
|
||||
maxlength: 30
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
trim: true,
|
||||
lowercase: true
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true,
|
||||
minlength: 6
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
// Hash password before saving
|
||||
userSchema.pre('save', async function(next) {
|
||||
if (!this.isModified('password')) return next();
|
||||
|
||||
try {
|
||||
const salt = await bcrypt.genSalt(10);
|
||||
this.password = await bcrypt.hash(this.password, salt);
|
||||
next();
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Compare password method
|
||||
userSchema.methods.comparePassword = async function(candidatePassword) {
|
||||
return bcrypt.compare(candidatePassword, this.password);
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
55
backend/models/UserSelection.js
Normal file
55
backend/models/UserSelection.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const userSelectionSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
required: true
|
||||
},
|
||||
selectedRecipes: [{
|
||||
recipeId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Recipe',
|
||||
required: true
|
||||
},
|
||||
quantity: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
min: 1
|
||||
},
|
||||
addedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
}],
|
||||
aggregatedIngredients: [{
|
||||
name: String,
|
||||
totalAmount: Number,
|
||||
unit: String,
|
||||
recipes: [{
|
||||
recipeId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Recipe'
|
||||
},
|
||||
recipeTitle: String,
|
||||
amount: Number,
|
||||
quantity: Number // recipe quantity multiplier
|
||||
}]
|
||||
}],
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
// Update the updatedAt field before saving
|
||||
userSelectionSchema.pre('save', function(next) {
|
||||
this.updatedAt = Date.now();
|
||||
next();
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('UserSelection', userSelectionSchema);
|
||||
1656
backend/package-lock.json
generated
Normal file
1656
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
backend/package.json
Normal file
25
backend/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "recipe-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Backend for recipe management app",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"dev": "nodemon server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"cors": "^2.8.5",
|
||||
"mongoose": "^7.5.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"jsonwebtoken": "^9.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.0.1"
|
||||
},
|
||||
"keywords": ["recipe", "management", "api"],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
81
backend/routes/recipes.js
Normal file
81
backend/routes/recipes.js
Normal file
@@ -0,0 +1,81 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const Recipe = require('../models/Recipe');
|
||||
|
||||
// Get all recipes
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const { category, difficulty, search } = req.query;
|
||||
let filter = {};
|
||||
|
||||
if (category) filter.category = category;
|
||||
if (difficulty) filter.difficulty = difficulty;
|
||||
if (search) {
|
||||
filter.$or = [
|
||||
{ title: { $regex: search, $options: 'i' } },
|
||||
{ description: { $regex: search, $options: 'i' } }
|
||||
];
|
||||
}
|
||||
|
||||
const recipes = await Recipe.find(filter).sort({ createdAt: -1 });
|
||||
res.json(recipes);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get recipe by ID
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const recipe = await Recipe.findById(req.params.id);
|
||||
if (!recipe) {
|
||||
return res.status(404).json({ error: 'Recipe not found' });
|
||||
}
|
||||
res.json(recipe);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Create new recipe
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const recipe = new Recipe(req.body);
|
||||
await recipe.save();
|
||||
res.status(201).json(recipe);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Update recipe
|
||||
router.put('/:id', async (req, res) => {
|
||||
try {
|
||||
const recipe = await Recipe.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
req.body,
|
||||
{ new: true, runValidators: true }
|
||||
);
|
||||
if (!recipe) {
|
||||
return res.status(404).json({ error: 'Recipe not found' });
|
||||
}
|
||||
res.json(recipe);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Delete recipe
|
||||
router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const recipe = await Recipe.findByIdAndDelete(req.params.id);
|
||||
if (!recipe) {
|
||||
return res.status(404).json({ error: 'Recipe not found' });
|
||||
}
|
||||
res.json({ message: 'Recipe deleted successfully' });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
219
backend/routes/selections.js
Normal file
219
backend/routes/selections.js
Normal file
@@ -0,0 +1,219 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const UserSelection = require('../models/UserSelection');
|
||||
const Recipe = require('../models/Recipe');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
// Middleware to authenticate JWT token
|
||||
function authenticateToken(req, res, next) {
|
||||
const authHeader = req.headers['authorization'];
|
||||
const token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'Access token required' });
|
||||
}
|
||||
|
||||
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
|
||||
if (err) {
|
||||
return res.status(403).json({ error: 'Invalid or expired token' });
|
||||
}
|
||||
req.userId = decoded.userId;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to aggregate ingredients
|
||||
async function aggregateIngredients(selectedRecipes) {
|
||||
const aggregated = {};
|
||||
|
||||
for (const selection of selectedRecipes) {
|
||||
const recipe = await Recipe.findById(selection.recipeId);
|
||||
if (!recipe) continue;
|
||||
|
||||
for (const ingredient of recipe.ingredients) {
|
||||
const key = `${ingredient.name}_${ingredient.unit}`;
|
||||
|
||||
if (!aggregated[key]) {
|
||||
aggregated[key] = {
|
||||
name: ingredient.name,
|
||||
totalAmount: 0,
|
||||
unit: ingredient.unit,
|
||||
recipes: []
|
||||
};
|
||||
}
|
||||
|
||||
const totalAmount = ingredient.amount * selection.quantity;
|
||||
aggregated[key].totalAmount += totalAmount;
|
||||
aggregated[key].recipes.push({
|
||||
recipeId: recipe._id,
|
||||
recipeTitle: recipe.title,
|
||||
amount: ingredient.amount,
|
||||
quantity: selection.quantity
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Object.values(aggregated);
|
||||
}
|
||||
|
||||
// Get user's selections
|
||||
router.get('/', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
let userSelection = await UserSelection.findOne({ userId: req.userId })
|
||||
.populate('selectedRecipes.recipeId', 'title description imageUrl category');
|
||||
|
||||
if (!userSelection) {
|
||||
userSelection = new UserSelection({
|
||||
userId: req.userId,
|
||||
selectedRecipes: [],
|
||||
aggregatedIngredients: []
|
||||
});
|
||||
await userSelection.save();
|
||||
}
|
||||
|
||||
res.json(userSelection);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Add recipe to user's selection
|
||||
router.post('/add', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { recipeId, quantity = 1 } = req.body;
|
||||
|
||||
// Verify recipe exists
|
||||
const recipe = await Recipe.findById(recipeId);
|
||||
if (!recipe) {
|
||||
return res.status(404).json({ error: 'Recipe not found' });
|
||||
}
|
||||
|
||||
let userSelection = await UserSelection.findOne({ userId: req.userId });
|
||||
|
||||
if (!userSelection) {
|
||||
userSelection = new UserSelection({
|
||||
userId: req.userId,
|
||||
selectedRecipes: [],
|
||||
aggregatedIngredients: []
|
||||
});
|
||||
}
|
||||
|
||||
// Check if recipe is already selected
|
||||
const existingIndex = userSelection.selectedRecipes.findIndex(
|
||||
item => item.recipeId.toString() === recipeId
|
||||
);
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
// Update quantity if recipe already exists
|
||||
userSelection.selectedRecipes[existingIndex].quantity += quantity;
|
||||
} else {
|
||||
// Add new recipe selection
|
||||
userSelection.selectedRecipes.push({
|
||||
recipeId,
|
||||
quantity,
|
||||
addedAt: new Date()
|
||||
});
|
||||
}
|
||||
|
||||
// Recalculate aggregated ingredients
|
||||
userSelection.aggregatedIngredients = await aggregateIngredients(userSelection.selectedRecipes);
|
||||
|
||||
await userSelection.save();
|
||||
|
||||
// Populate recipe details for response
|
||||
await userSelection.populate('selectedRecipes.recipeId', 'title description imageUrl category');
|
||||
|
||||
res.json(userSelection);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Update recipe quantity in selection
|
||||
router.put('/update', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { recipeId, quantity } = req.body;
|
||||
|
||||
if (quantity < 0) {
|
||||
return res.status(400).json({ error: 'Quantity must be positive' });
|
||||
}
|
||||
|
||||
const userSelection = await UserSelection.findOne({ userId: req.userId });
|
||||
if (!userSelection) {
|
||||
return res.status(404).json({ error: 'No selections found' });
|
||||
}
|
||||
|
||||
const recipeIndex = userSelection.selectedRecipes.findIndex(
|
||||
item => item.recipeId.toString() === recipeId
|
||||
);
|
||||
|
||||
if (recipeIndex === -1) {
|
||||
return res.status(404).json({ error: 'Recipe not found in selections' });
|
||||
}
|
||||
|
||||
if (quantity === 0) {
|
||||
// Remove recipe if quantity is 0
|
||||
userSelection.selectedRecipes.splice(recipeIndex, 1);
|
||||
} else {
|
||||
// Update quantity
|
||||
userSelection.selectedRecipes[recipeIndex].quantity = quantity;
|
||||
}
|
||||
|
||||
// Recalculate aggregated ingredients
|
||||
userSelection.aggregatedIngredients = await aggregateIngredients(userSelection.selectedRecipes);
|
||||
|
||||
await userSelection.save();
|
||||
await userSelection.populate('selectedRecipes.recipeId', 'title description imageUrl category');
|
||||
|
||||
res.json(userSelection);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Remove recipe from selection
|
||||
router.delete('/remove/:recipeId', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { recipeId } = req.params;
|
||||
|
||||
const userSelection = await UserSelection.findOne({ userId: req.userId });
|
||||
if (!userSelection) {
|
||||
return res.status(404).json({ error: 'No selections found' });
|
||||
}
|
||||
|
||||
userSelection.selectedRecipes = userSelection.selectedRecipes.filter(
|
||||
item => item.recipeId.toString() !== recipeId
|
||||
);
|
||||
|
||||
// Recalculate aggregated ingredients
|
||||
userSelection.aggregatedIngredients = await aggregateIngredients(userSelection.selectedRecipes);
|
||||
|
||||
await userSelection.save();
|
||||
await userSelection.populate('selectedRecipes.recipeId', 'title description imageUrl category');
|
||||
|
||||
res.json(userSelection);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Clear all selections
|
||||
router.delete('/clear', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const userSelection = await UserSelection.findOne({ userId: req.userId });
|
||||
if (!userSelection) {
|
||||
return res.status(404).json({ error: 'No selections found' });
|
||||
}
|
||||
|
||||
userSelection.selectedRecipes = [];
|
||||
userSelection.aggregatedIngredients = [];
|
||||
|
||||
await userSelection.save();
|
||||
|
||||
res.json(userSelection);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
115
backend/routes/users.js
Normal file
115
backend/routes/users.js
Normal file
@@ -0,0 +1,115 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const jwt = require('jsonwebtoken');
|
||||
const User = require('../models/User');
|
||||
|
||||
// Register new user
|
||||
router.post('/register', async (req, res) => {
|
||||
try {
|
||||
const { username, email, password } = req.body;
|
||||
|
||||
// Check if user already exists
|
||||
const existingUser = await User.findOne({
|
||||
$or: [{ email }, { username }]
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
return res.status(400).json({
|
||||
error: 'User with this email or username already exists'
|
||||
});
|
||||
}
|
||||
|
||||
const user = new User({ username, email, password });
|
||||
await user.save();
|
||||
|
||||
// Generate JWT token
|
||||
const token = jwt.sign(
|
||||
{ userId: user._id },
|
||||
process.env.JWT_SECRET,
|
||||
{ expiresIn: '7d' }
|
||||
);
|
||||
|
||||
res.status(201).json({
|
||||
message: 'User created successfully',
|
||||
token,
|
||||
user: {
|
||||
id: user._id,
|
||||
username: user.username,
|
||||
email: user.email
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Login user
|
||||
router.post('/login', async (req, res) => {
|
||||
try {
|
||||
const { email, password } = req.body;
|
||||
|
||||
// Find user by email
|
||||
const user = await User.findOne({ email });
|
||||
if (!user) {
|
||||
return res.status(401).json({ error: 'Invalid credentials' });
|
||||
}
|
||||
|
||||
// Check password
|
||||
const isPasswordValid = await user.comparePassword(password);
|
||||
if (!isPasswordValid) {
|
||||
return res.status(401).json({ error: 'Invalid credentials' });
|
||||
}
|
||||
|
||||
// Generate JWT token
|
||||
const token = jwt.sign(
|
||||
{ userId: user._id },
|
||||
process.env.JWT_SECRET,
|
||||
{ expiresIn: '7d' }
|
||||
);
|
||||
|
||||
res.json({
|
||||
message: 'Login successful',
|
||||
token,
|
||||
user: {
|
||||
id: user._id,
|
||||
username: user.username,
|
||||
email: user.email
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get user profile (protected route)
|
||||
router.get('/profile', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const user = await User.findById(req.userId).select('-password');
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
res.json(user);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Middleware to authenticate JWT token
|
||||
function authenticateToken(req, res, next) {
|
||||
const authHeader = req.headers['authorization'];
|
||||
const token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'Access token required' });
|
||||
}
|
||||
|
||||
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
|
||||
if (err) {
|
||||
return res.status(403).json({ error: 'Invalid or expired token' });
|
||||
}
|
||||
req.userId = decoded.userId;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
177
backend/seedData.js
Normal file
177
backend/seedData.js
Normal file
@@ -0,0 +1,177 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Recipe = require('./models/Recipe');
|
||||
require('dotenv').config();
|
||||
|
||||
const sampleRecipes = [
|
||||
{
|
||||
title: "Classic Spaghetti Carbonara",
|
||||
description: "A traditional Italian pasta dish with eggs, cheese, and pancetta",
|
||||
ingredients: [
|
||||
{ name: "spaghetti", amount: 400, unit: "g" },
|
||||
{ name: "pancetta", amount: 150, unit: "g" },
|
||||
{ name: "eggs", amount: 3, unit: "whole" },
|
||||
{ name: "parmesan cheese", amount: 100, unit: "g" },
|
||||
{ name: "black pepper", amount: 1, unit: "tsp" },
|
||||
{ name: "salt", amount: 1, unit: "tsp" }
|
||||
],
|
||||
instructions: [
|
||||
{ step: 1, description: "Cook spaghetti in salted boiling water until al dente" },
|
||||
{ step: 2, description: "Fry pancetta until crispy" },
|
||||
{ step: 3, description: "Beat eggs with grated parmesan and black pepper" },
|
||||
{ step: 4, description: "Drain pasta and mix with pancetta" },
|
||||
{ step: 5, description: "Remove from heat and quickly stir in egg mixture" },
|
||||
{ step: 6, description: "Serve immediately with extra parmesan" }
|
||||
],
|
||||
servings: 4,
|
||||
prepTime: 10,
|
||||
cookTime: 15,
|
||||
category: "dinner",
|
||||
difficulty: "medium",
|
||||
imageUrl: "https://images.unsplash.com/photo-1621996346565-e3dbc353d2e5?w=500"
|
||||
},
|
||||
{
|
||||
title: "Chocolate Chip Cookies",
|
||||
description: "Soft and chewy homemade chocolate chip cookies",
|
||||
ingredients: [
|
||||
{ name: "all-purpose flour", amount: 2.25, unit: "cups" },
|
||||
{ name: "butter", amount: 1, unit: "cup" },
|
||||
{ name: "brown sugar", amount: 0.75, unit: "cup" },
|
||||
{ name: "white sugar", amount: 0.75, unit: "cup" },
|
||||
{ name: "eggs", amount: 2, unit: "whole" },
|
||||
{ name: "vanilla extract", amount: 2, unit: "tsp" },
|
||||
{ name: "baking soda", amount: 1, unit: "tsp" },
|
||||
{ name: "salt", amount: 1, unit: "tsp" },
|
||||
{ name: "chocolate chips", amount: 2, unit: "cups" }
|
||||
],
|
||||
instructions: [
|
||||
{ step: 1, description: "Preheat oven to 375°F (190°C)" },
|
||||
{ step: 2, description: "Cream butter and sugars together" },
|
||||
{ step: 3, description: "Beat in eggs and vanilla" },
|
||||
{ step: 4, description: "Mix in flour, baking soda, and salt" },
|
||||
{ step: 5, description: "Stir in chocolate chips" },
|
||||
{ step: 6, description: "Drop spoonfuls on baking sheet" },
|
||||
{ step: 7, description: "Bake for 9-11 minutes until golden brown" }
|
||||
],
|
||||
servings: 24,
|
||||
prepTime: 15,
|
||||
cookTime: 11,
|
||||
category: "dessert",
|
||||
difficulty: "easy",
|
||||
imageUrl: "https://images.unsplash.com/photo-1499636136210-6f4ee915583e?w=500"
|
||||
},
|
||||
{
|
||||
title: "Caesar Salad",
|
||||
description: "Fresh romaine lettuce with classic Caesar dressing and croutons",
|
||||
ingredients: [
|
||||
{ name: "romaine lettuce", amount: 2, unit: "heads" },
|
||||
{ name: "parmesan cheese", amount: 0.5, unit: "cup" },
|
||||
{ name: "croutons", amount: 1, unit: "cup" },
|
||||
{ name: "mayonnaise", amount: 0.5, unit: "cup" },
|
||||
{ name: "lemon juice", amount: 2, unit: "tbsp" },
|
||||
{ name: "garlic", amount: 2, unit: "cloves" },
|
||||
{ name: "anchovy paste", amount: 1, unit: "tsp" },
|
||||
{ name: "worcestershire sauce", amount: 1, unit: "tsp" },
|
||||
{ name: "black pepper", amount: 0.5, unit: "tsp" }
|
||||
],
|
||||
instructions: [
|
||||
{ step: 1, description: "Wash and chop romaine lettuce" },
|
||||
{ step: 2, description: "Make dressing by mixing mayo, lemon juice, minced garlic, anchovy paste, and worcestershire" },
|
||||
{ step: 3, description: "Toss lettuce with dressing" },
|
||||
{ step: 4, description: "Top with parmesan cheese and croutons" },
|
||||
{ step: 5, description: "Season with black pepper and serve" }
|
||||
],
|
||||
servings: 4,
|
||||
prepTime: 15,
|
||||
cookTime: 0,
|
||||
category: "lunch",
|
||||
difficulty: "easy",
|
||||
imageUrl: "https://images.unsplash.com/photo-1546793665-c74683f339c1?w=500"
|
||||
},
|
||||
{
|
||||
title: "Pancakes",
|
||||
description: "Fluffy breakfast pancakes perfect for weekend mornings",
|
||||
ingredients: [
|
||||
{ name: "all-purpose flour", amount: 1.5, unit: "cups" },
|
||||
{ name: "sugar", amount: 3, unit: "tbsp" },
|
||||
{ name: "baking powder", amount: 1, unit: "tbsp" },
|
||||
{ name: "salt", amount: 0.5, unit: "tsp" },
|
||||
{ name: "milk", amount: 1.25, unit: "cups" },
|
||||
{ name: "egg", amount: 1, unit: "whole" },
|
||||
{ name: "butter", amount: 3, unit: "tbsp" },
|
||||
{ name: "vanilla extract", amount: 1, unit: "tsp" }
|
||||
],
|
||||
instructions: [
|
||||
{ step: 1, description: "Mix dry ingredients in a large bowl" },
|
||||
{ step: 2, description: "Whisk together milk, egg, melted butter, and vanilla" },
|
||||
{ step: 3, description: "Pour wet ingredients into dry ingredients and stir until just combined" },
|
||||
{ step: 4, description: "Heat griddle or large skillet over medium heat" },
|
||||
{ step: 5, description: "Pour 1/4 cup batter for each pancake" },
|
||||
{ step: 6, description: "Cook until bubbles form on surface, then flip" },
|
||||
{ step: 7, description: "Cook until golden brown on both sides" }
|
||||
],
|
||||
servings: 4,
|
||||
prepTime: 10,
|
||||
cookTime: 15,
|
||||
category: "breakfast",
|
||||
difficulty: "easy",
|
||||
imageUrl: "https://images.unsplash.com/photo-1567620905732-2d1ec7ab7445?w=500"
|
||||
},
|
||||
{
|
||||
title: "Beef Stir Fry",
|
||||
description: "Quick and healthy beef stir fry with vegetables",
|
||||
ingredients: [
|
||||
{ name: "beef sirloin", amount: 1, unit: "lb" },
|
||||
{ name: "broccoli", amount: 2, unit: "cups" },
|
||||
{ name: "bell peppers", amount: 2, unit: "whole" },
|
||||
{ name: "carrots", amount: 2, unit: "whole" },
|
||||
{ name: "soy sauce", amount: 3, unit: "tbsp" },
|
||||
{ name: "garlic", amount: 3, unit: "cloves" },
|
||||
{ name: "ginger", amount: 1, unit: "tbsp" },
|
||||
{ name: "vegetable oil", amount: 2, unit: "tbsp" },
|
||||
{ name: "cornstarch", amount: 1, unit: "tbsp" },
|
||||
{ name: "rice", amount: 2, unit: "cups" }
|
||||
],
|
||||
instructions: [
|
||||
{ step: 1, description: "Cut beef into thin strips and marinate with soy sauce and cornstarch" },
|
||||
{ step: 2, description: "Prepare vegetables by cutting into bite-sized pieces" },
|
||||
{ step: 3, description: "Heat oil in wok or large skillet over high heat" },
|
||||
{ step: 4, description: "Stir-fry beef until browned, remove from pan" },
|
||||
{ step: 5, description: "Stir-fry vegetables until crisp-tender" },
|
||||
{ step: 6, description: "Return beef to pan, add garlic and ginger" },
|
||||
{ step: 7, description: "Stir-fry for 2 more minutes and serve over rice" }
|
||||
],
|
||||
servings: 4,
|
||||
prepTime: 20,
|
||||
cookTime: 15,
|
||||
category: "dinner",
|
||||
difficulty: "medium",
|
||||
imageUrl: "https://images.unsplash.com/photo-1603133872878-684f208fb84b?w=500"
|
||||
}
|
||||
];
|
||||
|
||||
async function seedDatabase() {
|
||||
try {
|
||||
// Connect to MongoDB
|
||||
await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/recipe-management');
|
||||
console.log('Connected to MongoDB');
|
||||
|
||||
// Clear existing recipes
|
||||
await Recipe.deleteMany({});
|
||||
console.log('Cleared existing recipes');
|
||||
|
||||
// Insert sample recipes
|
||||
await Recipe.insertMany(sampleRecipes);
|
||||
console.log('Sample recipes inserted successfully');
|
||||
|
||||
console.log(`Inserted ${sampleRecipes.length} recipes`);
|
||||
|
||||
// Close connection
|
||||
await mongoose.connection.close();
|
||||
console.log('Database connection closed');
|
||||
} catch (error) {
|
||||
console.error('Error seeding database:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
seedDatabase();
|
||||
37
backend/server.js
Normal file
37
backend/server.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mongoose = require('mongoose');
|
||||
require('dotenv').config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// MongoDB connection
|
||||
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/recipe-management';
|
||||
mongoose.connect(MONGODB_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
|
||||
const db = mongoose.connection;
|
||||
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
|
||||
db.once('open', () => {
|
||||
console.log('Connected to MongoDB');
|
||||
});
|
||||
|
||||
// Routes
|
||||
app.use('/api/recipes', require('./routes/recipes'));
|
||||
app.use('/api/users', require('./routes/users'));
|
||||
app.use('/api/selections', require('./routes/selections'));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Recipe Management API is running!' });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
23
frontend/.gitignore
vendored
Normal file
23
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
46
frontend/README.md
Normal file
46
frontend/README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
17678
frontend/package-lock.json
generated
Normal file
17678
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
51
frontend/package.json
Normal file
51
frontend/package.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "recipe-frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/dom": "^10.4.1",
|
||||
"@testing-library/jest-dom": "^6.6.4",
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.18.126",
|
||||
"@types/react": "^19.1.9",
|
||||
"@types/react-dom": "^19.1.7",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"axios": "^1.11.0",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"react-router-dom": "^6.30.1",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "http://localhost:5000",
|
||||
"devDependencies": {
|
||||
"@types/axios": "^0.9.36"
|
||||
}
|
||||
}
|
||||
145
frontend/src/App.css
Normal file
145
frontend/src/App.css
Normal file
@@ -0,0 +1,145 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Global loading styles */
|
||||
.loading-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
min-height: 100vh;
|
||||
color: #666;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #2196F3;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Global button styles */
|
||||
.btn {
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: #1976D2;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
border-color: #ddd;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover:not(:disabled) {
|
||||
background: #45a049;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #d32f2f;
|
||||
}
|
||||
|
||||
/* Reset some default styles */
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
9
frontend/src/App.test.tsx
Normal file
9
frontend/src/App.test.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
79
frontend/src/App.tsx
Normal file
79
frontend/src/App.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { AuthProvider, useAuth } from './context/AuthContext';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import Login from './pages/Login';
|
||||
import Register from './pages/Register';
|
||||
import './App.css';
|
||||
|
||||
// Protected Route component
|
||||
const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const { user, loading } = useAuth();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="loading-container">
|
||||
<div className="loading-spinner"></div>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return user ? <>{children}</> : <Navigate to="/login" />;
|
||||
};
|
||||
|
||||
// Public Route component (redirect to dashboard if already logged in)
|
||||
const PublicRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const { user, loading } = useAuth();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="loading-container">
|
||||
<div className="loading-spinner"></div>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return user ? <Navigate to="/" /> : <>{children}</>;
|
||||
};
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<Router>
|
||||
<div className="App">
|
||||
<Routes>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Dashboard />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/login"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Login />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/register"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Register />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/" />} />
|
||||
</Routes>
|
||||
</div>
|
||||
</Router>
|
||||
</AuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
172
frontend/src/components/RecipeCard.css
Normal file
172
frontend/src/components/RecipeCard.css
Normal file
@@ -0,0 +1,172 @@
|
||||
.recipe-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
.recipe-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.recipe-card.selected {
|
||||
border-color: #4CAF50;
|
||||
box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
|
||||
}
|
||||
|
||||
.recipe-image-container {
|
||||
position: relative;
|
||||
height: 200px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.recipe-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.recipe-card:hover .recipe-image {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.recipe-badges {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.difficulty-badge,
|
||||
.category-badge {
|
||||
padding: 4px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: white;
|
||||
text-transform: capitalize;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.recipe-content {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.recipe-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px 0;
|
||||
color: #333;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.recipe-description {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.4;
|
||||
margin: 0 0 16px 0;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.recipe-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
font-size: 0.75rem;
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #1976D2;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.recipe-meta {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
106
frontend/src/components/RecipeCard.tsx
Normal file
106
frontend/src/components/RecipeCard.tsx
Normal file
@@ -0,0 +1,106 @@
|
||||
import React from 'react';
|
||||
import { Recipe } from '../services/api';
|
||||
import './RecipeCard.css';
|
||||
|
||||
interface RecipeCardProps {
|
||||
recipe: Recipe;
|
||||
onAddToSelection: (recipeId: string) => void;
|
||||
onViewDetails: (recipe: Recipe) => void;
|
||||
isSelected?: boolean;
|
||||
selectedQuantity?: number;
|
||||
}
|
||||
|
||||
const RecipeCard: React.FC<RecipeCardProps> = ({
|
||||
recipe,
|
||||
onAddToSelection,
|
||||
onViewDetails,
|
||||
isSelected = false,
|
||||
selectedQuantity = 0,
|
||||
}) => {
|
||||
const getDifficultyColor = (difficulty: string) => {
|
||||
switch (difficulty) {
|
||||
case 'easy': return '#4CAF50';
|
||||
case 'medium': return '#FF9800';
|
||||
case 'hard': return '#F44336';
|
||||
default: return '#757575';
|
||||
}
|
||||
};
|
||||
|
||||
const getCategoryColor = (category: string) => {
|
||||
switch (category) {
|
||||
case 'breakfast': return '#FFE082';
|
||||
case 'lunch': return '#81C784';
|
||||
case 'dinner': return '#64B5F6';
|
||||
case 'dessert': return '#F48FB1';
|
||||
case 'snack': return '#FFB74D';
|
||||
case 'appetizer': return '#A1C181';
|
||||
default: return '#E0E0E0';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`recipe-card ${isSelected ? 'selected' : ''}`}>
|
||||
<div className="recipe-image-container">
|
||||
<img
|
||||
src={recipe.imageUrl || '/placeholder-recipe.jpg'}
|
||||
alt={recipe.title}
|
||||
className="recipe-image"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).src = '/placeholder-recipe.jpg';
|
||||
}}
|
||||
/>
|
||||
<div className="recipe-badges">
|
||||
<span
|
||||
className="difficulty-badge"
|
||||
style={{ backgroundColor: getDifficultyColor(recipe.difficulty) }}
|
||||
>
|
||||
{recipe.difficulty}
|
||||
</span>
|
||||
<span
|
||||
className="category-badge"
|
||||
style={{ backgroundColor: getCategoryColor(recipe.category) }}
|
||||
>
|
||||
{recipe.category}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipe-content">
|
||||
<h3 className="recipe-title">{recipe.title}</h3>
|
||||
<p className="recipe-description">{recipe.description}</p>
|
||||
|
||||
<div className="recipe-meta">
|
||||
<div className="meta-item">
|
||||
<span className="meta-label">Prep:</span>
|
||||
<span className="meta-value">{recipe.prepTime}min</span>
|
||||
</div>
|
||||
<div className="meta-item">
|
||||
<span className="meta-label">Cook:</span>
|
||||
<span className="meta-value">{recipe.cookTime}min</span>
|
||||
</div>
|
||||
<div className="meta-item">
|
||||
<span className="meta-label">Serves:</span>
|
||||
<span className="meta-value">{recipe.servings}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipe-actions">
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
onClick={() => onViewDetails(recipe)}
|
||||
>
|
||||
View Details
|
||||
</button>
|
||||
<button
|
||||
className={`btn ${isSelected ? 'btn-success' : 'btn-primary'}`}
|
||||
onClick={() => onAddToSelection(recipe._id)}
|
||||
>
|
||||
{isSelected ? `Added (${selectedQuantity})` : 'Add to Menu'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeCard;
|
||||
133
frontend/src/components/RecipeList.css
Normal file
133
frontend/src/components/RecipeList.css
Normal file
@@ -0,0 +1,133 @@
|
||||
.recipe-list-container {
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.filters-container {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 24px;
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr 1fr;
|
||||
gap: 16px;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.filter-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.filter-group label {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.filter-input,
|
||||
.filter-select {
|
||||
padding: 10px 12px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
transition: border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.filter-input:focus,
|
||||
.filter-select:focus {
|
||||
outline: none;
|
||||
border-color: #2196F3;
|
||||
}
|
||||
|
||||
.recipes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 24px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #2196F3;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.error-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
background: #fff5f5;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #fed7d7;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #e53e3e;
|
||||
font-weight: 600;
|
||||
margin-bottom: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.no-recipes {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #666;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.no-recipes p {
|
||||
font-size: 1.1rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.filters-container {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.recipes-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.recipe-list-container {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.filters-container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.recipes-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
194
frontend/src/components/RecipeList.tsx
Normal file
194
frontend/src/components/RecipeList.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Recipe, recipesAPI, selectionsAPI, UserSelection } from '../services/api';
|
||||
import RecipeCard from './RecipeCard';
|
||||
import RecipeModal from './RecipeModal';
|
||||
import './RecipeList.css';
|
||||
|
||||
interface RecipeListProps {
|
||||
onSelectionUpdate?: (selection: UserSelection) => void;
|
||||
}
|
||||
|
||||
const RecipeList: React.FC<RecipeListProps> = ({ onSelectionUpdate }) => {
|
||||
const [recipes, setRecipes] = useState<Recipe[]>([]);
|
||||
const [userSelection, setUserSelection] = useState<UserSelection | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selectedRecipe, setSelectedRecipe] = useState<Recipe | null>(null);
|
||||
const [filters, setFilters] = useState({
|
||||
category: '',
|
||||
difficulty: '',
|
||||
search: '',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetchRecipes();
|
||||
fetchUserSelection();
|
||||
}, [filters]);
|
||||
|
||||
const fetchRecipes = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await recipesAPI.getAll(filters);
|
||||
setRecipes(response.data as Recipe[]);
|
||||
} catch (error: any) {
|
||||
setError(error.response?.data?.error || 'Failed to fetch recipes');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchUserSelection = async () => {
|
||||
try {
|
||||
const response = await selectionsAPI.get();
|
||||
setUserSelection(response.data as UserSelection);
|
||||
if (onSelectionUpdate) {
|
||||
onSelectionUpdate(response.data as UserSelection);
|
||||
}
|
||||
} catch (error: any) {
|
||||
// User might not have any selections yet, which is fine
|
||||
console.log('No user selections found');
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddToSelection = async (recipeId: string) => {
|
||||
try {
|
||||
const response = await selectionsAPI.addRecipe(recipeId, 1);
|
||||
setUserSelection(response.data as UserSelection);
|
||||
if (onSelectionUpdate) {
|
||||
onSelectionUpdate(response.data as UserSelection);
|
||||
}
|
||||
} catch (error: any) {
|
||||
setError(error.response?.data?.error || 'Failed to add recipe to selection');
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewDetails = (recipe: Recipe) => {
|
||||
setSelectedRecipe(recipe);
|
||||
};
|
||||
|
||||
const handleCloseModal = () => {
|
||||
setSelectedRecipe(null);
|
||||
};
|
||||
|
||||
const handleFilterChange = (filterType: string, value: string) => {
|
||||
setFilters(prev => ({
|
||||
...prev,
|
||||
[filterType]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
const isRecipeSelected = (recipeId: string) => {
|
||||
return userSelection?.selectedRecipes.some(
|
||||
selection => selection.recipeId._id === recipeId
|
||||
) || false;
|
||||
};
|
||||
|
||||
const getSelectedQuantity = (recipeId: string) => {
|
||||
const selection = userSelection?.selectedRecipes.find(
|
||||
selection => selection.recipeId._id === recipeId
|
||||
);
|
||||
return selection?.quantity || 0;
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="loading-container">
|
||||
<div className="loading-spinner"></div>
|
||||
<p>Loading recipes...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="error-container">
|
||||
<p className="error-message">{error}</p>
|
||||
<button className="btn btn-primary" onClick={fetchRecipes}>
|
||||
Try Again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipe-list-container">
|
||||
<div className="filters-container">
|
||||
<div className="filter-group">
|
||||
<label htmlFor="search">Search Recipes:</label>
|
||||
<input
|
||||
id="search"
|
||||
type="text"
|
||||
placeholder="Search by title or description..."
|
||||
value={filters.search}
|
||||
onChange={(e) => handleFilterChange('search', e.target.value)}
|
||||
className="filter-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="filter-group">
|
||||
<label htmlFor="category">Category:</label>
|
||||
<select
|
||||
id="category"
|
||||
value={filters.category}
|
||||
onChange={(e) => handleFilterChange('category', e.target.value)}
|
||||
className="filter-select"
|
||||
>
|
||||
<option value="">All Categories</option>
|
||||
<option value="breakfast">Breakfast</option>
|
||||
<option value="lunch">Lunch</option>
|
||||
<option value="dinner">Dinner</option>
|
||||
<option value="dessert">Dessert</option>
|
||||
<option value="snack">Snack</option>
|
||||
<option value="appetizer">Appetizer</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="filter-group">
|
||||
<label htmlFor="difficulty">Difficulty:</label>
|
||||
<select
|
||||
id="difficulty"
|
||||
value={filters.difficulty}
|
||||
onChange={(e) => handleFilterChange('difficulty', e.target.value)}
|
||||
className="filter-select"
|
||||
>
|
||||
<option value="">All Difficulties</option>
|
||||
<option value="easy">Easy</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="hard">Hard</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipes-grid">
|
||||
{recipes.length === 0 ? (
|
||||
<div className="no-recipes">
|
||||
<p>No recipes found matching your criteria.</p>
|
||||
</div>
|
||||
) : (
|
||||
recipes.map((recipe) => (
|
||||
<RecipeCard
|
||||
key={recipe._id}
|
||||
recipe={recipe}
|
||||
onAddToSelection={handleAddToSelection}
|
||||
onViewDetails={handleViewDetails}
|
||||
isSelected={isRecipeSelected(recipe._id)}
|
||||
selectedQuantity={getSelectedQuantity(recipe._id)}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedRecipe && (
|
||||
<RecipeModal
|
||||
recipe={selectedRecipe}
|
||||
onClose={handleCloseModal}
|
||||
onAddToSelection={handleAddToSelection}
|
||||
isSelected={isRecipeSelected(selectedRecipe._id)}
|
||||
selectedQuantity={getSelectedQuantity(selectedRecipe._id)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeList;
|
||||
274
frontend/src/components/RecipeModal.css
Normal file
274
frontend/src/components/RecipeModal.css
Normal file
@@ -0,0 +1,274 @@
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
max-height: 90vh;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 16px 20px 0 20px;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 2rem;
|
||||
cursor: pointer;
|
||||
color: #666;
|
||||
padding: 0;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background: #f0f0f0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0 20px 20px 20px;
|
||||
}
|
||||
|
||||
.recipe-image-section {
|
||||
position: relative;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.modal-recipe-image {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
object-fit: cover;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.modal-badges {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.difficulty-badge,
|
||||
.category-badge {
|
||||
padding: 6px 12px;
|
||||
border-radius: 16px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: white;
|
||||
text-transform: capitalize;
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.recipe-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.modal-recipe-title {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
color: #333;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.modal-recipe-description {
|
||||
font-size: 1.1rem;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.recipe-meta-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.meta-card {
|
||||
background: #f8f9fa;
|
||||
padding: 16px;
|
||||
border-radius: 12px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.ingredients-section h3,
|
||||
.instructions-section h3 {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 16px 0;
|
||||
color: #333;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.ingredients-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.ingredient-item {
|
||||
background: #f8f9fa;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-left: 4px solid #2196F3;
|
||||
}
|
||||
|
||||
.ingredient-amount {
|
||||
font-weight: 600;
|
||||
color: #2196F3;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.ingredient-name {
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.instructions-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.instruction-item {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.instruction-step {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.instruction-text {
|
||||
flex: 1;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 20px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.btn-large {
|
||||
width: 100%;
|
||||
padding: 16px 24px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.modal-backdrop {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
max-height: 95vh;
|
||||
}
|
||||
|
||||
.modal-recipe-image {
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.modal-recipe-title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.recipe-meta-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.ingredients-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.instruction-item {
|
||||
gap: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.recipe-meta-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 0 16px 16px 16px;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
146
frontend/src/components/RecipeModal.tsx
Normal file
146
frontend/src/components/RecipeModal.tsx
Normal file
@@ -0,0 +1,146 @@
|
||||
import React from 'react';
|
||||
import { Recipe } from '../services/api';
|
||||
import './RecipeModal.css';
|
||||
|
||||
interface RecipeModalProps {
|
||||
recipe: Recipe;
|
||||
onClose: () => void;
|
||||
onAddToSelection: (recipeId: string) => void;
|
||||
isSelected: boolean;
|
||||
selectedQuantity: number;
|
||||
}
|
||||
|
||||
const RecipeModal: React.FC<RecipeModalProps> = ({
|
||||
recipe,
|
||||
onClose,
|
||||
onAddToSelection,
|
||||
isSelected,
|
||||
selectedQuantity,
|
||||
}) => {
|
||||
const handleBackdropClick = (e: React.MouseEvent) => {
|
||||
if (e.target === e.currentTarget) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
const getDifficultyColor = (difficulty: string) => {
|
||||
switch (difficulty) {
|
||||
case 'easy': return '#4CAF50';
|
||||
case 'medium': return '#FF9800';
|
||||
case 'hard': return '#F44336';
|
||||
default: return '#757575';
|
||||
}
|
||||
};
|
||||
|
||||
const getCategoryColor = (category: string) => {
|
||||
switch (category) {
|
||||
case 'breakfast': return '#FFE082';
|
||||
case 'lunch': return '#81C784';
|
||||
case 'dinner': return '#64B5F6';
|
||||
case 'dessert': return '#F48FB1';
|
||||
case 'snack': return '#FFB74D';
|
||||
case 'appetizer': return '#A1C181';
|
||||
default: return '#E0E0E0';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop" onClick={handleBackdropClick}>
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<button className="close-button" onClick={onClose}>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="modal-body">
|
||||
<div className="recipe-image-section">
|
||||
<img
|
||||
src={recipe.imageUrl || '/placeholder-recipe.jpg'}
|
||||
alt={recipe.title}
|
||||
className="modal-recipe-image"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).src = '/placeholder-recipe.jpg';
|
||||
}}
|
||||
/>
|
||||
<div className="modal-badges">
|
||||
<span
|
||||
className="difficulty-badge"
|
||||
style={{ backgroundColor: getDifficultyColor(recipe.difficulty) }}
|
||||
>
|
||||
{recipe.difficulty}
|
||||
</span>
|
||||
<span
|
||||
className="category-badge"
|
||||
style={{ backgroundColor: getCategoryColor(recipe.category) }}
|
||||
>
|
||||
{recipe.category}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipe-details">
|
||||
<h2 className="modal-recipe-title">{recipe.title}</h2>
|
||||
<p className="modal-recipe-description">{recipe.description}</p>
|
||||
|
||||
<div className="recipe-meta-grid">
|
||||
<div className="meta-card">
|
||||
<span className="meta-label">Prep Time</span>
|
||||
<span className="meta-value">{recipe.prepTime} min</span>
|
||||
</div>
|
||||
<div className="meta-card">
|
||||
<span className="meta-label">Cook Time</span>
|
||||
<span className="meta-value">{recipe.cookTime} min</span>
|
||||
</div>
|
||||
<div className="meta-card">
|
||||
<span className="meta-label">Total Time</span>
|
||||
<span className="meta-value">{recipe.prepTime + recipe.cookTime} min</span>
|
||||
</div>
|
||||
<div className="meta-card">
|
||||
<span className="meta-label">Servings</span>
|
||||
<span className="meta-value">{recipe.servings}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="ingredients-section">
|
||||
<h3>Ingredients</h3>
|
||||
<ul className="ingredients-list">
|
||||
{recipe.ingredients.map((ingredient, index) => (
|
||||
<li key={index} className="ingredient-item">
|
||||
<span className="ingredient-amount">
|
||||
{ingredient.amount} {ingredient.unit}
|
||||
</span>
|
||||
<span className="ingredient-name">{ingredient.name}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div className="instructions-section">
|
||||
<h3>Instructions</h3>
|
||||
<ol className="instructions-list">
|
||||
{recipe.instructions.map((instruction) => (
|
||||
<li key={instruction.step} className="instruction-item">
|
||||
<div className="instruction-step">{instruction.step}</div>
|
||||
<div className="instruction-text">{instruction.description}</div>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="modal-footer">
|
||||
<button
|
||||
className={`btn ${isSelected ? 'btn-success' : 'btn-primary'} btn-large`}
|
||||
onClick={() => onAddToSelection(recipe._id)}
|
||||
>
|
||||
{isSelected ? `Added to Menu (${selectedQuantity})` : 'Add to Menu'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeModal;
|
||||
364
frontend/src/components/ShoppingList.css
Normal file
364
frontend/src/components/ShoppingList.css
Normal file
@@ -0,0 +1,364 @@
|
||||
.shopping-list-container {
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.error-banner {
|
||||
background: #fee;
|
||||
border: 1px solid #fcc;
|
||||
color: #c33;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.error-banner button {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #c33;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-state h2 {
|
||||
margin: 0 0 12px 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.shopping-list-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 32px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.header-info h2 {
|
||||
margin: 0 0 8px 0;
|
||||
color: #333;
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.header-info p {
|
||||
margin: 0;
|
||||
color: #666;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #d32f2f;
|
||||
}
|
||||
|
||||
.btn-danger:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.shopping-list-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 32px;
|
||||
}
|
||||
|
||||
.selected-recipes-section h3,
|
||||
.aggregated-ingredients-section h3 {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 20px 0;
|
||||
color: #333;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.selected-recipes-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.selected-recipe-item {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.recipe-info {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.recipe-thumbnail {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 8px;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.recipe-details {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.recipe-details h4 {
|
||||
margin: 0 0 4px 0;
|
||||
font-size: 1.1rem;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.recipe-details p {
|
||||
margin: 0 0 4px 0;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.recipe-meta {
|
||||
font-size: 0.8rem;
|
||||
color: #999;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.quantity-controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.quantity-controls label {
|
||||
font-size: 0.8rem;
|
||||
color: #666;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.quantity-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8px;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.quantity-btn {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.quantity-btn:hover:not(:disabled) {
|
||||
background: #1976D2;
|
||||
}
|
||||
|
||||
.quantity-btn:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.quantity-display {
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
border-radius: 4px;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.remove-btn:hover:not(:disabled) {
|
||||
background: #ffebee;
|
||||
}
|
||||
|
||||
.remove-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.no-ingredients {
|
||||
text-align: center;
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
padding: 40px 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.ingredients-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.ingredient-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
border-left: 4px solid #4CAF50;
|
||||
}
|
||||
|
||||
.ingredient-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.ingredient-name {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.ingredient-total {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: #4CAF50;
|
||||
background: #e8f5e8;
|
||||
padding: 4px 12px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.ingredient-breakdown {
|
||||
border-top: 1px solid #e0e0e0;
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.breakdown-label {
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.recipe-breakdown {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.recipe-breakdown-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 0.9rem;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.recipe-name {
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.recipe-amount {
|
||||
color: #666;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.shopping-list-content {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.shopping-list-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.selected-recipe-item {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.recipe-info {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.quantity-controls {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.shopping-list-container {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.ingredient-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.recipe-breakdown-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
}
|
||||
}
|
||||
193
frontend/src/components/ShoppingList.tsx
Normal file
193
frontend/src/components/ShoppingList.tsx
Normal file
@@ -0,0 +1,193 @@
|
||||
import React, { useState } from 'react';
|
||||
import { UserSelection, selectionsAPI } from '../services/api';
|
||||
import './ShoppingList.css';
|
||||
|
||||
interface ShoppingListProps {
|
||||
userSelection: UserSelection | null;
|
||||
onSelectionUpdate: (selection: UserSelection) => void;
|
||||
}
|
||||
|
||||
const ShoppingList: React.FC<ShoppingListProps> = ({ userSelection, onSelectionUpdate }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handleQuantityChange = async (recipeId: string, newQuantity: number) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
if (newQuantity <= 0) {
|
||||
const response = await selectionsAPI.removeRecipe(recipeId);
|
||||
onSelectionUpdate(response.data);
|
||||
} else {
|
||||
const response = await selectionsAPI.updateQuantity(recipeId, newQuantity);
|
||||
onSelectionUpdate(response.data);
|
||||
}
|
||||
} catch (error: any) {
|
||||
setError(error.response?.data?.error || 'Failed to update quantity');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveRecipe = async (recipeId: string) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const response = await selectionsAPI.removeRecipe(recipeId);
|
||||
onSelectionUpdate(response.data);
|
||||
} catch (error: any) {
|
||||
setError(error.response?.data?.error || 'Failed to remove recipe');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClearAll = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const response = await selectionsAPI.clear();
|
||||
onSelectionUpdate(response.data);
|
||||
} catch (error: any) {
|
||||
setError(error.response?.data?.error || 'Failed to clear selections');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getTotalRecipes = () => {
|
||||
return userSelection?.selectedRecipes.reduce((total, recipe) => total + recipe.quantity, 0) || 0;
|
||||
};
|
||||
|
||||
if (!userSelection || userSelection.selectedRecipes.length === 0) {
|
||||
return (
|
||||
<div className="shopping-list-container">
|
||||
<div className="empty-state">
|
||||
<h2>Your Menu is Empty</h2>
|
||||
<p>Start by selecting some recipes to create your shopping list!</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="shopping-list-container">
|
||||
{error && (
|
||||
<div className="error-banner">
|
||||
<p>{error}</p>
|
||||
<button onClick={() => setError(null)}>×</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="shopping-list-header">
|
||||
<div className="header-info">
|
||||
<h2>Your Menu & Shopping List</h2>
|
||||
<p>{userSelection.selectedRecipes.length} recipes • {getTotalRecipes()} total servings</p>
|
||||
</div>
|
||||
<button
|
||||
className="btn btn-danger"
|
||||
onClick={handleClearAll}
|
||||
disabled={loading}
|
||||
>
|
||||
Clear All
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="shopping-list-content">
|
||||
<div className="selected-recipes-section">
|
||||
<h3>Selected Recipes</h3>
|
||||
<div className="selected-recipes-list">
|
||||
{userSelection.selectedRecipes.map((selection) => (
|
||||
<div key={selection.recipeId._id} className="selected-recipe-item">
|
||||
<div className="recipe-info">
|
||||
<img
|
||||
src={selection.recipeId.imageUrl || '/placeholder-recipe.jpg'}
|
||||
alt={selection.recipeId.title}
|
||||
className="recipe-thumbnail"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).src = '/placeholder-recipe.jpg';
|
||||
}}
|
||||
/>
|
||||
<div className="recipe-details">
|
||||
<h4>{selection.recipeId.title}</h4>
|
||||
<p>{selection.recipeId.description}</p>
|
||||
<span className="recipe-meta">
|
||||
{selection.recipeId.category} • {selection.recipeId.difficulty} •
|
||||
{selection.recipeId.prepTime + selection.recipeId.cookTime} min
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="quantity-controls">
|
||||
<label>Quantity:</label>
|
||||
<div className="quantity-input-group">
|
||||
<button
|
||||
className="quantity-btn"
|
||||
onClick={() => handleQuantityChange(selection.recipeId._id, selection.quantity - 1)}
|
||||
disabled={loading || selection.quantity <= 1}
|
||||
>
|
||||
-
|
||||
</button>
|
||||
<span className="quantity-display">{selection.quantity}</span>
|
||||
<button
|
||||
className="quantity-btn"
|
||||
onClick={() => handleQuantityChange(selection.recipeId._id, selection.quantity + 1)}
|
||||
disabled={loading}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
className="remove-btn"
|
||||
onClick={() => handleRemoveRecipe(selection.recipeId._id)}
|
||||
disabled={loading}
|
||||
title="Remove recipe"
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="aggregated-ingredients-section">
|
||||
<h3>Shopping List</h3>
|
||||
{userSelection.aggregatedIngredients.length === 0 ? (
|
||||
<p className="no-ingredients">No ingredients to show.</p>
|
||||
) : (
|
||||
<div className="ingredients-grid">
|
||||
{userSelection.aggregatedIngredients.map((ingredient, index) => (
|
||||
<div key={index} className="ingredient-card">
|
||||
<div className="ingredient-header">
|
||||
<h4 className="ingredient-name">{ingredient.name}</h4>
|
||||
<span className="ingredient-total">
|
||||
{ingredient.totalAmount} {ingredient.unit}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="ingredient-breakdown">
|
||||
<span className="breakdown-label">Used in:</span>
|
||||
<ul className="recipe-breakdown">
|
||||
{ingredient.recipes.map((recipe, recipeIndex) => (
|
||||
<li key={recipeIndex} className="recipe-breakdown-item">
|
||||
<span className="recipe-name">{recipe.recipeTitle}</span>
|
||||
<span className="recipe-amount">
|
||||
{recipe.amount} {ingredient.unit} × {recipe.quantity}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ShoppingList;
|
||||
106
frontend/src/context/AuthContext.tsx
Normal file
106
frontend/src/context/AuthContext.tsx
Normal file
@@ -0,0 +1,106 @@
|
||||
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
||||
import { authAPI, User } from '../services/api';
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
register: (username: string, email: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useAuth must be used within an AuthProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
interface AuthProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [token, setToken] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const initAuth = async () => {
|
||||
const savedToken = localStorage.getItem('token');
|
||||
const savedUser = localStorage.getItem('user');
|
||||
|
||||
if (savedToken && savedUser) {
|
||||
setToken(savedToken);
|
||||
setUser(JSON.parse(savedUser));
|
||||
|
||||
try {
|
||||
// Verify token is still valid
|
||||
await authAPI.getProfile();
|
||||
} catch (error) {
|
||||
// Token is invalid, clear auth data
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
initAuth();
|
||||
}, []);
|
||||
|
||||
const login = async (email: string, password: string) => {
|
||||
try {
|
||||
const response = await authAPI.login({ email, password });
|
||||
const { token: newToken, user: newUser } = response.data;
|
||||
|
||||
setToken(newToken);
|
||||
setUser(newUser);
|
||||
|
||||
localStorage.setItem('token', newToken);
|
||||
localStorage.setItem('user', JSON.stringify(newUser));
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response?.data?.error || 'Login failed');
|
||||
}
|
||||
};
|
||||
|
||||
const register = async (username: string, email: string, password: string) => {
|
||||
try {
|
||||
const response = await authAPI.register({ username, email, password });
|
||||
const { token: newToken, user: newUser } = response.data;
|
||||
|
||||
setToken(newToken);
|
||||
setUser(newUser);
|
||||
|
||||
localStorage.setItem('token', newToken);
|
||||
localStorage.setItem('user', JSON.stringify(newUser));
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response?.data?.error || 'Registration failed');
|
||||
}
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
};
|
||||
|
||||
const value = {
|
||||
user,
|
||||
token,
|
||||
login,
|
||||
register,
|
||||
logout,
|
||||
loading,
|
||||
};
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
13
frontend/src/index.css
Normal file
13
frontend/src/index.css
Normal file
@@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
19
frontend/src/index.tsx
Normal file
19
frontend/src/index.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
1
frontend/src/logo.svg
Normal file
1
frontend/src/logo.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
146
frontend/src/pages/Auth.css
Normal file
146
frontend/src/pages/Auth.css
Normal file
@@ -0,0 +1,146 @@
|
||||
.auth-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
padding: 40px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
color: #666;
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s ease;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #2196F3;
|
||||
box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
|
||||
}
|
||||
|
||||
.form-group input:disabled {
|
||||
background: #f5f5f5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #fee;
|
||||
border: 1px solid #fcc;
|
||||
color: #c33;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-button {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 14px 20px;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.auth-button:hover:not(:disabled) {
|
||||
background: #1976D2;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.auth-button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
text-align: center;
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.auth-footer p {
|
||||
color: #666;
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.auth-link {
|
||||
color: #2196F3;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.auth-link:hover {
|
||||
color: #1976D2;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.auth-container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
}
|
||||
202
frontend/src/pages/Dashboard.css
Normal file
202
frontend/src/pages/Dashboard.css
Normal file
@@ -0,0 +1,202 @@
|
||||
.dashboard {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.dashboard-header {
|
||||
background: white;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.welcome-text {
|
||||
color: #666;
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.stats-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #2196F3;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.8rem;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logout-button {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.logout-button:hover {
|
||||
background: #d32f2f;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.tab-navigation {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
flex: 1;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 16px 24px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
border-bottom: 3px solid transparent;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tab-button:hover {
|
||||
color: #333;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.tab-button.active {
|
||||
color: #2196F3;
|
||||
border-bottom-color: #2196F3;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.tab-badge {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
min-width: 20px;
|
||||
height: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.dashboard-content {
|
||||
min-height: calc(100vh - 140px);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.header-content {
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.stats-container {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.tab-navigation {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.tab-button.active {
|
||||
border-bottom-color: #e0e0e0;
|
||||
border-left: 3px solid #2196F3;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.header-content {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.stats-container {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
padding: 12px 16px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
85
frontend/src/pages/Dashboard.tsx
Normal file
85
frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import RecipeList from '../components/RecipeList';
|
||||
import ShoppingList from '../components/ShoppingList';
|
||||
import { UserSelection } from '../services/api';
|
||||
import './Dashboard.css';
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
const { user, logout } = useAuth();
|
||||
const [userSelection, setUserSelection] = useState<UserSelection | null>(null);
|
||||
const [activeTab, setActiveTab] = useState<'recipes' | 'shopping'>('recipes');
|
||||
|
||||
const handleSelectionUpdate = (selection: UserSelection) => {
|
||||
setUserSelection(selection);
|
||||
};
|
||||
|
||||
const getSelectedRecipesCount = () => {
|
||||
return userSelection?.selectedRecipes.length || 0;
|
||||
};
|
||||
|
||||
const getTotalIngredientsCount = () => {
|
||||
return userSelection?.aggregatedIngredients.length || 0;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="dashboard">
|
||||
<header className="dashboard-header">
|
||||
<div className="header-content">
|
||||
<div className="header-left">
|
||||
<h1 className="app-title">Recipe Manager</h1>
|
||||
<p className="welcome-text">Welcome back, {user?.username}!</p>
|
||||
</div>
|
||||
|
||||
<div className="header-right">
|
||||
<div className="stats-container">
|
||||
<div className="stat-item">
|
||||
<span className="stat-number">{getSelectedRecipesCount()}</span>
|
||||
<span className="stat-label">Selected Recipes</span>
|
||||
</div>
|
||||
<div className="stat-item">
|
||||
<span className="stat-number">{getTotalIngredientsCount()}</span>
|
||||
<span className="stat-label">Ingredients</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button className="logout-button" onClick={logout}>
|
||||
Logout
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav className="tab-navigation">
|
||||
<button
|
||||
className={`tab-button ${activeTab === 'recipes' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('recipes')}
|
||||
>
|
||||
Browse Recipes
|
||||
</button>
|
||||
<button
|
||||
className={`tab-button ${activeTab === 'shopping' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('shopping')}
|
||||
>
|
||||
My Menu & Shopping List
|
||||
{getSelectedRecipesCount() > 0 && (
|
||||
<span className="tab-badge">{getSelectedRecipesCount()}</span>
|
||||
)}
|
||||
</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main className="dashboard-content">
|
||||
{activeTab === 'recipes' ? (
|
||||
<RecipeList onSelectionUpdate={handleSelectionUpdate} />
|
||||
) : (
|
||||
<ShoppingList
|
||||
userSelection={userSelection}
|
||||
onSelectionUpdate={handleSelectionUpdate}
|
||||
/>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
98
frontend/src/pages/Login.tsx
Normal file
98
frontend/src/pages/Login.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import './Auth.css';
|
||||
|
||||
const Login: React.FC = () => {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const { login } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email || !password) {
|
||||
setError('Please fill in all fields');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
await login(email, password);
|
||||
navigate('/');
|
||||
} catch (error: any) {
|
||||
setError(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<div className="auth-header">
|
||||
<h1>Welcome Back</h1>
|
||||
<p>Sign in to your recipe management account</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="auth-form">
|
||||
{error && (
|
||||
<div className="error-message">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="email">Email Address</label>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="Enter your email"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter your password"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="auth-button"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Signing In...' : 'Sign In'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-footer">
|
||||
<p>
|
||||
Don't have an account?{' '}
|
||||
<Link to="/register" className="auth-link">
|
||||
Sign up here
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
136
frontend/src/pages/Register.tsx
Normal file
136
frontend/src/pages/Register.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import './Auth.css';
|
||||
|
||||
const Register: React.FC = () => {
|
||||
const [username, setUsername] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const { register } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!username || !email || !password || !confirmPassword) {
|
||||
setError('Please fill in all fields');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
setError('Passwords do not match');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
setError('Password must be at least 6 characters long');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
await register(username, email, password);
|
||||
navigate('/');
|
||||
} catch (error: any) {
|
||||
setError(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<div className="auth-header">
|
||||
<h1>Create Account</h1>
|
||||
<p>Join us to start managing your recipes</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="auth-form">
|
||||
{error && (
|
||||
<div className="error-message">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="username">Username</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="Choose a username"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="email">Email Address</label>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="Enter your email"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Create a password (min 6 characters)"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="confirmPassword">Confirm Password</label>
|
||||
<input
|
||||
id="confirmPassword"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
placeholder="Confirm your password"
|
||||
disabled={loading}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="auth-button"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Creating Account...' : 'Create Account'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-footer">
|
||||
<p>
|
||||
Already have an account?{' '}
|
||||
<Link to="/login" className="auth-link">
|
||||
Sign in here
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Register;
|
||||
1
frontend/src/react-app-env.d.ts
vendored
Normal file
1
frontend/src/react-app-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
15
frontend/src/reportWebVitals.ts
Normal file
15
frontend/src/reportWebVitals.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ReportHandler } from 'web-vitals';
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
||||
143
frontend/src/services/api.ts
Normal file
143
frontend/src/services/api.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
// Add auth token to requests
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
// Handle auth errors
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export interface Recipe {
|
||||
_id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
ingredients: Array<{
|
||||
name: string;
|
||||
amount: number;
|
||||
unit: string;
|
||||
}>;
|
||||
instructions: Array<{
|
||||
step: number;
|
||||
description: string;
|
||||
}>;
|
||||
servings: number;
|
||||
prepTime: number;
|
||||
cookTime: number;
|
||||
category: 'breakfast' | 'lunch' | 'dinner' | 'dessert' | 'snack' | 'appetizer';
|
||||
difficulty: 'easy' | 'medium' | 'hard';
|
||||
imageUrl: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface AuthResponse {
|
||||
token: string;
|
||||
user: User;
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
data: T;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface UserSelection {
|
||||
_id: string;
|
||||
userId: string;
|
||||
selectedRecipes: Array<{
|
||||
recipeId: Recipe;
|
||||
quantity: number;
|
||||
addedAt: string;
|
||||
}>;
|
||||
aggregatedIngredients: Array<{
|
||||
name: string;
|
||||
totalAmount: number;
|
||||
unit: string;
|
||||
recipes: Array<{
|
||||
recipeId: string;
|
||||
recipeTitle: string;
|
||||
amount: number;
|
||||
quantity: number;
|
||||
}>;
|
||||
}>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
// Auth API
|
||||
export const authAPI = {
|
||||
register: (userData: { username: string; email: string; password: string }) =>
|
||||
api.post<AuthResponse>('/users/register', userData),
|
||||
|
||||
login: (credentials: { email: string; password: string }) =>
|
||||
api.post<AuthResponse>('/users/login', credentials),
|
||||
|
||||
getProfile: () =>
|
||||
api.get<User>('/users/profile'),
|
||||
};
|
||||
|
||||
// Recipes API
|
||||
export const recipesAPI = {
|
||||
getAll: (params?: { category?: string; difficulty?: string; search?: string }) =>
|
||||
api.get('/recipes', { params }),
|
||||
|
||||
getById: (id: string) =>
|
||||
api.get(`/recipes/${id}`),
|
||||
|
||||
create: (recipe: Omit<Recipe, '_id' | 'createdAt'>) =>
|
||||
api.post('/recipes', recipe),
|
||||
|
||||
update: (id: string, recipe: Partial<Recipe>) =>
|
||||
api.put(`/recipes/${id}`, recipe),
|
||||
|
||||
delete: (id: string) =>
|
||||
api.delete(`/recipes/${id}`),
|
||||
};
|
||||
|
||||
// Selections API
|
||||
export const selectionsAPI = {
|
||||
get: () =>
|
||||
api.get<UserSelection>('/selections'),
|
||||
|
||||
addRecipe: (recipeId: string, quantity: number = 1) =>
|
||||
api.post<UserSelection>('/selections/add', { recipeId, quantity }),
|
||||
|
||||
updateQuantity: (recipeId: string, quantity: number) =>
|
||||
api.put<UserSelection>('/selections/update', { recipeId, quantity }),
|
||||
|
||||
removeRecipe: (recipeId: string) =>
|
||||
api.delete<UserSelection>(`/selections/remove/${recipeId}`),
|
||||
|
||||
clear: () =>
|
||||
api.delete<UserSelection>('/selections/clear'),
|
||||
};
|
||||
|
||||
export default api;
|
||||
5
frontend/src/setupTests.ts
Normal file
5
frontend/src/setupTests.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
||||
26
frontend/tsconfig.json
Normal file
26
frontend/tsconfig.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user