Skip to content

Commit

Permalink
Update npm dependencies and add @firecms/neat library for gradient co…
Browse files Browse the repository at this point in the history
…mponent
  • Loading branch information
markohautala committed Jul 14, 2024
1 parent 34f5e62 commit 3da8e85
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 326 deletions.
36 changes: 18 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Todo App</title>
<link rel="apple-touch-icon" sizes="180x180" href="src/images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="src/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="src/images/favicon-16x16.png">


<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Todo App</title>
<link rel="apple-touch-icon" sizes="180x180" href="src/images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="src/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="src/images/favicon-16x16.png">
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
<div class="main-container">
<p class="title">Built with React</p>
<div class="container">
<span class="react-logo">
<span class="nucleo"></span>
</span>
<canvas id="gradientCanvas" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;"></canvas>
<div id="root"></div>
<div class="main-container">
<p class="title">Built with React</p>
<div class="container">
<span class="react-logo">
<span class="nucleo"></span>
</span>
</div>
</div>
</div>

<script type="module" src="/src/main.jsx"></script>
</body>

</html>
</html>
37 changes: 36 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"preview": "vite preview"
},
"dependencies": {
"@firecms/neat": "^0.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"three.js": "^0.77.1"
},
"devDependencies": {
"@types/react": "^18.2.55",
Expand Down
110 changes: 57 additions & 53 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
import { useEffect, useState } from "react"
import { NewTodoForm } from "./NewTodoForm"
import "./styles.css"
import { TodoList } from "./TodoList"

export default function App() {
// Store the todos in local storage
const [todos, setTodos] = useState(() => {
const localValue = localStorage.getItem("ITEMS")
if (localValue == null) return []

return JSON.parse(localValue)
})
// every time the todos change, update the local storage
useEffect(() => {
localStorage.setItem("ITEMS", JSON.stringify(todos))
}, [todos])

function addTodo(title) {
setTodos(currentTodos => {
return [
...currentTodos,
{ id: crypto.randomUUID(), title, completed: false },
]
})
}

function toggleTodo(id, completed) {
setTodos(currentTodos => {
return currentTodos.map(todo => {
if (todo.id === id) {
return { ...todo, completed }
}

return todo
})
})
}

function deleteTodo(id) {
setTodos(currentTodos => {
return currentTodos.filter(todo => todo.id !== id)
})
}

return (
<>
<NewTodoForm onSubmit={addTodo} />
<h1 className="header">Todo List:</h1>
<TodoList todos={todos} toggleTodo={toggleTodo} deleteTodo={deleteTodo} />
</>
)
}
import React, { useEffect, useState } from "react";
import { NewTodoForm } from "./NewTodoForm";
import "./styles.css";
import { TodoList } from "./TodoList";
import GradientComponent from "./GradientComponent";

function App() {
const [todos, setTodos] = useState(() => {
const localValue = localStorage.getItem("ITEMS");
return localValue ? JSON.parse(localValue) : [];
});

const [backgroundColor, setBackgroundColor] = useState("#0b3954");

useEffect(() => {
localStorage.setItem("ITEMS", JSON.stringify(todos));
}, [todos]);

function addTodo(title) {
setTodos((currentTodos) => [
...currentTodos,
{ id: crypto.randomUUID(), title, completed: false },
]);
}

function toggleTodo(id, completed) {
setTodos((currentTodos) =>
currentTodos.map((todo) =>
todo.id === id ? { ...todo, completed } : todo
)
);
}

function deleteTodo(id) {
setTodos((currentTodos) =>
currentTodos.filter((todo) => todo.id !== id)
);
}

// Set the background color directly on the body tag
useEffect(() => {
document.body.style.backgroundColor = backgroundColor;
}, [backgroundColor]);

return (
<>
<GradientComponent onBackgroundColorChange={setBackgroundColor} />
<div className="app-container">
<NewTodoForm onSubmit={addTodo} />
<h1 className="header">Todo List:</h1>
<TodoList todos={todos} toggleTodo={toggleTodo} deleteTodo={deleteTodo} />
</div>
</>
);
}

export default App;
74 changes: 74 additions & 0 deletions src/GradientComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// GradientComponent.jsx

import React, { useEffect, useRef } from "react";
import { NeatGradient } from "@firecms/neat";

const GradientComponent = () => {
const canvasRef = useRef(null);
const gradientRef = useRef(null);

useEffect(() => {
if (!canvasRef.current) return;

const config = {
"colors": [
{
"color": "#D5DFF4",
"enabled": true
},
{
"color": "#ECF2FF",
"enabled": true
},
{
"color": "#F3D4F2",
"enabled": true
},
{
"color": "#E0E7FF",
"enabled": true
},
{
"color": "#F6FFFF",
"enabled": true
}
],
"speed": 8,
"horizontalPressure": 2,
"verticalPressure": 5,
"waveFrequencyX": 2,
"waveFrequencyY": 4,
"waveAmplitude": 8,
"shadows": 7,
"highlights": 6,
"colorBrightness": 1.05,
"colorSaturation": 1,
"wireframe": false,
"colorBlending": 7,
"backgroundColor": "#0b3954",
"backgroundAlpha": 1,
"resolution": 2
};

gradientRef.current = new NeatGradient({
ref: canvasRef.current,
...config,
});

return () => {
if (gradientRef.current) {
gradientRef.current.destroy();
}
};
}, []);

return (
<canvas
id="gradientCanvas"
style={{ position: "fixed", top: 0, left: 0, width: "100%", height: "100%", zIndex: -1 }}
ref={canvasRef}
/>
);
};

export default GradientComponent;
17 changes: 9 additions & 8 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Loading

0 comments on commit 3da8e85

Please sign in to comment.