Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ylvas ToDo-project Week 11 #446

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3091043
Initial commit
YlvaKarlsson Apr 18, 2023
6e14c67
Some kind of a working to do list - yey
YlvaKarlsson Apr 18, 2023
e4d1c0a
Some more things are working and some are still in progress
YlvaKarlsson Apr 20, 2023
34edb37
Changes and some styling
YlvaKarlsson Apr 20, 2023
120290c
Changes in styling, updating font etc
YlvaKarlsson Apr 20, 2023
85f805c
Trying some more
YlvaKarlsson Apr 20, 2023
d6cad35
Not working anymore
YlvaKarlsson Apr 20, 2023
aa1d9ea
Not working!
YlvaKarlsson Apr 20, 2023
cab2f17
Fixed a border
YlvaKarlsson Apr 20, 2023
eda39f5
All working - some styling left
YlvaKarlsson Apr 21, 2023
ae0753a
Fixed some bugs
YlvaKarlsson Apr 21, 2023
cc5bf0b
Added OG-tags and updated readme
YlvaKarlsson Apr 23, 2023
13fd172
Changed to a dropdown for categories - might delete tagsinput and use…
YlvaKarlsson Apr 23, 2023
bf671dc
Fixed header-image and header-title
YlvaKarlsson Apr 23, 2023
c6539f0
Fixes in the styling
YlvaKarlsson Apr 23, 2023
e4c4602
Edited Netlify-link
YlvaKarlsson Apr 23, 2023
eab3522
New commit since auto-build to Netlify didn't work
YlvaKarlsson Apr 23, 2023
31ad477
Trying to fix this shit!
YlvaKarlsson Apr 23, 2023
ca4fc8b
Removed some unnecessary code - trying to make the deploy to Netlify …
YlvaKarlsson Apr 24, 2023
edb122a
Trying again...
YlvaKarlsson Apr 24, 2023
3c47163
Try with comment
YlvaKarlsson Apr 24, 2023
f2c16cb
Trying again
YlvaKarlsson Apr 24, 2023
6341ee8
Try again
YlvaKarlsson Apr 24, 2023
b12aa08
Trying to rename
YlvaKarlsson Apr 24, 2023
5c8a108
Renaming to force update in GitHub
YlvaKarlsson Apr 24, 2023
4395c59
Renaming again to get changes in folders published on Netlify
YlvaKarlsson Apr 24, 2023
96fc33e
Added link to favicon
YlvaKarlsson Apr 24, 2023
d8c7c22
Fixed the issue with categories
YlvaKarlsson Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
461 changes: 423 additions & 38 deletions code/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"framer-motion": "^10.12.3",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-datepicker": "^4.11.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-redux": "^8.0.5"
"react-redux": "^8.0.5",
"styled-components.macro": "^1.0.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
Binary file added code/public/favicon.ico
Binary file not shown.
4 changes: 3 additions & 1 deletion code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
Favicon provided free from Icons8 - here you can reed more about the usage of this in your own projects
https://icons8.com/license
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is such a great thing to add credits in the html, commented out.

Expand All @@ -13,7 +15,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Technigo React App</title>
<title>W11 - To-Do-App by Ylva</title>
</head>

<body>
Expand Down
22 changes: 14 additions & 8 deletions code/src/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import React from 'react';
import { Provider } from 'react-redux';
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import AddToDo from 'components/AddToDo';
import ToDoList from 'components/ToDoList';
import todos from 'redux/reducers/todos'
import { ToDoList } from 'components/ToDoList';
import { todos } from 'redux/reducers/todos'
import { GlobalStyle } from 'components/GlobalStyle';

const reducer = combineReducers({
todos: todos.reducer
});

const store = configureStore({ reducer });

export const App = () => {
const reducer = combineReducers({
todos: todos.reducer
});
const store = configureStore({ reducer });
// const reducer = combineReducers({
// todos: todos.reducer
// });
// const store = configureStore({ reducer });
return (
<Provider store={store}>
<AddToDo />
<GlobalStyle />
<ToDoList />
</Provider>
)
Expand Down
68 changes: 52 additions & 16 deletions code/src/components/AddToDo.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
/* eslint-disable jsx-a11y/label-has-associated-control */
/* eslint-disable no-undef */
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import todos from 'redux/reducers/todos';
import { todos } from 'redux/reducers/todos';
import styled from 'styled-components';

const AddToDo = () => {
const NewToDo = styled.form`
line-height: 0.5rem;
padding-bottom: 0.8rem;
`;

const Input = styled.input`
background: #a83256;
border: none;
padding: 8px;
font-size: 18px;
font-family: 'Baloo 2', cursive;
border-bottom: 2px dashed;
:focus {
outline: none;
}
`;

const AddButton = styled.button`
font-family: 'Baloo 2', cursive;
font-size: 18px;
border: none;
background: transparent;
cursor: pointer;
`;

export const AddToDo = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice that you like using styled-components! if you like different ways of styling you can read more about Sass or tailwind css :) Maybe you can also try to switch to rems, ems instead of px.

const [inputValue, setInputValue] = useState('');
const dispatch = useDispatch();
const onFormSubmit = (event) => {
event.preventDefault();

const newToDo = {
id: Date.now().toString(),
name: inputValue.charAt(0).toUpperCase() + inputValue.slice(1),
isNew: false
createdAt: new Date(),
text: inputValue.charAt(0).toUpperCase() + inputValue.slice(1),
isDone: false
};
dispatch(todos.actions.addToDo(newToDo));
dispatch(todos.actions.addItem(newToDo));
setInputValue('');
// https://www.random.org
}
};

