generated from Lidemy/mentor-program-5th
-
Notifications
You must be signed in to change notification settings - Fork 0
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
week23 finished #27
Merged
week23 finished #27
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains 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 @@ | ||
# redux_todoList |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,41 @@ | ||
{ | ||
"name": "todolist", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@reduxjs/toolkit": "^1.5.1", | ||
"@testing-library/jest-dom": "^4.2.4", | ||
"@testing-library/react": "^9.3.2", | ||
"@testing-library/user-event": "^7.1.2", | ||
"gh-pages": "^3.2.3", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-redux": "^7.2.3", | ||
"react-scripts": "4.0.3", | ||
"styled-components": "^5.3.3" | ||
}, | ||
"homepage": "https://dingdingdingliu.github.io/redux_todoList/", | ||
"scripts": { | ||
"predeploy": "npm run build", | ||
"deploy": "gh-pages -b master -d build", | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
This file contains 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,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
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. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
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>React Redux App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
This file contains 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,2 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * |
This file contains 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,40 @@ | ||
import React from 'react' | ||
import styled, { ThemeProvider } from 'styled-components' | ||
import GlobalStyle from './constants/globalStyle' | ||
import Header from './components/header' | ||
import MainTodoList from './components/mainTodoList' | ||
import ThemeButton from './components/themeButton' | ||
import { useSelector } from 'react-redux' | ||
import { colorThemeSelector } from './redux/selector' | ||
|
||
const AppDiv = styled.div` | ||
min-height: 100vh; | ||
background-color: ${(props) => props.theme.colors.background}; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
` | ||
const ThemeButtonDiv = styled.div` | ||
position: absolute; | ||
top: 10%; | ||
left: 90%; | ||
` | ||
|
||
function App() { | ||
const theme = useSelector(colorThemeSelector) | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyle /> | ||
<AppDiv> | ||
<ThemeButtonDiv> | ||
<ThemeButton /> | ||
</ThemeButtonDiv> | ||
<Header /> | ||
<MainTodoList /> | ||
</AppDiv> | ||
</ThemeProvider> | ||
) | ||
} | ||
|
||
export default App |
This file contains 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,8 @@ | ||
import { configureStore } from '@reduxjs/toolkit' | ||
import todoItemsReducer from '../redux/reducer' | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
todoListState: todoItemsReducer | ||
} | ||
}) |
This file contains 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,83 @@ | ||
import styled from 'styled-components' | ||
import { useCallback, useEffect } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { LargeButtonStyle } from '../button/Button' | ||
import useInput from '../../hooks/useInput' | ||
import { addTodo } from '../../redux/actions' | ||
import { useSelector } from 'react-redux' | ||
import { todoItemsSelector } from '../../redux/selector' | ||
|
||
const AddTodoDiv = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 10px; | ||
` | ||
|
||
const AddInputStyle = styled.input` | ||
padding: 10px; | ||
margin-right: 10px; | ||
border-radius: 5px; | ||
outline: none; | ||
border: 1px solid ${(props) => props.theme.colors.border}; | ||
` | ||
|
||
function AddInput({ type, placeholder, value, onChange, onKeyPress }) { | ||
return ( | ||
<AddInputStyle | ||
type={type} | ||
placeholder={placeholder} | ||
value={value} | ||
onChange={onChange} | ||
onKeyPress={onKeyPress} | ||
></AddInputStyle> | ||
) | ||
} | ||
|
||
function AddItemButton({ className, onClick, children }) { | ||
return ( | ||
<LargeButtonStyle className={className} onClick={onClick}> | ||
{children} | ||
</LargeButtonStyle> | ||
) | ||
} | ||
|
||
export default function AddTodo() { | ||
const dispatch = useDispatch() | ||
const { value, setValue, handleInputChange } = useInput() | ||
const todoItemsState = useSelector(todoItemsSelector) | ||
|
||
function setItemIntoLocalStorage(todoItemList) { | ||
const localList = { todoItems: todoItemList } | ||
window.localStorage.setItem('todoItems', JSON.stringify(localList)) | ||
} | ||
|
||
useEffect(() => { | ||
setItemIntoLocalStorage(todoItemsState) | ||
}, [todoItemsState]) | ||
|
||
const handleAddTodo = useCallback(() => { | ||
if (!value.trim('')) return setValue('') | ||
dispatch(addTodo(value)) | ||
setValue('') | ||
}, [dispatch, value, setValue]) | ||
|
||
const handleKeyPress = useCallback( | ||
(e) => { | ||
if (e.key === 'Enter') handleAddTodo() | ||
}, | ||
[handleAddTodo] | ||
) | ||
|
||
return ( | ||
<AddTodoDiv> | ||
<AddInput | ||
type='text' | ||
placeholder='Your Todo' | ||
value={value} | ||
onChange={handleInputChange} | ||
onKeyPress={handleKeyPress} | ||
/> | ||
<AddItemButton onClick={handleAddTodo}>Add Todo</AddItemButton> | ||
</AddTodoDiv> | ||
) | ||
} |
This file contains 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 @@ | ||
export { default } from './AddTodo' |
This file contains 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,29 @@ | ||
import styled from 'styled-components' | ||
|
||
const LargeButtonStyle = styled.button` | ||
padding: 8px 16px; | ||
font-size: 20px; | ||
background: ${(props) => props.theme.colors.background}; | ||
color: ${(props) => props.theme.colors.font}; | ||
border: 2px solid ${(props) => props.theme.colors.border}; | ||
border-radius: 5px; | ||
|
||
:hover { | ||
cursor: pointer; | ||
transform: scale(1.05); | ||
} | ||
` | ||
|
||
const SmallButtonStyle = styled.button` | ||
padding: 6px 10px; | ||
font-size: 14px; | ||
background: ${(props) => props.theme.colors.background}; | ||
border-radius: 5px; | ||
|
||
:hover { | ||
cursor: pointer; | ||
transform: scale(1.05); | ||
} | ||
` | ||
|
||
export { LargeButtonStyle, SmallButtonStyle } |
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.
如果你這個 component 只是把東西都傳下去,其實不需要這個,你直接用 AddInputStyle 也可以達成一樣的效果