Settings.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { useEffect, useState } from "react";
  2. import "./App.css";
  3. function Settings() {
  4. const [autoComma, setAutoComma] = useState(false);
  5. const [allowStart, setAllowStart] = useState(false);
  6. useEffect(()=>{
  7. let comma = JSON.parse(window.localStorage.getItem("autoMoveComma"));
  8. setAutoComma(comma);
  9. console.log("current auto comma state:", comma);
  10. let start = JSON.parse(window.localStorage.getItem("allowStartOver"));
  11. setAllowStart(start);
  12. console.log("current allow start state:", start);
  13. }, []);
  14. function handleMoveChange(newValue) {
  15. window.localStorage.setItem("autoMoveComma", newValue.target.checked);
  16. console.log("set auto comma state:", newValue.target.checked);
  17. setAutoComma(newValue.target.checked);
  18. }
  19. function handleStartChange(newValue) {
  20. window.localStorage.setItem("allowStartOver", newValue.target.checked);
  21. console.log("set allow start state:", newValue.target.checked);
  22. setAllowStart(newValue.target.checked);
  23. }
  24. return (
  25. <main>
  26. <h1>Einstellungen</h1>
  27. <form>
  28. <input type="checkbox" id="autoMoveComma" name="autoMoveComma" autoFocus
  29. onChange={(e) => handleMoveChange(e)}
  30. checked={autoComma} />
  31. <label htmlFor="autoMoveComma">Zahlen automatisch ausrichten</label>
  32. <br/>
  33. <input type="checkbox" id="allowStartOver" name="allowStartOver"
  34. onChange={(e) => handleStartChange(e)}
  35. checked={allowStart}/>
  36. <label htmlFor="allowStartOver">Fehler ausbessern erlauben</label>
  37. </form>
  38. </main>
  39. );
  40. }
  41. export default Settings;