-
Notifications
You must be signed in to change notification settings - Fork 419
week 11 - edvard #451
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
Open
edv-rd
wants to merge
13
commits into
Technigo:master
Choose a base branch
from
edv-rd:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
week 11 - edvard #451
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35cbe6c
init
edv-rd 9444fcb
basic functionality
edv-rd 1a4eb38
t
edv-rd 07997e9
non functional delete button
edv-rd 0dd1c2a
functional delete button
edv-rd 30acf00
refactoring
edv-rd c5aaaba
complete all and clear all functionality
edv-rd a1b216e
started styling mobile first
edv-rd f8d2e4d
hamburger menu
edv-rd d65a635
styling
edv-rd 92eadfe
more styling
edv-rd 3de4918
changed task data
edv-rd 8a9023c
Update README.md
edv-rd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| # Project Todos | ||
|
|
||
| Replace this readme with your own information about your project. | ||
|
|
||
| Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
|
|
||
| ## The problem | ||
|
|
||
| Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
|
|
||
|
|
||
| ## View it live | ||
|
|
||
| Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
| https://reliable-torte-e7250c.netlify.app/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,31 @@ | ||
| import React from 'react'; | ||
| import { Provider } from 'react-redux' | ||
| import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
| import styled from 'styled-components/macro' | ||
| import { tasks } from './reducers/tasks' | ||
|
|
||
| import Todos from './components/Todos' | ||
|
|
||
| const StyledContainer = styled.div` | ||
| background-color: var(--background-color); | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh;` | ||
|
|
||
| const reducer = combineReducers({ | ||
| tasks: tasks.reducer | ||
| }) | ||
|
|
||
| const store = configureStore({ reducer }) | ||
|
|
||
| export const App = () => { | ||
| return ( | ||
| <div> | ||
| Find me in src/app.js! | ||
| </div> | ||
| <Provider store={store}> | ||
| <StyledContainer> | ||
| <Todos /> | ||
| </StyledContainer> | ||
| </Provider> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react' | ||
| import { useDispatch } from 'react-redux'; | ||
| import { tasks } from 'reducers/tasks' | ||
| import styled from 'styled-components/macro' | ||
|
|
||
| const StyledCheckbox = styled.input`` | ||
|
|
||
| const CheckBox = ({ id }) => { | ||
| const dispatch = useDispatch(); | ||
| const checkComplete = () => { | ||
| dispatch(tasks.actions.completeTask(id)) | ||
| } | ||
| return ( | ||
|
|
||
| <StyledCheckbox type="checkbox" text="completed?" onClick={checkComplete} /> | ||
| ); | ||
| } | ||
|
|
||
| export default CheckBox; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from 'react' | ||
| import { useDispatch } from 'react-redux'; | ||
| import { tasks } from 'reducers/tasks' | ||
| import styled from 'styled-components/macro' | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
| import { faX } from '@fortawesome/free-solid-svg-icons' | ||
|
|
||
| const StyledButton = styled.button` | ||
| background-color: inherit; | ||
| border: none; | ||
| transition: color 0.2s ease-out; | ||
| cursor: pointer; | ||
|
|
||
| ` | ||
| const DeleteButton = ({ id, completed }) => { | ||
| const dispatch = useDispatch(); | ||
|
|
||
| const handleDelete = () => { | ||
| dispatch(tasks.actions.deleteTask(id)) | ||
| } | ||
| return (<StyledButton onClick={handleDelete}><FontAwesomeIcon icon={faX} style={{ color: `var(${completed ? '--background-color' : '--foreground-primary-color'})` }} /></StyledButton>); | ||
| } | ||
|
|
||
| export default DeleteButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import React from 'react' | ||
| import { useSelector, useDispatch } from 'react-redux' | ||
| import styled from 'styled-components/macro' | ||
| import DeleteButton from './DeleteButton' | ||
| import { tasks } from '../reducers/tasks' | ||
|
|
||
| const StyledContainer = styled.div` | ||
| display: flex; | ||
| padding: 5px; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| justify-content: space-around; | ||
|
|
||
| ` | ||
|
|
||
| const StyledText = styled.p` | ||
| font-weight: 400; | ||
| font-size: 15px; | ||
| color: var(--foreground-primary-color); | ||
| flex: 1; | ||
| text-align: center; | ||
| transition: color 0.1s ease-out; | ||
| cursor: pointer; | ||
|
|
||
|
|
||
|
|
||
| &.completed { | ||
| color: var(--background-color);; | ||
| } | ||
|
|
||
| ` | ||
|
|
||
| const Task = ({ id }) => { | ||
| const dispatch = useDispatch(); | ||
| const checkComplete = () => { | ||
| dispatch(tasks.actions.completeTask(id)) | ||
| } | ||
| const task = useSelector((state) => state.tasks.todos.find((t) => t.id === id)) | ||
| return ( | ||
| <StyledContainer> | ||
|
|
||
| <StyledText | ||
| className={ | ||
| task.complete | ||
| && 'completed' | ||
| } | ||
| onClick={checkComplete}> | ||
| {task.text} | ||
| </StyledText> | ||
| <DeleteButton id={task.id} completed={task.complete} /> | ||
| </StyledContainer> | ||
| ); | ||
| } | ||
|
|
||
| export default Task; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React, { useState } from 'react' | ||
| import { useDispatch } from 'react-redux' | ||
| import { tasks } from 'reducers/tasks' | ||
| import styled from 'styled-components/macro' | ||
| import uniqid from 'uniqid' | ||
|
|
||
| const StyledContainer = styled.div` | ||
| padding: 5px; | ||
| display: flex; | ||
| flex-direction: row; | ||
| background-color: var(--foreground-primary-color); | ||
| ` | ||
|
|
||
| const StyledInput = styled.input` | ||
| border: none; | ||
| height: 20px; | ||
| font-family: "Raleway"; | ||
| ` | ||
|
|
||
| const StyledButton = styled.button` | ||
| background-color: var(--foreground-primary-color); | ||
| font-weight: 400; | ||
| color: white; | ||
| border: none; | ||
| font-family: "Raleway"; | ||
| font-size: 15px; | ||
| cursor: pointer; | ||
|
|
||
| ` | ||
|
|
||
| const TaskAdder = () => { | ||
| const [todoText, setTodoText] = useState(''); | ||
| const dispatch = useDispatch(); | ||
|
|
||
| const handleSubmit = () => { | ||
| dispatch(tasks.actions.addTask({ id: uniqid(), text: todoText, complete: false })) | ||
| } | ||
|
|
||
| return ( | ||
| <StyledContainer> | ||
| <StyledInput value={todoText} onChange={(e) => setTodoText(e.target.value)} /> | ||
| <StyledButton onClick={handleSubmit}>task</StyledButton> | ||
| </StyledContainer> | ||
| ); | ||
| } | ||
|
|
||
| export default TaskAdder; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import React, { useState } from 'react' | ||
| import styled from 'styled-components/macro' | ||
| import { useSelector, useDispatch } from 'react-redux' | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
| import { faBars } from '@fortawesome/free-solid-svg-icons' | ||
| import { tasks } from '../reducers/tasks' | ||
| import Task from './Task' | ||
|
|
||
| const StyledContainer = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| width: 100%;` | ||
|
|
||
| const StyledTasklistBar = styled.div` | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: center; | ||
| padding: 5px; | ||
| align-items: center; | ||
| background-color: var(--foreground-primary-color); | ||
|
|
||
| h1 { | ||
| font-size: 15px; | ||
| flex: 1; | ||
| color: white; | ||
| text-align: center; | ||
| } | ||
|
|
||
| ` | ||
|
|
||
| const StyledActionBar = styled.div` | ||
| display: none; | ||
| height: 0px; | ||
| opacity: 0; | ||
| transition: opacity 1s ease-out; | ||
| overflow: hidden; | ||
| background-color: var(--foreground-primary-color); | ||
|
|
||
|
|
||
|
|
||
| &.active { | ||
| opacity: 1; | ||
| height: auto; | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: center; | ||
| gap: 10px; | ||
| padding: 2px; | ||
| } | ||
| ` | ||
|
|
||
| const HamburgerMenuButton = styled.button` | ||
| width: 30px; | ||
| height: 30px; | ||
| background-color: inherit; | ||
| border: none; | ||
| cursor: pointer; | ||
| ` | ||
|
|
||
| const CompleteAllButton = styled.button` | ||
| font-weight: 400; | ||
| color: white; | ||
| border: none; | ||
| font-family: "Raleway"; | ||
| font-size: 12px; | ||
| width: 50%; | ||
| padding: 5px; | ||
| background-color: inherit; | ||
| cursor: pointer; | ||
|
|
||
| ` | ||
|
|
||
| const DeleteAllButton = styled(CompleteAllButton)` | ||
| text-decoration: underline; | ||
| text-decoration-color: red; | ||
| text-underline-offset: 4px; | ||
| ` | ||
|
|
||
| const TaskList = () => { | ||
| const [toggledActionBar, setToggledActionBar] = useState(true); | ||
|
|
||
| const toggleActionBar = () => { | ||
| setToggledActionBar(!toggledActionBar); | ||
| } | ||
|
|
||
| const dispatch = useDispatch(); | ||
|
|
||
| const handleCompleteAll = () => { | ||
| dispatch(tasks.actions.completeAllTasks()) | ||
| } | ||
| const handleDeleteAll = () => { | ||
| if (window.confirm('Are you sure you want to delete all?')) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice touch adding the window. Adds a lot to the user experience that you can't accidentally just delete everything with a single click. |
||
| dispatch(tasks.actions.deleteAllTasks()) | ||
| } | ||
| } | ||
| const tasksData = useSelector((state) => state.tasks.todos) | ||
| return ( | ||
| <StyledContainer> | ||
| <StyledTasklistBar> | ||
| <HamburgerMenuButton onClick={toggleActionBar}> | ||
| <FontAwesomeIcon icon={faBars} style={{ color: '#ffffff' }} /> | ||
| </HamburgerMenuButton> | ||
| <h1>tasks</h1> | ||
| </StyledTasklistBar> | ||
| <StyledActionBar className={toggledActionBar && 'active'}> | ||
| <CompleteAllButton value="Complete All" onClick={handleCompleteAll}>complete all</CompleteAllButton> | ||
| <DeleteAllButton value="Delete All" onClick={handleDeleteAll}>delete all</DeleteAllButton> | ||
| </StyledActionBar> | ||
| {tasksData.map((task) => ( | ||
| <Task id={task.id} key={task.id} />))} | ||
| </StyledContainer> | ||
| ); | ||
| } | ||
|
|
||
| export default TaskList; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import React from 'react' | ||
| import styled from 'styled-components/macro' | ||
| import TaskAdder from './TaskAdder'; | ||
| import TaskList from './TaskList'; | ||
|
|
||
| const TodoSection = styled.section` | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| background-color: var(--foreground-secondary-color); | ||
| overflow: visible; | ||
| box-shadow: | ||
| 0.3em 0.3em 1em rgba(0, 0, 0, 0.3); | ||
| ` | ||
|
|
||
| const Todos = () => { | ||
| return ( | ||
| <TodoSection> | ||
| <TaskList /> | ||
| <TaskAdder /> | ||
| </TodoSection> | ||
| ); | ||
| } | ||
|
|
||
| export default Todos; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat way of adding some conditional styling. Didn't know you could target classnames in styled components like this, but it makes sense once you see it.