Compare commits
19 Commits
4c3acfa2d0
...
jbin
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bd5cc138c | |||
| 5733f19673 | |||
| bda954787f | |||
| e05b9dfaf1 | |||
| ed795097a8 | |||
| 6a3b5f780b | |||
| fbf79c71ac | |||
| fadca54b3c | |||
| 79c985bada | |||
| 49ba14c001 | |||
| b039a86bb2 | |||
| 915d8493f4 | |||
| f4e06bc29a | |||
| 1efe5792d2 | |||
| a47d56b8c8 | |||
| 1647e6ab1b | |||
|
|
36787704d7 | ||
|
|
5f51e4930d | ||
| f556fda1c8 |
@@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- massage_board
|
||||
- jbin
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
|
||||
31
dockerfile
31
dockerfile
@@ -1,11 +1,32 @@
|
||||
# Dockerfile
|
||||
# Stage 1: Build React App
|
||||
FROM node:18 as build
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package.json and package-lock.json
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy the rest of the source code
|
||||
COPY . .
|
||||
|
||||
# Build the app
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Serve the app using Nginx
|
||||
FROM nginx:alpine
|
||||
|
||||
# Kopiere das gesamte 'view' Verzeichnis in das Nginx-HTML-Verzeichnis
|
||||
COPY view/ /usr/share/nginx/html/
|
||||
# Copy custom Nginx configuration
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Exponiere den Port 80 für den Container
|
||||
# Copy build artifacts to Nginx's web root
|
||||
COPY --from=build /app/build /usr/share/nginx/html
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Standardbefehl zum Starten von Nginx
|
||||
# Start Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
13
nginx.conf
Normal file
13
nginx.conf
Normal file
@@ -0,0 +1,13 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name test.out.jafre.li;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
|
||||
error_page 404 /index.html;
|
||||
}
|
||||
36
package.json
Normal file
36
package.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "nachrichten-app",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"pocketbase": "^0.13.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"react-router-dom": "^6.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tailwindcss": "^3.3.2",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.24"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
17
public/index.html
Normal file
17
public/index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Nachrichten App</title>
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<!-- Tailwind CSS (optional if used) -->
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
</head>
|
||||
<body class="bg-gray-100">
|
||||
<!-- Root element where React mounts -->
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
17
src/App.jsx
Normal file
17
src/App.jsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
|
||||
import Home from './components/Home';
|
||||
import Message from './components/Message';
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path=":id" element={<Message />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
36
src/components/Home.jsx
Normal file
36
src/components/Home.jsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import PocketBase from 'pocketbase';
|
||||
import MessageForm from './MessageForm';
|
||||
|
||||
const pb = new PocketBase('https://db.out.jafre.li');
|
||||
|
||||
const Home = () => {
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const handleSubmit = async (message) => {
|
||||
try {
|
||||
const data = { message };
|
||||
const record = await pb.collection('jbin').create(data);
|
||||
setSubmitted(record.id);
|
||||
} catch (err) {
|
||||
setError('Fehler beim Erstellen der Nachricht');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center p-4">
|
||||
<h1 className="text-2xl font-bold mb-4">Nachricht erstellen</h1>
|
||||
<MessageForm onSubmit={handleSubmit} />
|
||||
{submitted && (
|
||||
<p className="mt-4 text-green-500">
|
||||
Nachricht erstellt! Schaue sie dir hier an: <Link to={`/${submitted}`} className="text-blue-500 underline">/{submitted}</Link>
|
||||
</p>
|
||||
)}
|
||||
{error && <p className="mt-4 text-red-500">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Home;
|
||||
46
src/components/Message.jsx
Normal file
46
src/components/Message.jsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
|
||||
const pb = new PocketBase('https://db.out.jafre.li');
|
||||
|
||||
const Message = () => {
|
||||
const { id } = useParams();
|
||||
const [message, setMessage] = useState(null);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchMessage = async () => {
|
||||
try {
|
||||
const record = await pb.collection('jbin').getOne(id);
|
||||
setMessage(record.message);
|
||||
} catch (err) {
|
||||
setError('Nachricht nicht gefunden');
|
||||
}
|
||||
};
|
||||
|
||||
fetchMessage();
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center p-4">
|
||||
{error ? (
|
||||
<h1 className="text-xl font-bold text-red-500">{error}</h1>
|
||||
) : message ? (
|
||||
<>
|
||||
<h1 className="text-2xl font-bold mb-4">Nachricht</h1>
|
||||
<p className="p-4 border rounded-xl bg-gray-100 w-full max-w-md">{message}</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-gray-500">Lädt...</p>
|
||||
)}
|
||||
<Link to="/" className="mt-4">
|
||||
<button className="bg-blue-500 text-white py-2 px-4 rounded-xl hover:bg-blue-600">
|
||||
Neue Nachricht
|
||||
</button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Message;
|
||||
28
src/components/MessageForm.jsx
Normal file
28
src/components/MessageForm.jsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
const MessageForm = ({ onSubmit }) => {
|
||||
const [message, setMessage] = useState('');
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
onSubmit(message);
|
||||
setMessage('');
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-4 w-full max-w-md">
|
||||
<textarea
|
||||
className="p-2 border rounded-xl w-full"
|
||||
placeholder="Nachricht hier eingeben..."
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
required
|
||||
></textarea>
|
||||
<button type="submit" className="bg-blue-500 text-white py-2 rounded-xl hover:bg-blue-600">
|
||||
Nachricht posten
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageForm;
|
||||
11
src/index.js
Normal file
11
src/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
//import './index.css'; // Falls du globale Styles hast
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -13,14 +13,15 @@
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Message Board</h1>
|
||||
<form id="messageForm">
|
||||
<input type="text" id="name" placeholder="Your Name" required>
|
||||
<textarea id="message" placeholder="Your Message" maxlength="100" required></textarea>
|
||||
<div id="charCount">0 / 100</div>
|
||||
<button type="submit">Send</button>
|
||||
</form>
|
||||
<div id="messages">
|
||||
<!-- Nachrichten werden hier dynamisch geladen -->
|
||||
</div>
|
||||
<form id="messageForm">
|
||||
<input type="text" id="name" placeholder="Your Name" required>
|
||||
<textarea id="message" placeholder="Your Message" required></textarea>
|
||||
<button type="submit">Send</button>
|
||||
</form>
|
||||
</div>
|
||||
<script src="message-board.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
const pb = new PocketBase('https://db.out.jafre.li');
|
||||
const messageContainer = document.getElementById('messages');
|
||||
const messageForm = document.getElementById('messageForm');
|
||||
const charCount = document.getElementById('charCount');
|
||||
const messageInput = document.getElementById('message');
|
||||
|
||||
|
||||
// Funktion, um die letzten 10 Nachrichten zu laden
|
||||
async function loadMessages() {
|
||||
const result = await pb.collection('message_board').getList(1, 10, {
|
||||
const result = await pb.collection('message_board').getList(1, 8, {
|
||||
sort: '-created', // Sortiert nach Erstellungsdatum absteigend
|
||||
});
|
||||
|
||||
@@ -33,6 +36,7 @@ messageForm.addEventListener('submit', async (e) => {
|
||||
await pb.collection('message_board').create({ name, message });
|
||||
loadMessages(); // Aktualisiert die Nachrichtenanzeige
|
||||
messageForm.reset(); // Löscht das Formular
|
||||
charCount.textContent = `0 / 100`;
|
||||
} catch (error) {
|
||||
console.error('Error creating message:', error);
|
||||
}
|
||||
@@ -40,3 +44,9 @@ messageForm.addEventListener('submit', async (e) => {
|
||||
|
||||
// Nachrichten beim Laden der Seite anzeigen
|
||||
loadMessages();
|
||||
|
||||
// Event-Listener für Eingaben im Textfeld
|
||||
messageInput.addEventListener('input', () => {
|
||||
const currentLength = messageInput.value.length;
|
||||
charCount.textContent = `${currentLength} / 100`;
|
||||
});
|
||||
|
||||
@@ -108,3 +108,10 @@ form button {
|
||||
form button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
#charCount {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
text-align: right; /* Rechtsbündig unter dem Textfeld */
|
||||
width: 90%;
|
||||
}
|
||||
Reference in New Issue
Block a user