Datei-Struktur ordentlich bereinigt
This commit is contained in:
24
frontend/.gitignore
vendored
Normal file
24
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
138
frontend/Dockerfile
Normal file
138
frontend/Dockerfile
Normal file
@@ -0,0 +1,138 @@
|
||||
# Frontend Dockerfile
|
||||
FROM node:18-alpine AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build arguments for environment variables
|
||||
# For local network: VITE_API_URL will be set dynamically by the container hostname
|
||||
ARG VITE_API_URL
|
||||
ENV VITE_API_URL=$VITE_API_URL
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Production stage with Nginx
|
||||
FROM nginx:alpine AS production
|
||||
|
||||
# Install curl for healthcheck
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
# Copy custom nginx configuration
|
||||
COPY <<EOF /etc/nginx/nginx.conf
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
|
||||
'\$status \$body_bytes_sent "\$http_referer" '
|
||||
'"\$http_user_agent" "\$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/json;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Handle client-side routing
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Security headers for HTML files
|
||||
location ~* \.html$ {
|
||||
expires epoch;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Copy built application from builder stage
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nginx_user && \
|
||||
adduser -S nginx_user -u 1001 -G nginx_user
|
||||
|
||||
# Set proper permissions
|
||||
RUN chown -R nginx_user:nginx_user /usr/share/nginx/html && \
|
||||
chown -R nginx_user:nginx_user /var/cache/nginx && \
|
||||
chown -R nginx_user:nginx_user /var/log/nginx && \
|
||||
chown -R nginx_user:nginx_user /etc/nginx/conf.d
|
||||
|
||||
# Create nginx runtime directories
|
||||
RUN touch /var/run/nginx.pid && \
|
||||
chown -R nginx_user:nginx_user /var/run/nginx.pid
|
||||
|
||||
# Switch to non-root user
|
||||
USER nginx_user
|
||||
|
||||
# Expose port
|
||||
EXPOSE 80
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:80/health || exit 1
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
69
frontend/README.md
Normal file
69
frontend/README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
23
frontend/eslint.config.js
Normal file
23
frontend/eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
13
frontend/index.html
Normal file
13
frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
3765
frontend/package-lock.json
generated
Normal file
3765
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
frontend/package.json
Normal file
32
frontend/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"axios": "^1.12.2",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"react-router-dom": "^7.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.35.0",
|
||||
"@types/react": "^19.1.13",
|
||||
"@types/react-dom": "^19.1.9",
|
||||
"@vitejs/plugin-react": "^5.0.2",
|
||||
"eslint": "^9.35.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.4.0",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.43.0",
|
||||
"vite": "^7.1.6"
|
||||
}
|
||||
}
|
||||
1
frontend/public/vite.svg
Normal file
1
frontend/public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
76
frontend/src/App.css
Normal file
76
frontend/src/App.css
Normal file
@@ -0,0 +1,76 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.App {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
/* Global button styles */
|
||||
button {
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Global input styles */
|
||||
input, select, textarea {
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Global link styles */
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Utility classes */
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mb-1 { margin-bottom: 0.5rem; }
|
||||
.mb-2 { margin-bottom: 1rem; }
|
||||
.mb-3 { margin-bottom: 1.5rem; }
|
||||
.mb-4 { margin-bottom: 2rem; }
|
||||
|
||||
.mt-1 { margin-top: 0.5rem; }
|
||||
.mt-2 { margin-top: 1rem; }
|
||||
.mt-3 { margin-top: 1.5rem; }
|
||||
.mt-4 { margin-top: 2rem; }
|
||||
|
||||
.p-1 { padding: 0.5rem; }
|
||||
.p-2 { padding: 1rem; }
|
||||
.p-3 { padding: 1.5rem; }
|
||||
.p-4 { padding: 2rem; }
|
||||
|
||||
/* Responsive utilities */
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
}
|
||||
29
frontend/src/App.tsx
Normal file
29
frontend/src/App.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||
import Header from './components/Header';
|
||||
import RecipeList from './components/RecipeList';
|
||||
import RecipeDetail from './components/RecipeDetail';
|
||||
import RecipeEdit from './components/RecipeEdit';
|
||||
import RecipeCreate from './components/RecipeCreate';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<div className="App">
|
||||
<Header />
|
||||
<main className="main-content">
|
||||
<Routes>
|
||||
<Route path="/" element={<RecipeList />} />
|
||||
<Route path="/recipes" element={<RecipeList />} />
|
||||
<Route path="/recipes/new" element={<RecipeCreate />} />
|
||||
<Route path="/recipes/:id" element={<RecipeDetail />} />
|
||||
<Route path="/recipes/:id/edit" element={<RecipeEdit />} />
|
||||
{/* More routes will be added here */}
|
||||
</Routes>
|
||||
</main>
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
296
frontend/src/components/FileUpload.css
Normal file
296
frontend/src/components/FileUpload.css
Normal file
@@ -0,0 +1,296 @@
|
||||
/* FileUpload Component Styles */
|
||||
.file-upload {
|
||||
width: 100%;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
/* Drop Zone */
|
||||
.drop-zone {
|
||||
border: 2px dashed #007bff;
|
||||
border-radius: 12px;
|
||||
padding: 40px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
background: #f8f9fa;
|
||||
position: relative;
|
||||
min-height: 150px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.drop-zone:hover {
|
||||
border-color: #0056b3;
|
||||
background: #e3f2fd;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.drop-zone.drag-over {
|
||||
border-color: #28a745;
|
||||
background: #d4edda;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.drop-zone.disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
background: #e9ecef;
|
||||
border-color: #ced4da;
|
||||
}
|
||||
|
||||
.drop-zone.disabled:hover {
|
||||
transform: none;
|
||||
border-color: #ced4da;
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.drop-zone-content {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 3em;
|
||||
margin-bottom: 15px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Error Messages */
|
||||
.upload-errors {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
border-radius: 6px;
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 8px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
/* File Previews */
|
||||
.file-previews {
|
||||
margin-top: 20px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.preview-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.preview-header h4 {
|
||||
margin: 0;
|
||||
color: #333;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.clear-all-btn {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9em;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.clear-all-btn:hover:not(:disabled) {
|
||||
background: #c82333;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.clear-all-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* Preview Grid */
|
||||
.preview-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.file-preview {
|
||||
background: white;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.file-preview:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.preview-image {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
background: #f8f9fa;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.preview-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.preview-image:hover img {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.remove-file-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
background: rgba(220, 53, 69, 0.9);
|
||||
color: white;
|
||||
border: none;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.3s ease;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.file-preview:hover .remove-file-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.remove-file-btn:hover:not(:disabled) {
|
||||
background: rgba(200, 35, 51, 0.9);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.remove-file-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.file-info {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 4px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
color: #666;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
/* Progress Bar (for future use) */
|
||||
.upload-progress {
|
||||
margin-top: 15px;
|
||||
background: #e9ecef;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.upload-progress-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #007bff, #0056b3);
|
||||
transition: width 0.3s ease;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 768px) {
|
||||
.drop-zone {
|
||||
padding: 30px 15px;
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.preview-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.preview-image {
|
||||
height: 120px;
|
||||
}
|
||||
|
||||
.preview-header {
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.clear-all-btn {
|
||||
align-self: center;
|
||||
width: fit-content;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.preview-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
||||
}
|
||||
|
||||
.file-info {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
}
|
||||
233
frontend/src/components/FileUpload.tsx
Normal file
233
frontend/src/components/FileUpload.tsx
Normal file
@@ -0,0 +1,233 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import type { DragEvent, ChangeEvent } from 'react';
|
||||
import './FileUpload.css';
|
||||
|
||||
interface FileUploadProps {
|
||||
onFilesSelected: (files: File[]) => void;
|
||||
accept?: string;
|
||||
multiple?: boolean;
|
||||
maxFiles?: number;
|
||||
maxFileSize?: number; // in MB
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface FileWithPreview extends File {
|
||||
preview?: string;
|
||||
}
|
||||
|
||||
const FileUpload: React.FC<FileUploadProps> = ({
|
||||
onFilesSelected,
|
||||
accept = 'image/*',
|
||||
multiple = true,
|
||||
maxFiles = 10,
|
||||
maxFileSize = 5, // 5MB default
|
||||
disabled = false,
|
||||
className = '',
|
||||
}) => {
|
||||
const [selectedFiles, setSelectedFiles] = useState<FileWithPreview[]>([]);
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
const [errors, setErrors] = useState<string[]>([]);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const validateFile = (file: File): string | null => {
|
||||
// Check file size
|
||||
if (file.size > maxFileSize * 1024 * 1024) {
|
||||
return `Datei "${file.name}" ist zu groß. Maximum: ${maxFileSize}MB`;
|
||||
}
|
||||
|
||||
// Check file type
|
||||
if (!file.type.startsWith('image/')) {
|
||||
return `Datei "${file.name}" ist kein gültiges Bild`;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const processFiles = (files: FileList | File[]) => {
|
||||
const fileArray = Array.from(files);
|
||||
const newErrors: string[] = [];
|
||||
const validFiles: FileWithPreview[] = [];
|
||||
|
||||
// Check total file count
|
||||
if (selectedFiles.length + fileArray.length > maxFiles) {
|
||||
newErrors.push(`Maximal ${maxFiles} Dateien erlaubt`);
|
||||
setErrors(newErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
fileArray.forEach((file) => {
|
||||
const error = validateFile(file);
|
||||
if (error) {
|
||||
newErrors.push(error);
|
||||
} else {
|
||||
// Create preview URL
|
||||
const fileWithPreview = file as FileWithPreview;
|
||||
fileWithPreview.preview = URL.createObjectURL(file);
|
||||
validFiles.push(fileWithPreview);
|
||||
}
|
||||
});
|
||||
|
||||
if (newErrors.length > 0) {
|
||||
setErrors(newErrors);
|
||||
} else {
|
||||
setErrors([]);
|
||||
const updatedFiles = [...selectedFiles, ...validFiles];
|
||||
setSelectedFiles(updatedFiles);
|
||||
onFilesSelected(updatedFiles);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileSelect = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
if (e.target.files && e.target.files.length > 0) {
|
||||
processFiles(e.target.files);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDrop = (e: DragEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
setDragOver(false);
|
||||
|
||||
if (disabled) return;
|
||||
|
||||
const files = e.dataTransfer.files;
|
||||
if (files.length > 0) {
|
||||
processFiles(files);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragOver = (e: DragEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
if (!disabled) {
|
||||
setDragOver(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragLeave = (e: DragEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
setDragOver(false);
|
||||
};
|
||||
|
||||
const removeFile = (index: number) => {
|
||||
const fileToRemove = selectedFiles[index];
|
||||
if (fileToRemove.preview) {
|
||||
URL.revokeObjectURL(fileToRemove.preview);
|
||||
}
|
||||
|
||||
const updatedFiles = selectedFiles.filter((_, i) => i !== index);
|
||||
setSelectedFiles(updatedFiles);
|
||||
onFilesSelected(updatedFiles);
|
||||
};
|
||||
|
||||
const clearAll = () => {
|
||||
selectedFiles.forEach(file => {
|
||||
if (file.preview) {
|
||||
URL.revokeObjectURL(file.preview);
|
||||
}
|
||||
});
|
||||
setSelectedFiles([]);
|
||||
setErrors([]);
|
||||
onFilesSelected([]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`file-upload ${className}`}>
|
||||
{/* Drop Zone */}
|
||||
<div
|
||||
className={`drop-zone ${dragOver ? 'drag-over' : ''} ${disabled ? 'disabled' : ''}`}
|
||||
onDrop={handleDrop}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onClick={() => !disabled && fileInputRef.current?.click()}
|
||||
>
|
||||
<div className="drop-zone-content">
|
||||
<div className="upload-icon">📁</div>
|
||||
<p className="upload-text">
|
||||
{selectedFiles.length > 0
|
||||
? `${selectedFiles.length} Datei${selectedFiles.length > 1 ? 'en' : ''} ausgewählt`
|
||||
: 'Bilder hier ablegen oder klicken zum Auswählen'
|
||||
}
|
||||
</p>
|
||||
<p className="upload-hint">
|
||||
Maximal {maxFiles} Dateien, je max. {maxFileSize}MB
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept={accept}
|
||||
multiple={multiple}
|
||||
onChange={handleFileSelect}
|
||||
disabled={disabled}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Error Messages */}
|
||||
{errors.length > 0 && (
|
||||
<div className="upload-errors">
|
||||
{errors.map((error, index) => (
|
||||
<div key={index} className="error-message">
|
||||
⚠️ {error}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* File Previews */}
|
||||
{selectedFiles.length > 0 && (
|
||||
<div className="file-previews">
|
||||
<div className="preview-header">
|
||||
<h4>Ausgewählte Bilder ({selectedFiles.length})</h4>
|
||||
<button
|
||||
type="button"
|
||||
onClick={clearAll}
|
||||
className="clear-all-btn"
|
||||
disabled={disabled}
|
||||
>
|
||||
Alle entfernen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="preview-grid">
|
||||
{selectedFiles.map((file, index) => (
|
||||
<div key={index} className="file-preview">
|
||||
<div className="preview-image">
|
||||
<img
|
||||
src={file.preview}
|
||||
alt={file.name}
|
||||
onLoad={() => {
|
||||
// Clean up object URL after image loads
|
||||
if (file.preview) {
|
||||
URL.revokeObjectURL(file.preview);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="remove-file-btn"
|
||||
onClick={() => removeFile(index)}
|
||||
disabled={disabled}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="file-info">
|
||||
<div className="file-name" title={file.name}>
|
||||
{file.name.length > 20 ? `${file.name.substring(0, 17)}...` : file.name}
|
||||
</div>
|
||||
<div className="file-size">
|
||||
{(file.size / 1024 / 1024).toFixed(2)} MB
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default FileUpload;
|
||||
74
frontend/src/components/Header.css
Normal file
74
frontend/src/components/Header.css
Normal file
@@ -0,0 +1,74 @@
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 1rem 0;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.brand-link {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.brand-link h1 {
|
||||
margin: 0;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 600;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.nav-menu {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 6px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.nav-menu {
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.brand-link h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
font-size: 0.9rem;
|
||||
padding: 0.4rem 0.8rem;
|
||||
}
|
||||
}
|
||||
24
frontend/src/components/Header.tsx
Normal file
24
frontend/src/components/Header.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import './Header.css';
|
||||
|
||||
const Header: React.FC = () => {
|
||||
return (
|
||||
<header className="header">
|
||||
<div className="container">
|
||||
<div className="nav-brand">
|
||||
<Link to="/" className="brand-link">
|
||||
<h1>🍳 Rezepte</h1>
|
||||
</Link>
|
||||
</div>
|
||||
<nav className="nav-menu">
|
||||
<Link to="/" className="nav-link">Alle Rezepte</Link>
|
||||
<Link to="/recipes/new" className="nav-link">Neues Rezept</Link>
|
||||
<Link to="/ingredients" className="nav-link">Zutaten</Link>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
300
frontend/src/components/RecipeCreate.tsx
Normal file
300
frontend/src/components/RecipeCreate.tsx
Normal file
@@ -0,0 +1,300 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import { recipeApi, imageApi } from '../services/api';
|
||||
import FileUpload from './FileUpload';
|
||||
import './RecipeEdit.css'; // Reuse the same styles
|
||||
|
||||
const RecipeCreate: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [uploadProgress, setUploadProgress] = useState(0);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||
|
||||
// Form state
|
||||
const [formData, setFormData] = useState({
|
||||
title: '',
|
||||
description: '',
|
||||
category: '',
|
||||
servings: 4,
|
||||
ingredients: '',
|
||||
preparation: '',
|
||||
instructions: '',
|
||||
comment: '',
|
||||
recipeNumber: ''
|
||||
});
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: name === 'servings' ? parseInt(value) || 1 : value
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
// Validation
|
||||
if (!formData.title.trim()) {
|
||||
throw new Error('Titel ist erforderlich');
|
||||
}
|
||||
|
||||
// First create the recipe
|
||||
const response = await recipeApi.createRecipe(formData);
|
||||
|
||||
if (response.success) {
|
||||
const recipeId = response.data.id;
|
||||
|
||||
// Upload images if any were selected
|
||||
if (selectedFiles.length > 0) {
|
||||
try {
|
||||
await imageApi.uploadImages(recipeId, selectedFiles, setUploadProgress);
|
||||
} catch (uploadError) {
|
||||
console.warn('Image upload failed:', uploadError);
|
||||
// Don't fail the entire process if image upload fails
|
||||
}
|
||||
}
|
||||
|
||||
setSuccess(true);
|
||||
// Redirect to the new recipe detail page after a short delay
|
||||
setTimeout(() => {
|
||||
navigate(`/recipes/${recipeId}`);
|
||||
}, 1500);
|
||||
} else {
|
||||
setError('Fehler beim Erstellen des Rezepts');
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Unbekannter Fehler');
|
||||
console.error('Error creating recipe:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFilesSelected = (files: File[]) => {
|
||||
setSelectedFiles(files);
|
||||
};
|
||||
|
||||
if (success) {
|
||||
return (
|
||||
<div className="recipe-edit">
|
||||
<div className="success-message">
|
||||
<h2>✅ Rezept erfolgreich erstellt!</h2>
|
||||
<p>Sie werden zur Rezept-Detailseite weitergeleitet...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipe-edit">
|
||||
{/* Header */}
|
||||
<div className="recipe-header">
|
||||
<div className="breadcrumb">
|
||||
<Link to="/" className="breadcrumb-link">Alle Rezepte</Link>
|
||||
<span className="breadcrumb-separator">›</span>
|
||||
<span className="breadcrumb-current">Neues Rezept</span>
|
||||
</div>
|
||||
|
||||
<div className="recipe-actions">
|
||||
<button onClick={() => navigate(-1)} className="back-button">
|
||||
← Zurück
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Form */}
|
||||
<div className="recipe-form-container">
|
||||
<form onSubmit={handleSubmit} className="recipe-form">
|
||||
<h1>Neues Rezept erstellen</h1>
|
||||
|
||||
{error && (
|
||||
<div className="error-message">
|
||||
<span className="error-icon">⚠️</span>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="form-row">
|
||||
{/* Left Column */}
|
||||
<div className="form-column">
|
||||
<div className="form-group">
|
||||
<label htmlFor="title">Titel *</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
name="title"
|
||||
value={formData.title}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Name des Rezepts..."
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="recipeNumber">Rezeptnummer</label>
|
||||
<input
|
||||
type="text"
|
||||
id="recipeNumber"
|
||||
name="recipeNumber"
|
||||
value={formData.recipeNumber}
|
||||
onChange={handleInputChange}
|
||||
placeholder="z.B. R031"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="category">Kategorie</label>
|
||||
<select
|
||||
id="category"
|
||||
name="category"
|
||||
value={formData.category}
|
||||
onChange={handleInputChange}
|
||||
>
|
||||
<option value="">Kategorie wählen...</option>
|
||||
<option value="Vorspeise">Vorspeise</option>
|
||||
<option value="Hauptgericht">Hauptgericht</option>
|
||||
<option value="Nachspeise">Nachspeise</option>
|
||||
<option value="Beilage">Beilage</option>
|
||||
<option value="Suppe">Suppe</option>
|
||||
<option value="Salat">Salat</option>
|
||||
<option value="Fleisch">Fleisch</option>
|
||||
<option value="Fisch">Fisch</option>
|
||||
<option value="Vegetarisch">Vegetarisch</option>
|
||||
<option value="Vegan">Vegan</option>
|
||||
<option value="Dessert">Dessert</option>
|
||||
<option value="Getränk">Getränk</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="servings">Portionen</label>
|
||||
<input
|
||||
type="number"
|
||||
id="servings"
|
||||
name="servings"
|
||||
value={formData.servings}
|
||||
onChange={handleInputChange}
|
||||
min="1"
|
||||
max="50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="description">Beschreibung</label>
|
||||
<textarea
|
||||
id="description"
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleInputChange}
|
||||
rows={4}
|
||||
placeholder="Kurze Beschreibung des Rezepts..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="ingredients">Zutaten</label>
|
||||
<textarea
|
||||
id="ingredients"
|
||||
name="ingredients"
|
||||
value={formData.ingredients}
|
||||
onChange={handleInputChange}
|
||||
rows={8}
|
||||
placeholder="Eine Zutat pro Zeile... z.B.: 500g Mehl 2 Eier 250ml Milch"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column - now empty or for other content */}
|
||||
<div className="form-column">
|
||||
{/* Right column is now available for other fields if needed */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Full Width Sections */}
|
||||
<div className="form-group">
|
||||
<label htmlFor="preparation">Vorbereitung</label>
|
||||
<textarea
|
||||
id="preparation"
|
||||
name="preparation"
|
||||
value={formData.preparation}
|
||||
onChange={handleInputChange}
|
||||
rows={4}
|
||||
placeholder="Vorbereitungsschritte..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="instructions">Zubereitung</label>
|
||||
<textarea
|
||||
id="instructions"
|
||||
name="instructions"
|
||||
value={formData.instructions}
|
||||
onChange={handleInputChange}
|
||||
rows={8}
|
||||
placeholder="Detaillierte Zubereitungsschritte... Ein Schritt pro Zeile für optimale Darstellung mit Bildern."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="comment">Tipps & Kommentare</label>
|
||||
<textarea
|
||||
id="comment"
|
||||
name="comment"
|
||||
value={formData.comment}
|
||||
onChange={handleInputChange}
|
||||
rows={3}
|
||||
placeholder="Zusätzliche Tipps oder Anmerkungen..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Image Upload Section */}
|
||||
<div className="form-group">
|
||||
<label>Bilder hochladen</label>
|
||||
<p className="form-hint">
|
||||
Laden Sie Bilder für Ihr Rezept hoch. Das erste Bild wird als Hauptbild verwendet,
|
||||
weitere Bilder werden den Zubereitungsschritten zugeordnet.
|
||||
</p>
|
||||
<FileUpload
|
||||
onFilesSelected={handleFilesSelected}
|
||||
maxFiles={10}
|
||||
maxFileSize={5}
|
||||
disabled={loading}
|
||||
/>
|
||||
{uploadProgress > 0 && uploadProgress < 100 && (
|
||||
<div className="upload-progress">
|
||||
<div className="upload-progress-bar" style={{ width: `${uploadProgress}%` }}></div>
|
||||
<span className="upload-progress-text">{uploadProgress}% hochgeladen</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Form Actions */}
|
||||
<div className="form-actions">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate('/')}
|
||||
className="cancel-button"
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="save-button"
|
||||
>
|
||||
{loading ? 'Wird erstellt...' : 'Rezept erstellen'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeCreate;
|
||||
711
frontend/src/components/RecipeDetail.css
Normal file
711
frontend/src/components/RecipeDetail.css
Normal file
@@ -0,0 +1,711 @@
|
||||
/* Recipe Detail Layout */
|
||||
.recipe-detail {
|
||||
max-width: 1400px; /* Increased from 1200px */
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
/* Main Content */
|
||||
.recipe-content {
|
||||
max-width: 1200px; /* Increased from 900px */
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Recipe Info Section */
|
||||
.recipe-info {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
/* Two Column Layout for Desktop */
|
||||
.recipe-columns {
|
||||
display: flex;
|
||||
gap: 40px; /* Increased from 30px */
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.recipe-sidebar {
|
||||
flex: 0 0 400px; /* Increased from 350px */
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
padding: 25px; /* Increased from 20px */
|
||||
}
|
||||
|
||||
.recipe-main-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.recipe-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.breadcrumb-link {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.breadcrumb-link:hover {
|
||||
color: #0056b3;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.breadcrumb-separator {
|
||||
color: #999;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.breadcrumb-current {
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.edit-button, .back-button {
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.edit-button {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.edit-button:hover {
|
||||
background: #218838;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.back-button {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background: #545b62;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Main Content */
|
||||
.recipe-content {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
display: block; /* Ensure block layout */
|
||||
}
|
||||
|
||||
/* Recipe Info Section */
|
||||
.recipe-info {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
padding: 30px;
|
||||
display: block; /* Force block layout instead of flex */
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Force single column layout for all children */
|
||||
.recipe-info > * {
|
||||
width: 100%;
|
||||
display: block; /* Force all children to be block elements */
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Ensure no grid or multi-column layouts */
|
||||
.recipe-info .recipe-description,
|
||||
.recipe-info .recipe-meta,
|
||||
.recipe-info .recipe-section {
|
||||
width: 100% !important;
|
||||
display: block !important;
|
||||
float: none !important;
|
||||
position: relative !important;
|
||||
}
|
||||
|
||||
.recipe-title-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.recipe-title {
|
||||
margin: 0;
|
||||
font-size: 2.2em;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.recipe-number {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
padding: 4px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Main Recipe Image */
|
||||
.main-recipe-image {
|
||||
margin: 25px 0;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
|
||||
background: #f8f9fa;
|
||||
max-height: 400px;
|
||||
}
|
||||
|
||||
.main-recipe-image img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
max-height: 400px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.main-recipe-image:hover img {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.recipe-description {
|
||||
margin-bottom: 25px;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border-left: 4px solid #007bff;
|
||||
}
|
||||
|
||||
.recipe-description p {
|
||||
margin: 0;
|
||||
font-size: 1.1em;
|
||||
line-height: 1.6;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
/* Recipe Links */
|
||||
.recipe-link {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted #007bff;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.recipe-link:hover {
|
||||
color: #0056b3;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid #0056b3;
|
||||
background-color: rgba(0, 123, 255, 0.1);
|
||||
padding: 1px 2px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.recipe-meta {
|
||||
display: block !important; /* Force block layout instead of flex */
|
||||
gap: 0 !important;
|
||||
margin-bottom: 30px !important;
|
||||
padding: 20px !important;
|
||||
background: #f8f9fa !important;
|
||||
border-radius: 8px !important;
|
||||
width: 100% !important;
|
||||
grid-template-columns: none !important;
|
||||
flex-direction: column !important;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
display: block !important; /* Force block layout */
|
||||
margin-bottom: 15px !important;
|
||||
width: 100% !important;
|
||||
float: none !important;
|
||||
flex: none !important;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* Recipe Sections */
|
||||
.recipe-section {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.recipe-section h3 {
|
||||
margin: 0 0 15px 0;
|
||||
font-size: 1.4em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 2px solid #007bff;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* Ingredients */
|
||||
.ingredients-content {
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.ingredient-item {
|
||||
padding: 8px 0;
|
||||
position: relative;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.ingredient-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.ingredient-item::before {
|
||||
content: "•";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: #007bff;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
/* Preparation */
|
||||
.preparation-content {
|
||||
background: #fff3cd;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
border-left: 4px solid #ffc107;
|
||||
}
|
||||
|
||||
.preparation-step {
|
||||
margin: 0 0 5px 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.preparation-step:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Instructions */
|
||||
.instructions-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.instruction-step-with-image {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border-left: 4px solid #28a745;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.step-image {
|
||||
flex-shrink: 0;
|
||||
width: 200px;
|
||||
height: 150px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: #e9ecef;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.step-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.step-image img:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.instruction-step {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
flex: 1;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.step-number {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.step-text {
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Comment */
|
||||
.comment-content {
|
||||
background: #d1ecf1;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
border-left: 4px solid #17a2b8;
|
||||
}
|
||||
|
||||
.recipe-comment {
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* Image Management */
|
||||
.image-management {
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px;
|
||||
padding: 25px;
|
||||
margin: 30px 0;
|
||||
border: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.image-management h3 {
|
||||
margin: 0 0 20px 0;
|
||||
color: #333;
|
||||
font-size: 1.3em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.image-management h3::before {
|
||||
content: "📸";
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.upload-section {
|
||||
margin-bottom: 30px;
|
||||
padding-bottom: 25px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.upload-section h4,
|
||||
.existing-images h4 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #555;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.existing-images {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.images-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.image-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.image-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.image-preview:hover img {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.delete-image-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
background: rgba(220, 53, 69, 0.9);
|
||||
color: white;
|
||||
border: none;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s ease;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.image-item:hover .delete-image-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.delete-image-btn:hover {
|
||||
background: rgba(200, 35, 51, 0.9);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.image-info {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-name {
|
||||
display: block;
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-bottom: 5px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.main-image-badge {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.8em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.upload-progress {
|
||||
margin-top: 15px;
|
||||
background: #e9ecef;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.upload-progress-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #007bff, #0056b3);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.upload-progress-text {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-top: 8px;
|
||||
text-align: center;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Error States */
|
||||
.error, .not-found {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.error h3, .not-found h3 {
|
||||
color: #dc3545;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.error-actions {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.retry-button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.retry-button:hover {
|
||||
background: #0056b3;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Loading */
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
font-size: 1.2em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
/* Large screens - extra wide layout */
|
||||
@media (min-width: 1400px) {
|
||||
.recipe-detail {
|
||||
max-width: 1600px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.recipe-content {
|
||||
max-width: 1400px;
|
||||
}
|
||||
|
||||
.recipe-columns {
|
||||
gap: 50px;
|
||||
}
|
||||
|
||||
.recipe-sidebar {
|
||||
flex: 0 0 450px;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.recipe-info {
|
||||
padding: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.recipe-detail {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.recipe-header {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.recipe-content {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.recipe-info {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.recipe-title {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.recipe-meta {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
/* Stack columns on mobile */
|
||||
.recipe-columns {
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.recipe-sidebar {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.instruction-step-with-image {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.step-image {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.instruction-step {
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.step-number {
|
||||
align-self: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.recipe-actions {
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.edit-button, .back-button {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
}/* Force reload */
|
||||
392
frontend/src/components/RecipeDetail.tsx
Normal file
392
frontend/src/components/RecipeDetail.tsx
Normal file
@@ -0,0 +1,392 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, Link, useNavigate } from 'react-router-dom';
|
||||
import type { Recipe } from '../services/api';
|
||||
import { recipeApi, imageApi } from '../services/api';
|
||||
import FileUpload from './FileUpload';
|
||||
import './RecipeDetail.css';
|
||||
|
||||
// Helper function to convert URLs in text to clickable links
|
||||
const linkifyText = (text: string): React.ReactNode => {
|
||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
const parts = text.split(urlRegex);
|
||||
|
||||
return parts.map((part, index) => {
|
||||
if (urlRegex.test(part)) {
|
||||
return (
|
||||
<a
|
||||
key={index}
|
||||
href={part}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="recipe-link"
|
||||
>
|
||||
{part}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
return part;
|
||||
});
|
||||
};
|
||||
|
||||
const RecipeDetail: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [recipe, setRecipe] = useState<Recipe | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [editingImages, setEditingImages] = useState(false);
|
||||
const [uploadProgress, setUploadProgress] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const loadRecipe = async () => {
|
||||
if (!id) {
|
||||
setError('Keine Rezept-ID angegeben');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setError(null);
|
||||
const response = await recipeApi.getRecipe(parseInt(id));
|
||||
|
||||
if (response.success) {
|
||||
setRecipe(response.data);
|
||||
} else {
|
||||
setError('Rezept konnte nicht geladen werden');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Verbindungsfehler - Ist der Server gestartet?');
|
||||
console.error('Error loading recipe:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadRecipe();
|
||||
}, [id]);
|
||||
|
||||
const handleImageUpload = async (files: File[]) => {
|
||||
if (!recipe || !id) return;
|
||||
|
||||
try {
|
||||
setUploadProgress(0);
|
||||
await imageApi.uploadImages(parseInt(id), files, setUploadProgress);
|
||||
|
||||
// Reload recipe to get updated images
|
||||
const response = await recipeApi.getRecipe(parseInt(id));
|
||||
if (response.success) {
|
||||
setRecipe(response.data);
|
||||
}
|
||||
|
||||
setUploadProgress(0);
|
||||
} catch (error) {
|
||||
console.error('Error uploading images:', error);
|
||||
setError('Fehler beim Hochladen der Bilder');
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageDelete = async (imageId: number) => {
|
||||
if (!recipe || !id) return;
|
||||
|
||||
try {
|
||||
await imageApi.deleteImage(imageId);
|
||||
|
||||
// Reload recipe to get updated images
|
||||
const response = await recipeApi.getRecipe(parseInt(id));
|
||||
if (response.success) {
|
||||
setRecipe(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting image:', error);
|
||||
setError('Fehler beim Löschen des Bildes');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="recipe-detail">
|
||||
<div className="loading">Lade Rezept...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="recipe-detail">
|
||||
<div className="error">
|
||||
<h3>Fehler</h3>
|
||||
<p>{error}</p>
|
||||
<div className="error-actions">
|
||||
<button onClick={() => window.location.reload()} className="retry-button">
|
||||
Erneut versuchen
|
||||
</button>
|
||||
<Link to="/" className="back-button">
|
||||
Zurück zur Liste
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!recipe) {
|
||||
return (
|
||||
<div className="recipe-detail">
|
||||
<div className="not-found">
|
||||
<h3>Rezept nicht gefunden</h3>
|
||||
<p>Das angeforderte Rezept existiert nicht.</p>
|
||||
<Link to="/" className="back-button">
|
||||
Zurück zur Liste
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipe-detail">
|
||||
{/* Header */}
|
||||
<div className="recipe-header">
|
||||
<div className="breadcrumb">
|
||||
<Link to="/" className="breadcrumb-link">Alle Rezepte</Link>
|
||||
<span className="breadcrumb-separator">›</span>
|
||||
<span className="breadcrumb-current">{recipe.title}</span>
|
||||
</div>
|
||||
|
||||
<div className="recipe-actions">
|
||||
<button
|
||||
onClick={() => setEditingImages(!editingImages)}
|
||||
className="edit-button"
|
||||
style={{ marginRight: '8px' }}
|
||||
>
|
||||
📸 {editingImages ? 'Fertig' : 'Bilder verwalten'}
|
||||
</button>
|
||||
<Link to={`/recipes/${recipe.id}/edit`} className="edit-button">
|
||||
✏️ Bearbeiten
|
||||
</Link>
|
||||
<button onClick={() => navigate(-1)} className="back-button">
|
||||
← Zurück
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<div className="recipe-content">
|
||||
{/* Recipe Info - Full Width */}
|
||||
<div className="recipe-info">
|
||||
<div className="recipe-title-section">
|
||||
<h1 className="recipe-title">{recipe.title}</h1>
|
||||
{recipe.recipeNumber && (
|
||||
<span className="recipe-number">#{recipe.recipeNumber}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Hauptbild (xxx_0.jpg) */}
|
||||
{recipe.images && recipe.images.length > 0 && (
|
||||
<div className="main-recipe-image">
|
||||
{(() => {
|
||||
// Find the main image (xxx_0.jpg)
|
||||
const mainImage = recipe.images.find(image => {
|
||||
const fileName = image.filePath.split('/').pop() || '';
|
||||
return fileName.includes('_0.jpg');
|
||||
});
|
||||
|
||||
if (mainImage) {
|
||||
return (
|
||||
<img
|
||||
src={imageApi.getImageUrl(mainImage.filePath)}
|
||||
alt={`${recipe.title} - Hauptbild`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="recipe-meta">
|
||||
{recipe.category && (
|
||||
<div className="meta-item">
|
||||
<span className="meta-label">Kategorie:</span>
|
||||
<span className="meta-value">{recipe.category}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="meta-item">
|
||||
<span className="meta-label">Portionen:</span>
|
||||
<span className="meta-value">👥 {recipe.servings}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Management Section */}
|
||||
{editingImages && (
|
||||
<div className="image-management">
|
||||
<h3>Bilder verwalten</h3>
|
||||
|
||||
{/* Upload new images */}
|
||||
<div className="upload-section">
|
||||
<h4>Neue Bilder hochladen</h4>
|
||||
<FileUpload
|
||||
onFilesSelected={handleImageUpload}
|
||||
maxFiles={5}
|
||||
maxFileSize={5}
|
||||
disabled={uploadProgress > 0}
|
||||
/>
|
||||
{uploadProgress > 0 && uploadProgress < 100 && (
|
||||
<div className="upload-progress">
|
||||
<div className="upload-progress-bar" style={{ width: `${uploadProgress}%` }}></div>
|
||||
<span className="upload-progress-text">{uploadProgress}% hochgeladen</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Existing images */}
|
||||
{recipe.images && recipe.images.length > 0 && (
|
||||
<div className="existing-images">
|
||||
<h4>Vorhandene Bilder ({recipe.images.length})</h4>
|
||||
<div className="images-grid">
|
||||
{recipe.images.map((image, index) => (
|
||||
<div key={image.id} className="image-item">
|
||||
<div className="image-preview">
|
||||
<img
|
||||
src={imageApi.getImageUrl(image.filePath)}
|
||||
alt={`Bild ${index + 1}`}
|
||||
/>
|
||||
<button
|
||||
className="delete-image-btn"
|
||||
onClick={() => handleImageDelete(image.id)}
|
||||
title="Bild löschen"
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
</div>
|
||||
<div className="image-info">
|
||||
<span className="image-name">
|
||||
{image.filePath.split('/').pop()}
|
||||
</span>
|
||||
{image.filePath.includes('_0.jpg') && (
|
||||
<span className="main-image-badge">Hauptbild</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Two Column Layout for Description/Ingredients and Preparation */}
|
||||
<div className="recipe-columns">
|
||||
{/* Left Column - Description and Ingredients */}
|
||||
<div className="recipe-sidebar">
|
||||
{recipe.description && (
|
||||
<div className="recipe-description">
|
||||
<h3>Beschreibung</h3>
|
||||
<p>{linkifyText(recipe.description)}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Zutaten */}
|
||||
{recipe.ingredients && (
|
||||
<div className="recipe-section">
|
||||
<h3>Zutaten</h3>
|
||||
<div className="ingredients-content">
|
||||
{recipe.ingredients.split('\n').map((ingredient, index) => (
|
||||
<div key={index} className="ingredient-item">
|
||||
{ingredient.trim()}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Right Column - Preparation and Instructions */}
|
||||
<div className="recipe-main-content">
|
||||
|
||||
{/* Vorbereitung */}
|
||||
{recipe.preparation && (
|
||||
<div className="recipe-section">
|
||||
<h3>Vorbereitung</h3>
|
||||
<div className="preparation-content">
|
||||
{recipe.preparation.split('\n').map((step, index) => (
|
||||
<p key={index} className="preparation-step">
|
||||
{step.trim()}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Anweisungen */}
|
||||
{recipe.instructions && (
|
||||
<div className="recipe-section">
|
||||
<h3>Zubereitung</h3>
|
||||
<div className="instructions-content">
|
||||
{(() => {
|
||||
// Get all preparation images (exclude main image _0.jpg)
|
||||
const preparationImages = recipe.images
|
||||
?.filter(image => {
|
||||
const fileName = image.filePath.split('/').pop() || '';
|
||||
// Match pattern like R005_1.jpg, R005_2.jpg, etc. but not R005_0.jpg
|
||||
return fileName.match(/_[1-9]\d*\.jpg$/);
|
||||
})
|
||||
.sort((a, b) => {
|
||||
// Sort by the number in the filename
|
||||
const getNumber = (path: string) => {
|
||||
const match = path.match(/_(\d+)\.jpg$/);
|
||||
return match ? parseInt(match[1]) : 0;
|
||||
};
|
||||
return getNumber(a.filePath) - getNumber(b.filePath);
|
||||
}) || [];
|
||||
|
||||
return recipe.instructions.split('\n').map((instruction, index) => {
|
||||
// Get the corresponding image for this step
|
||||
const stepImage = preparationImages[index];
|
||||
|
||||
return (
|
||||
<div key={index} className="instruction-step-with-image">
|
||||
{stepImage && (
|
||||
<div className="step-image">
|
||||
<img
|
||||
src={imageApi.getImageUrl(stepImage.filePath)}
|
||||
alt={`${recipe.title} - Schritt ${index + 1}`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="instruction-step">
|
||||
<span className="step-number">{index + 1}</span>
|
||||
<p className="step-text">{instruction.trim()}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Kommentar */}
|
||||
{recipe.comment && (
|
||||
<div className="recipe-section">
|
||||
<h3>Tipp</h3>
|
||||
<div className="comment-content">
|
||||
<p className="recipe-comment">{recipe.comment}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeDetail;
|
||||
64
frontend/src/components/RecipeDetailFix.css
Normal file
64
frontend/src/components/RecipeDetailFix.css
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ULTIMATE OVERRIDE - This will force single column no matter what */
|
||||
html body div#root div.App main.main-content div.recipe-detail,
|
||||
html body div#root div.App main.main-content div.recipe-detail *,
|
||||
.recipe-detail,
|
||||
.recipe-detail * {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
max-width: 100% !important;
|
||||
float: none !important;
|
||||
position: relative !important;
|
||||
left: auto !important;
|
||||
right: auto !important;
|
||||
top: auto !important;
|
||||
bottom: auto !important;
|
||||
grid-template-columns: none !important;
|
||||
grid-template-areas: none !important;
|
||||
grid-column: auto !important;
|
||||
grid-row: auto !important;
|
||||
columns: none !important;
|
||||
column-count: 1 !important;
|
||||
column-width: auto !important;
|
||||
flex-direction: column !important;
|
||||
flex-wrap: nowrap !important;
|
||||
flex-basis: auto !important;
|
||||
flex-grow: 0 !important;
|
||||
flex-shrink: 0 !important;
|
||||
align-items: stretch !important;
|
||||
justify-content: flex-start !important;
|
||||
margin-left: 0 !important;
|
||||
margin-right: 0 !important;
|
||||
box-sizing: border-box !important;
|
||||
}
|
||||
|
||||
/* Even more specific - target the exact structure */
|
||||
.recipe-detail .recipe-content .recipe-info {
|
||||
background: white !important;
|
||||
border-radius: 12px !important;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
|
||||
padding: 30px !important;
|
||||
border: 5px solid lime !important; /* DEBUGGING: Bright green border */
|
||||
}
|
||||
|
||||
.recipe-detail .recipe-content .recipe-info > * {
|
||||
width: 100% !important;
|
||||
display: block !important;
|
||||
margin-bottom: 20px !important;
|
||||
border: 2px solid orange !important; /* DEBUGGING: Orange border for each section */
|
||||
}
|
||||
|
||||
/* Force specific elements to be single column */
|
||||
.recipe-detail .recipe-meta {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.recipe-detail .recipe-description {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.recipe-detail .recipe-section {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
434
frontend/src/components/RecipeEdit.css
Normal file
434
frontend/src/components/RecipeEdit.css
Normal file
@@ -0,0 +1,434 @@
|
||||
/* Recipe Edit Styles */
|
||||
.recipe-edit {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.recipe-edit-header {
|
||||
margin-bottom: 30px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.recipe-edit-header h1 {
|
||||
margin: 15px 0 0 0;
|
||||
font-size: 2.2em;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.breadcrumb-link {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.breadcrumb-link:hover {
|
||||
color: #0056b3;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.breadcrumb-separator {
|
||||
color: #999;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.breadcrumb-current {
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Messages */
|
||||
.message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 15px 20px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.message-icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
/* Form Layout */
|
||||
.recipe-form {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 40px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.form-section h3 {
|
||||
margin: 0 0 25px 0;
|
||||
font-size: 1.4em;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 2px solid #007bff;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* Form Groups */
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 120px;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group label.required::after {
|
||||
content: " *";
|
||||
color: #dc3545;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Form Inputs */
|
||||
.form-group input,
|
||||
.form-group textarea,
|
||||
.form-group select {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
transition: all 0.3s ease;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus,
|
||||
.form-group select:focus {
|
||||
outline: none;
|
||||
border-color: #007bff;
|
||||
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
|
||||
}
|
||||
|
||||
.form-group input:invalid,
|
||||
.form-group textarea:invalid {
|
||||
border-color: #dc3545;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.form-group select {
|
||||
cursor: pointer;
|
||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
|
||||
background-position: right 12px center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 16px;
|
||||
padding-right: 40px;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 5px;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Form Actions */
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 15px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.cancel-button,
|
||||
.save-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 120px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cancel-button {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.cancel-button:hover:not(:disabled) {
|
||||
background: #545b62;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.save-button {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.save-button:hover:not(:disabled) {
|
||||
background: #218838;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.cancel-button:disabled,
|
||||
.save-button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* Loading Spinner */
|
||||
.loading-spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: white;
|
||||
animation: spin 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Error States */
|
||||
.error {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.error h3 {
|
||||
color: #dc3545;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.error-actions {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.retry-button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.retry-button:hover {
|
||||
background: #0056b3;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.back-button {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background: #545b62;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Loading */
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
font-size: 1.2em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Character Counter */
|
||||
.form-group[data-maxlength]::after {
|
||||
content: attr(data-current) "/" attr(data-maxlength);
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
float: right;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 768px) {
|
||||
.recipe-edit {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.recipe-form {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
.cancel-button,
|
||||
.save-button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.recipe-edit-header h1 {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.breadcrumb {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.form-section h3 {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 12px 15px;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea,
|
||||
.form-group select {
|
||||
padding: 10px 14px;
|
||||
font-size: 16px; /* Prevents zoom on iOS */
|
||||
}
|
||||
}
|
||||
|
||||
/* Upload Progress in Forms */
|
||||
.form-group .upload-progress {
|
||||
margin-top: 10px;
|
||||
background: #e9ecef;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
height: 6px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.form-group .upload-progress-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #007bff, #0056b3);
|
||||
transition: width 0.3s ease;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.upload-progress-text {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 10px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* High Contrast Mode */
|
||||
@media (prefers-contrast: high) {
|
||||
.form-group input,
|
||||
.form-group textarea,
|
||||
.form-group select {
|
||||
border-width: 3px;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus,
|
||||
.form-group select:focus {
|
||||
border-color: #000;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reduced Motion */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.form-group input,
|
||||
.form-group textarea,
|
||||
.form-group select,
|
||||
.cancel-button,
|
||||
.save-button,
|
||||
.breadcrumb-link {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
379
frontend/src/components/RecipeEdit.tsx
Normal file
379
frontend/src/components/RecipeEdit.tsx
Normal file
@@ -0,0 +1,379 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom';
|
||||
import type { Recipe } from '../services/api';
|
||||
import { recipeApi } from '../services/api';
|
||||
import './RecipeEdit.css';
|
||||
|
||||
interface FormData {
|
||||
title: string;
|
||||
description: string;
|
||||
category: string;
|
||||
servings: number;
|
||||
ingredients: string;
|
||||
preparation: string;
|
||||
instructions: string;
|
||||
comment: string;
|
||||
}
|
||||
|
||||
const RecipeEdit: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [recipe, setRecipe] = useState<Recipe | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
const [formData, setFormData] = useState<FormData>({
|
||||
title: '',
|
||||
description: '',
|
||||
category: '',
|
||||
servings: 1,
|
||||
ingredients: '',
|
||||
preparation: '',
|
||||
instructions: '',
|
||||
comment: '',
|
||||
});
|
||||
|
||||
// Load recipe data
|
||||
useEffect(() => {
|
||||
const loadRecipe = async () => {
|
||||
if (!id) {
|
||||
setError('Keine Rezept-ID angegeben');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setError(null);
|
||||
const response = await recipeApi.getRecipe(parseInt(id));
|
||||
|
||||
if (response.success) {
|
||||
const recipeData = response.data;
|
||||
setRecipe(recipeData);
|
||||
setFormData({
|
||||
title: recipeData.title || '',
|
||||
description: recipeData.description || '',
|
||||
category: recipeData.category || '',
|
||||
servings: recipeData.servings || 1,
|
||||
ingredients: recipeData.ingredients || '',
|
||||
preparation: recipeData.preparation || '',
|
||||
instructions: recipeData.instructions || '',
|
||||
comment: recipeData.comment || '',
|
||||
});
|
||||
} else {
|
||||
setError('Rezept konnte nicht geladen werden');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Verbindungsfehler - Ist der Server gestartet?');
|
||||
console.error('Error loading recipe:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadRecipe();
|
||||
}, [id]);
|
||||
|
||||
// Handle form field changes
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: name === 'servings' ? parseInt(value) || 1 : value
|
||||
}));
|
||||
|
||||
// Clear messages when user starts typing
|
||||
if (error) setError(null);
|
||||
if (successMessage) setSuccessMessage(null);
|
||||
};
|
||||
|
||||
// Handle form submission
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!id || !recipe) {
|
||||
setError('Rezept nicht gefunden');
|
||||
return;
|
||||
}
|
||||
|
||||
// Basic validation
|
||||
if (!formData.title.trim()) {
|
||||
setError('Titel ist erforderlich');
|
||||
return;
|
||||
}
|
||||
|
||||
if (formData.servings < 1 || formData.servings > 50) {
|
||||
setError('Portionen müssen zwischen 1 und 50 liegen');
|
||||
return;
|
||||
}
|
||||
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
setSuccessMessage(null);
|
||||
|
||||
try {
|
||||
const updateData = {
|
||||
...formData,
|
||||
title: formData.title.trim(),
|
||||
description: formData.description.trim() || undefined,
|
||||
category: formData.category.trim() || undefined,
|
||||
ingredients: formData.ingredients.trim() || undefined,
|
||||
preparation: formData.preparation.trim() || undefined,
|
||||
instructions: formData.instructions.trim() || undefined,
|
||||
comment: formData.comment.trim() || undefined,
|
||||
};
|
||||
|
||||
const response = await recipeApi.updateRecipe(parseInt(id), updateData);
|
||||
|
||||
if (response.success) {
|
||||
setSuccessMessage('Rezept erfolgreich gespeichert!');
|
||||
setRecipe(response.data);
|
||||
|
||||
// Redirect after successful save
|
||||
setTimeout(() => {
|
||||
navigate(`/recipes/${id}`);
|
||||
}, 1500);
|
||||
} else {
|
||||
setError(response.message || 'Fehler beim Speichern des Rezepts');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Verbindungsfehler beim Speichern');
|
||||
console.error('Error updating recipe:', err);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle cancel
|
||||
const handleCancel = () => {
|
||||
navigate(`/recipes/${id}`);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="recipe-edit">
|
||||
<div className="loading">Lade Rezept...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error && !recipe) {
|
||||
return (
|
||||
<div className="recipe-edit">
|
||||
<div className="error">
|
||||
<h3>Fehler</h3>
|
||||
<p>{error}</p>
|
||||
<div className="error-actions">
|
||||
<button onClick={() => window.location.reload()} className="retry-button">
|
||||
Erneut versuchen
|
||||
</button>
|
||||
<Link to="/" className="back-button">
|
||||
Zurück zur Liste
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipe-edit">
|
||||
{/* Header */}
|
||||
<div className="recipe-edit-header">
|
||||
<div className="breadcrumb">
|
||||
<Link to="/" className="breadcrumb-link">Alle Rezepte</Link>
|
||||
<span className="breadcrumb-separator">›</span>
|
||||
<Link to={`/recipes/${id}`} className="breadcrumb-link">{recipe?.title}</Link>
|
||||
<span className="breadcrumb-separator">›</span>
|
||||
<span className="breadcrumb-current">Bearbeiten</span>
|
||||
</div>
|
||||
|
||||
<h1>Rezept bearbeiten</h1>
|
||||
</div>
|
||||
|
||||
{/* Messages */}
|
||||
{error && (
|
||||
<div className="message error-message">
|
||||
<span className="message-icon">⚠️</span>
|
||||
<span className="message-text">{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{successMessage && (
|
||||
<div className="message success-message">
|
||||
<span className="message-icon">✅</span>
|
||||
<span className="message-text">{successMessage}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Form */}
|
||||
<form onSubmit={handleSubmit} className="recipe-form">
|
||||
<div className="form-grid">
|
||||
{/* Left Column - Basic Info */}
|
||||
<div className="form-section">
|
||||
<h3>Grundinformationen</h3>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="title" className="required">Titel</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
name="title"
|
||||
value={formData.title}
|
||||
onChange={handleInputChange}
|
||||
placeholder="z.B. Pasta Gamberoni"
|
||||
maxLength={200}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-row">
|
||||
<div className="form-group">
|
||||
<label htmlFor="category">Kategorie</label>
|
||||
<select
|
||||
id="category"
|
||||
name="category"
|
||||
value={formData.category}
|
||||
onChange={handleInputChange}
|
||||
>
|
||||
<option value="">Kategorie wählen</option>
|
||||
<option value="Vegan">Vegan</option>
|
||||
<option value="Vegetarisch">Vegetarisch</option>
|
||||
<option value="Fleisch">Fleisch</option>
|
||||
<option value="Fisch">Fisch</option>
|
||||
<option value="Fisch, Garnelen">Fisch, Garnelen</option>
|
||||
<option value="Dessert">Dessert</option>
|
||||
<option value="Suppe">Suppe</option>
|
||||
<option value="Salat">Salat</option>
|
||||
<option value="Beilage">Beilage</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="servings" className="required">Portionen</label>
|
||||
<input
|
||||
type="number"
|
||||
id="servings"
|
||||
name="servings"
|
||||
value={formData.servings}
|
||||
onChange={handleInputChange}
|
||||
min="1"
|
||||
max="50"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="description">Beschreibung</label>
|
||||
<textarea
|
||||
id="description"
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Kurze Beschreibung des Rezepts..."
|
||||
rows={4}
|
||||
maxLength={1000}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column - Recipe Content */}
|
||||
<div className="form-section">
|
||||
<h3>Rezeptinhalt</h3>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="ingredients">Zutaten</label>
|
||||
<textarea
|
||||
id="ingredients"
|
||||
name="ingredients"
|
||||
value={formData.ingredients}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Eine Zutat pro Zeile, z.B. 200g Pasta 400g Garnelen 2 Knoblauchzehen"
|
||||
rows={8}
|
||||
maxLength={5000}
|
||||
/>
|
||||
<div className="form-hint">
|
||||
Eine Zutat pro Zeile eingeben
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="preparation">Vorbereitung</label>
|
||||
<textarea
|
||||
id="preparation"
|
||||
name="preparation"
|
||||
value={formData.preparation}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Vorbereitungsschritte, z.B. Garnelen putzen Knoblauch schneiden"
|
||||
rows={6}
|
||||
maxLength={3000}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="instructions">Zubereitung</label>
|
||||
<textarea
|
||||
id="instructions"
|
||||
name="instructions"
|
||||
value={formData.instructions}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Detaillierte Zubereitungsschritte..."
|
||||
rows={10}
|
||||
maxLength={10000}
|
||||
/>
|
||||
<div className="form-hint">
|
||||
Jeden Schritt in einer neuen Zeile beschreiben
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="comment">Tipps & Hinweise</label>
|
||||
<textarea
|
||||
id="comment"
|
||||
name="comment"
|
||||
value={formData.comment}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Zusätzliche Tipps oder Hinweise..."
|
||||
rows={4}
|
||||
maxLength={2000}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Form Actions */}
|
||||
<div className="form-actions">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCancel}
|
||||
className="cancel-button"
|
||||
disabled={saving}
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="save-button"
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? (
|
||||
<>
|
||||
<span className="loading-spinner"></span>
|
||||
Speichert...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
💾 Speichern
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeEdit;
|
||||
362
frontend/src/components/RecipeList.css
Normal file
362
frontend/src/components/RecipeList.css
Normal file
@@ -0,0 +1,362 @@
|
||||
.recipe-list {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
|
||||
.recipe-list-header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.recipe-list-header h2 {
|
||||
color: #333;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.searching-indicator {
|
||||
font-size: 1.2rem;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 0.6; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
padding: 0.75rem;
|
||||
border: 2px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
padding: 0.75rem 1rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.search-button:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
.category-select {
|
||||
padding: 0.75rem;
|
||||
border: 2px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.category-select:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.recipes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.recipe-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
min-height: 450px; /* Stabile Mindesthöhe */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.recipe-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.recipe-image {
|
||||
height: 200px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.recipe-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.recipe-card:hover .recipe-image img {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.no-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
font-size: 3rem;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.recipe-content {
|
||||
padding: 1.5rem;
|
||||
flex: 1; /* Nimmt verfügbaren Platz ein */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.recipe-title {
|
||||
color: #333;
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
min-height: 1.6em; /* Verhindert Layout-Sprünge */
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2; /* Begrenzt auf 2 Zeilen */
|
||||
line-clamp: 2; /* Standard property für Kompatibilität */
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.recipe-description {
|
||||
color: #666;
|
||||
margin: 0 0 1rem 0;
|
||||
line-height: 1.5;
|
||||
font-size: 0.95rem;
|
||||
min-height: 3em; /* Verhindert Layout-Sprünge */
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3; /* Begrenzt auf 3 Zeilen */
|
||||
line-clamp: 3; /* Standard property für Kompatibilität */
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.recipe-meta {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.recipe-category {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 20px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.recipe-servings {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.view-button, .edit-button {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 0.75rem;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
font-size: 0.9rem;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.view-button {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.view-button:hover {
|
||||
background: #5a6fd8;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.edit-button {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
border: 2px solid #667eea;
|
||||
}
|
||||
|
||||
.edit-button:hover {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.no-recipes {
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.no-recipes h3 {
|
||||
color: #333;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.create-button {
|
||||
display: inline-block;
|
||||
margin-top: 1rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.create-button:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.pagination-button {
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.pagination-button:hover:not(:disabled) {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
.pagination-button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.pagination-info {
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.loading, .error {
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: #666;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #e74c3c;
|
||||
}
|
||||
|
||||
.error h3 {
|
||||
color: #e74c3c;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.retry-button {
|
||||
margin-top: 1rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: #e74c3c;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.retry-button:hover {
|
||||
background: #c0392b;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.recipe-list {
|
||||
padding: 1rem 0.5rem;
|
||||
}
|
||||
|
||||
.filters {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
.recipes-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.recipe-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
243
frontend/src/components/RecipeList.tsx
Normal file
243
frontend/src/components/RecipeList.tsx
Normal file
@@ -0,0 +1,243 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { Recipe } from '../services/api';
|
||||
import { recipeApi, imageApi } from '../services/api';
|
||||
import './RecipeList.css';
|
||||
|
||||
// Debounce hook
|
||||
const useDebounce = (value: string, delay: number) => {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedValue(value);
|
||||
}, delay);
|
||||
|
||||
return () => {
|
||||
clearTimeout(handler);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
};
|
||||
|
||||
const RecipeList: React.FC = () => {
|
||||
const [recipes, setRecipes] = useState<Recipe[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isSearching, setIsSearching] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [search, setSearch] = useState('');
|
||||
const [category, setCategory] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
const [pagination, setPagination] = useState({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
pages: 0,
|
||||
});
|
||||
|
||||
// Debounce search to prevent too many API calls
|
||||
const debouncedSearch = useDebounce(search, 300);
|
||||
|
||||
const loadRecipes = async () => {
|
||||
try {
|
||||
if (recipes.length > 0) {
|
||||
setIsSearching(true); // Show subtle loading for subsequent searches
|
||||
}
|
||||
setError(null); // Clear previous errors
|
||||
const response = await recipeApi.getRecipes({
|
||||
search: debouncedSearch || undefined,
|
||||
category: category || undefined,
|
||||
page,
|
||||
limit: 12,
|
||||
sortBy: 'title',
|
||||
sortOrder: 'asc',
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
setRecipes(response.data);
|
||||
setPagination(response.pagination);
|
||||
} else {
|
||||
setError('Fehler beim Laden der Rezepte');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Verbindungsfehler - Ist der Server gestartet?');
|
||||
console.error('Error loading recipes:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setIsSearching(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadRecipes();
|
||||
}, [debouncedSearch, category, page]);
|
||||
|
||||
const handleSearchSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setPage(1);
|
||||
loadRecipes();
|
||||
};
|
||||
|
||||
const handleCategoryChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
setCategory(e.target.value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="recipe-list">
|
||||
<div className="loading">Lade Rezepte...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="recipe-list">
|
||||
<div className="error">
|
||||
<h3>Fehler</h3>
|
||||
<p>{error}</p>
|
||||
<button onClick={loadRecipes} className="retry-button">
|
||||
Erneut versuchen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recipe-list">
|
||||
<div className="recipe-list-header">
|
||||
<h2>
|
||||
Alle Rezepte ({pagination.total})
|
||||
{isSearching && <span className="searching-indicator"> 🔍</span>}
|
||||
</h2>
|
||||
|
||||
<div className="filters">
|
||||
<form onSubmit={handleSearchSubmit} className="search-form">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Rezepte durchsuchen..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="search-input"
|
||||
/>
|
||||
<button type="submit" className="search-button">
|
||||
🔍
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<select
|
||||
value={category}
|
||||
onChange={handleCategoryChange}
|
||||
className="category-select"
|
||||
>
|
||||
<option value="">Alle Kategorien</option>
|
||||
<option value="Vegan">Vegan</option>
|
||||
<option value="Vegetarisch">Vegetarisch</option>
|
||||
<option value="Fleisch">Fleisch</option>
|
||||
<option value="Fisch">Fisch</option>
|
||||
<option value="Dessert">Dessert</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="recipes-grid">
|
||||
{recipes.map((recipe) => (
|
||||
<div key={recipe.id} className="recipe-card">
|
||||
<div className="recipe-image">
|
||||
{recipe.images && recipe.images.length > 0 ? (
|
||||
<img
|
||||
src={imageApi.getImageUrl(recipe.images[0].filePath)}
|
||||
alt={recipe.title}
|
||||
loading="lazy"
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
objectFit: 'cover',
|
||||
display: 'block'
|
||||
}}
|
||||
onError={(e) => {
|
||||
const imgSrc = recipe.images?.[0]?.filePath
|
||||
? imageApi.getImageUrl(recipe.images[0].filePath)
|
||||
: 'unknown';
|
||||
console.error('Failed to load image:', imgSrc);
|
||||
e.currentTarget.style.display = 'none';
|
||||
e.currentTarget.parentElement!.innerHTML = '<div class="no-image">📸</div>';
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className="no-image">📸</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="recipe-content">
|
||||
<h3 className="recipe-title">{recipe.title}</h3>
|
||||
<p className="recipe-description">
|
||||
{recipe.description ?
|
||||
recipe.description.length > 100 ?
|
||||
recipe.description.substring(0, 100) + '...' :
|
||||
recipe.description
|
||||
: 'Keine Beschreibung verfügbar'
|
||||
}
|
||||
</p>
|
||||
|
||||
<div className="recipe-meta">
|
||||
{recipe.category && (
|
||||
<span className="recipe-category">{recipe.category}</span>
|
||||
)}
|
||||
<span className="recipe-servings">👥 {recipe.servings} Portionen</span>
|
||||
</div>
|
||||
|
||||
<div className="recipe-actions">
|
||||
<Link to={`/recipes/${recipe.id}`} className="view-button">
|
||||
Ansehen
|
||||
</Link>
|
||||
<Link to={`/recipes/${recipe.id}/edit`} className="edit-button">
|
||||
Bearbeiten
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{recipes.length === 0 && (
|
||||
<div className="no-recipes">
|
||||
<h3>Keine Rezepte gefunden</h3>
|
||||
<p>Versuche es mit anderen Suchbegriffen oder erstelle ein neues Rezept.</p>
|
||||
<Link to="/recipes/new" className="create-button">
|
||||
Neues Rezept erstellen
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{pagination.pages > 1 && (
|
||||
<div className="pagination">
|
||||
<button
|
||||
onClick={() => setPage(page - 1)}
|
||||
disabled={page <= 1}
|
||||
className="pagination-button"
|
||||
>
|
||||
← Vorherige
|
||||
</button>
|
||||
|
||||
<span className="pagination-info">
|
||||
Seite {page} von {pagination.pages}
|
||||
</span>
|
||||
|
||||
<button
|
||||
onClick={() => setPage(page + 1)}
|
||||
disabled={page >= pagination.pages}
|
||||
className="pagination-button"
|
||||
>
|
||||
Nächste →
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecipeList;
|
||||
68
frontend/src/index.css
Normal file
68
frontend/src/index.css
Normal file
@@ -0,0 +1,68 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
10
frontend/src/main.tsx
Normal file
10
frontend/src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
191
frontend/src/services/api.ts
Normal file
191
frontend/src/services/api.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
import axios from 'axios';
|
||||
|
||||
// Runtime API URL detection - works in the browser
|
||||
const getApiBaseUrl = (): string => {
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
if (hostname === 'localhost' || hostname === '127.0.0.1') {
|
||||
// Local development
|
||||
return 'http://localhost:3001/api';
|
||||
} else {
|
||||
// Network access - use same host as frontend
|
||||
return `http://${hostname}:3001/api`;
|
||||
}
|
||||
};
|
||||
|
||||
const API_BASE_URL = getApiBaseUrl();
|
||||
|
||||
console.log('🔗 API Base URL:', API_BASE_URL); // Debug log
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
// Recipe interfaces
|
||||
export interface Recipe {
|
||||
id: number;
|
||||
recipeNumber: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
category?: string;
|
||||
filePath?: string;
|
||||
preparation?: string;
|
||||
servings: number;
|
||||
ingredients?: string;
|
||||
instructions?: string;
|
||||
comment?: string;
|
||||
images?: RecipeImage[];
|
||||
ingredientsList?: Ingredient[];
|
||||
}
|
||||
|
||||
export interface Ingredient {
|
||||
id: number;
|
||||
recipeNumber: string;
|
||||
ingredients: string;
|
||||
}
|
||||
|
||||
export interface RecipeImage {
|
||||
id: number;
|
||||
recipeId: number;
|
||||
filePath: string;
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data: T;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> extends ApiResponse<T[]> {
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
pages: number;
|
||||
};
|
||||
}
|
||||
|
||||
// Recipe API methods
|
||||
export const recipeApi = {
|
||||
// Get all recipes with pagination and search
|
||||
getRecipes: async (params?: {
|
||||
search?: string;
|
||||
category?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: 'asc' | 'desc';
|
||||
}): Promise<PaginatedResponse<Recipe>> => {
|
||||
const response = await api.get('/recipes', { params });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Get single recipe by ID
|
||||
getRecipe: async (id: number): Promise<ApiResponse<Recipe>> => {
|
||||
const response = await api.get(`/recipes/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Create new recipe
|
||||
createRecipe: async (recipe: Omit<Recipe, 'id'>): Promise<ApiResponse<Recipe>> => {
|
||||
const response = await api.post('/recipes', recipe);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Update recipe
|
||||
updateRecipe: async (id: number, recipe: Partial<Recipe>): Promise<ApiResponse<Recipe>> => {
|
||||
const response = await api.put(`/recipes/${id}`, recipe);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Delete recipe
|
||||
deleteRecipe: async (id: number): Promise<ApiResponse<null>> => {
|
||||
const response = await api.delete(`/recipes/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
// Ingredient API methods
|
||||
export const ingredientApi = {
|
||||
getIngredients: async (params?: {
|
||||
search?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}): Promise<PaginatedResponse<Ingredient>> => {
|
||||
const response = await api.get('/ingredients', { params });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getIngredient: async (id: number): Promise<ApiResponse<Ingredient>> => {
|
||||
const response = await api.get(`/ingredients/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createIngredient: async (ingredient: Omit<Ingredient, 'id'>): Promise<ApiResponse<Ingredient>> => {
|
||||
const response = await api.post('/ingredients', ingredient);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateIngredient: async (id: number, ingredient: Partial<Ingredient>): Promise<ApiResponse<Ingredient>> => {
|
||||
const response = await api.put(`/ingredients/${id}`, ingredient);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteIngredient: async (id: number): Promise<ApiResponse<null>> => {
|
||||
const response = await api.delete(`/ingredients/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
// Image API methods
|
||||
export const imageApi = {
|
||||
getRecipeImages: async (recipeId: number): Promise<ApiResponse<RecipeImage[]>> => {
|
||||
const response = await api.get(`/images/recipe/${recipeId}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getImageUrl: (imagePath: string): string => {
|
||||
// Use the same dynamic API base URL logic for images
|
||||
return `${API_BASE_URL}/images/serve/${imagePath}`;
|
||||
},
|
||||
|
||||
// Upload images for a recipe
|
||||
uploadImages: async (recipeId: number, files: File[], onProgress?: (progress: number) => void): Promise<ApiResponse<RecipeImage[]>> => {
|
||||
const formData = new FormData();
|
||||
files.forEach((file) => {
|
||||
formData.append('images', file);
|
||||
});
|
||||
|
||||
const response = await api.post(`/images/upload/${recipeId}`, formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
onUploadProgress: (progressEvent) => {
|
||||
if (onProgress && progressEvent.total) {
|
||||
const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
||||
onProgress(progress);
|
||||
}
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Delete an image
|
||||
deleteImage: async (imageId: number): Promise<ApiResponse<null>> => {
|
||||
const response = await api.delete(`/images/${imageId}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
// Health check
|
||||
export const healthApi = {
|
||||
check: async (): Promise<ApiResponse<{ status: string; timestamp: string }>> => {
|
||||
const response = await api.get('/health');
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
1
frontend/src/vite-env.d.ts
vendored
Normal file
1
frontend/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
27
frontend/tsconfig.app.json
Normal file
27
frontend/tsconfig.app.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
frontend/tsconfig.json
Normal file
7
frontend/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
25
frontend/tsconfig.node.json
Normal file
25
frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
7
frontend/vite.config.ts
Normal file
7
frontend/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
Reference in New Issue
Block a user