Readme angepasst, Leserlichkeit im Code leicht verbessert
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
# React App zum Laufen bringen
|
# Inhalt des Repositories
|
||||||
1. 'react-todolist' Ordner in Eingabeaufforderung oder PowerShell öffnen
|
In dem Repositories liegen die Dateien des aktuellen Bausteins WJSF. Neben den reinen html/css/js-Seiten sind aktuell drei React-Apps enthalten.
|
||||||
|
|
||||||
|
Die React-Apps liegen in den Verzeichnissen 'Erster React Test', 'react-todolist' und 'react-unterricht-todolist'.
|
||||||
|
|
||||||
|
react-todolist enthält eine für React angepasste Todo-App von Montag. react-unterricht-todolist ist eine vereinfachte Variante der heute (Dienstag) vorgestellten App (keine API-Aufrufe, keine Statistiken).
|
||||||
|
|
||||||
|
React Apps lassen sich nach klonen des Repositories nicht einfach so öffnen. Es müssen erst Pakete etc. nachgeladen werden. Dafür kann die untenstehende Anleitung verwendet werden.
|
||||||
|
# React Apps zum Laufen bringen
|
||||||
|
1. Mit Eingabeaufforderung oder PowerShell Ordner mit React-App öffnen
|
||||||
2. `npm install` -> npm installiert Abhängigkeiten für React
|
2. `npm install` -> npm installiert Abhängigkeiten für React
|
||||||
3. `npm run dev` -> npm startet React-Development-Server; Ausgabe sollte ungefähr sein:
|
3. `npm run dev` -> npm startet React-Development-Server; Ausgabe sollte ungefähr sein:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ function App() {
|
|||||||
};
|
};
|
||||||
setTodos((currentTodos) => [newTodo, ...currentTodos]);
|
setTodos((currentTodos) => [newTodo, ...currentTodos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTodo(id) {
|
function toggleTodo(id) {
|
||||||
setTodos((currentTodos) =>
|
setTodos((currentTodos) =>
|
||||||
currentTodos.map((todo) =>
|
currentTodos.map((todo) =>
|
||||||
@@ -22,6 +23,7 @@ function App() {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTodo(id) {
|
function deleteTodo(id) {
|
||||||
setTodos((currentTodos) =>
|
setTodos((currentTodos) =>
|
||||||
currentTodos.filter((todo) => todo.id !== id)
|
currentTodos.filter((todo) => todo.id !== id)
|
||||||
|
|||||||
@@ -1,22 +1,30 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
function TodoForm({ onAddTodo }) {
|
function TodoForm({ onAddTodo }) {
|
||||||
const [input, setInput] = useState("");
|
const [input, setInput] = useState("");
|
||||||
const [priority, setPriority] = useState("normal");
|
const [priority, setPriority] = useState("normal");
|
||||||
const [validationError, setValidationError] = useState("");
|
const [validationError, setValidationError] = useState("");
|
||||||
|
|
||||||
function handleSubmit(event) {
|
function handleSubmit(event) {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const cleanedInput = input.trim();
|
const cleanedInput = input.trim();
|
||||||
|
|
||||||
if (cleanedInput === "") {
|
if (cleanedInput === "") {
|
||||||
setValidationError("Bitte geben Sie eine Aufgabe ein.");
|
setValidationError("Bitte geben Sie eine Aufgabe ein.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddTodo(cleanedInput, priority);
|
onAddTodo(cleanedInput, priority);
|
||||||
|
|
||||||
setInput("");
|
setInput("");
|
||||||
setPriority("normal");
|
setPriority("normal");
|
||||||
setValidationError("");
|
setValidationError("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="todo-form" onSubmit={handleSubmit}>
|
<form className="todo-form" onSubmit={handleSubmit}>
|
||||||
|
|
||||||
<div className="form-field">
|
<div className="form-field">
|
||||||
<label htmlFor="todo-input">Neue Aufgabe</label>
|
<label htmlFor="todo-input">Neue Aufgabe</label>
|
||||||
<input
|
<input
|
||||||
@@ -27,6 +35,7 @@ function TodoForm({ onAddTodo }) {
|
|||||||
placeholder="Zum Beispiel: React-Komponenten wiederholen"
|
placeholder="Zum Beispiel: React-Komponenten wiederholen"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="form-field">
|
<div className="form-field">
|
||||||
<label htmlFor="priority">Priorität</label>
|
<label htmlFor="priority">Priorität</label>
|
||||||
<select
|
<select
|
||||||
@@ -39,6 +48,7 @@ function TodoForm({ onAddTodo }) {
|
|||||||
<option value="high">Hoch</option>
|
<option value="high">Hoch</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button className="primary-button" type="submit">
|
<button className="primary-button" type="submit">
|
||||||
Aufgabe hinzufügen
|
Aufgabe hinzufügen
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user