return (
<section>
<form onSubmit={onFormSubmit}>
<label htmlFor="addToDoTaskInput">
Add Your new To Do task here!
<input value={inputValue} onChange={(event) => setInputValue(event.target.value)} id="addToDoInput" type="text" />
<NewToDo onSubmit={onFormSubmit}>
<label>
{/* htmlFor={`new-todo-input${newToDo.id}`} */}
<p>New to do:</p>
<Input
type="text"
value={inputValue}
onChange={(event) => setInputValue(event.target.value)} />
{/* id={`new-todo-input${newToDo.id}`} /> */}
</label>
<button type="submit"> Add new To Do now</button>
</form>
<AddButton type="submit" disabled={inputValue.length === 0}>
Add new To Do now
</AddButton>
</NewToDo>
</section>
)
}

export default AddToDo;
);
};
50 changes: 50 additions & 0 deletions code/src/components/GlobalStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { createGlobalStyle } from 'styled-components/macro';
import styled from 'styled-components';

export const GlobalStyle = createGlobalStyle`
body {
background-color: linear-gradient(to bottom, #3366ff 0%, #ff00ff 100%);
/* opacity: 50%; */
font-family: 'DynaPuff', cursive;
font-size: 20px;
display: flex;
justify-content: center;
}
`;

export const Wrapper = styled.div`
background: #3483eb;
width: 80vw;
text-align: center;
padding: 10px;
margin: 20px auto;
margin-bottom: 40px;
border-radius: 25px;
box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);

@media (min-width: 668px) {
width: 55vw;
}
`;

export const SingleTodo = styled.div`
margin: 10px;
border-bottom: 1px solid black;
padding-bottom: 15px;
line-height: 1em;
`;

export const Button = styled.button`
font-size: 18px;
padding: 4px 13px;
margin: 8px;
font-family: 'Baloo 2', cursive;
background: #edca7f;
color: #fff;
border: solid 2px red;
border-radius: 30px;
cursor: pointer;
/* :hover {
opacity: 70%;
} */
`;
42 changes: 42 additions & 0 deletions code/src/components/ToDoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import moment from 'moment';
import styled from 'styled-components';
import { SingleTodo } from './GlobalStyle';

const ToDoText = styled.div`
cursor: pointer;
text-decoration: ${(props) => (props.isDone ? 'line-through' : 'none')};
font-size: 24px;
`;

const DateText = styled.div`
font-style: italic;
font-size: 14px;
margin: 7px;
opacity: 50%;
`;

const DeleteButton = styled.button`
background: #a83256;
border: none;
font-family: 'DynaPuff', cursive;
font-size: 18px;
cursor: pointer;
border-radius: 50%;
padding: 0px 9px;
`;

export const ToDoItem = ({ todo, index, onDelete, onDone }) => {
return (
<SingleTodo>
<ToDoText onClick={() => onDone(todo.id)} key={todo.id} isDone={todo.isDone}>
<p>{todo.text}</p>
<DateText>Added {moment(todo.createdAt).format('HH:mm on MMM D, YYYY')}</DateText>
</ToDoText>
<DeleteButton onClick={() => onDelete(index)} type="button" title="Delete task">
{' '}
X
</DeleteButton>
</SingleTodo>
);
};
77 changes: 68 additions & 9 deletions code/src/components/ToDoList.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
/* eslint-disable no-undef */
/* eslint-disable import/named */
/* eslint-disable no-unused-vars */
import React from 'react';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { todos } from 'redux/reducers/todos';
import { ToDoItem } from './ToDoItem';
import { AddToDo } from './AddToDo';

export const ToDoList = () => {
const dispatch = useDispatch();
const allTodos = useSelector((store) => store.todos.items);

const onDone = (id) => {
dispatch(todos.actions.deleteItem(todoIndex));
};

const onDelete = (todoIndex) => {
dispatch(todos.actions.deleteItem(todoIndex));
};

const onCompleteAll = () => {
allTodos.forEach((todo) => {
if (!todo.isDone) {
dispatch(todos.actions.toggleItem(todo.id));
}
});
};

const onClearAll = () => {
if (window.confirm('Do you really want to delete all to-dos?')) {
dispatch(todos.actions.clearAll());
}
};

const todosTodo = allTodos.filter((todo) => !todo.isDone);
const doneTodos = allTodos.filter((todo) => todo.isDone);

const ToDoList = () => {
const todoList = useSelector((store) => store.todos.items)
return (
<section>
<ul>
{/* <ul>
{allTodos.map((singleToDo) => {
return <li key={singleToDo.id}>{singleToDo.name}</li>
})}
</ul> */}
<h2>To-do ({todosTodo.length})</h2>

{todosTodo.lenghth === 0 && <p>All done - great job! ✨</p>}

{todosTodo.map((todo, index) => (
<ToDoItem todo={todo} index={index} key={todo.id} onDelete={onDelete} onDone={onDone} />
))}

<AddToDo />

<h2>Done ({doneTodos.lenght})</h2>

<button type="button" onClick={onCompleteAll}>
Complete all to-dos
</button>

<button type="button" onClick={onClearAll}>
Clear all to-dos
</button>

{doneTodos.map((todo, index) => (
<ToDoItem todo={todo} index={index} key={todo.id} onDelete={onDelete} onDone={onDone} />
))}
{/* <ul>
{todoList.map((singleToDo) => {
return <li key={singleToDo.id}>{singleToDo.name}</li>
})}
</ul>
</ul> */}
</section>
)
}

export default ToDoList;
);
};
2 changes: 2 additions & 0 deletions code/src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url('https://fonts.googleapis.com/css2?family=DynaPuff:wght@400;600&display=swap');

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
Expand Down
Loading