-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1396 from BigBear-JS/task1
task1:BigBear-JS
- Loading branch information
Showing
25 changed files
with
401 additions
and
0 deletions.
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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,50 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
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,28 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
import tseslint from 'typescript-eslint' | ||
|
||
export default tseslint.config( | ||
{ ignores: ['dist'] }, | ||
{ | ||
extends: [js.configs.recommended, ...tseslint.configs.recommended], | ||
files: ['**/*.{ts,tsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
) |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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 @@ | ||
{ | ||
"name": "todolist", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.9.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"eslint": "^9.9.0", | ||
"eslint-plugin-react-hooks": "^5.1.0-rc.0", | ||
"eslint-plugin-react-refresh": "^0.4.9", | ||
"globals": "^15.9.0", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^8.0.1", | ||
"vite": "^5.4.1" | ||
} | ||
} |
Loading
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,4 @@ | ||
.todolist-container { | ||
margin: auto; | ||
width: 300px; | ||
} |
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,50 @@ | ||
import { useState, useEffect } from 'react' | ||
import { Todo } from './types' | ||
import Header from './components/Header' | ||
import AddTodo from './components/AddTodo' | ||
import TodoList from './components/TodoList' | ||
|
||
import './App.css' | ||
|
||
function App() { | ||
const [todos, setTodos] = useState<Todo[]>(JSON.parse(localStorage.getItem('todos') || '[]')) | ||
|
||
const addTodo = (text: string) => { | ||
setTodos([ | ||
...todos, | ||
{ | ||
id: Date.now(), | ||
text: text, | ||
completed: false, | ||
} | ||
]) | ||
} | ||
const deleteTodo = (id: number) => { | ||
setTodos(todos.filter(todo => todo.id !== id)) | ||
} | ||
const toggleCompleted = (id: number) => { | ||
setTodos(todos.map(todo => { | ||
if (todo.id === id) { | ||
return { | ||
...todo, | ||
completed: !todo.completed | ||
} | ||
} | ||
return todo | ||
})) | ||
} | ||
|
||
useEffect(() => { | ||
localStorage.setItem('todos', JSON.stringify(todos)) | ||
}, [todos]) | ||
|
||
return ( | ||
<div className='todolist-container'> | ||
<Header title={"Todo List"} /> | ||
<AddTodo onAdd={addTodo} /> | ||
<TodoList onDelete={deleteTodo} onToggle={toggleCompleted} todos={todos} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.css
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,17 @@ | ||
.addtodo { | ||
padding: 5px 0; | ||
display: flex; | ||
justify-content: space-between; | ||
height: 40px; | ||
} | ||
.addtodo input { | ||
flex: 1; | ||
padding: 0 5px; | ||
box-sizing: border-box; | ||
} | ||
.addtodo button { | ||
margin-left: 10px; | ||
padding: 0 5px; | ||
color: #fff; | ||
background: #000; | ||
} |
29 changes: 29 additions & 0 deletions
29
members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.tsx
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 { useState } from 'react'; | ||
import './index.css' | ||
|
||
interface AddTodoProps { | ||
onAdd: (text: string) => void; | ||
} | ||
export default function AddTodo({ onAdd }: AddTodoProps) { | ||
const [text, setText] = useState<string>('') | ||
const addText = () => { | ||
if (text.trim() === '') { | ||
alert('Please enter a todo') | ||
return | ||
} | ||
onAdd(text) | ||
setText('') | ||
} | ||
|
||
return ( | ||
<div className="addtodo"> | ||
<input | ||
type="text" | ||
placeholder="Add Todo" | ||
value={text} | ||
onChange={e => setText(e.target.value)} | ||
/> | ||
<button onClick={addText}>Add</button> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
members/BigBear-JS/task1/TodoList/src/components/Header/index.css
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,3 @@ | ||
.header { | ||
text-align: center; | ||
} |
8 changes: 8 additions & 0 deletions
8
members/BigBear-JS/task1/TodoList/src/components/Header/index.tsx
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 './index.css' | ||
|
||
interface HeaderProps { | ||
title: string | ||
} | ||
export default function Header({ title }: HeaderProps) { | ||
return <h1>{title}</h1> | ||
} |
18 changes: 18 additions & 0 deletions
18
members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.css
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,18 @@ | ||
.todoitem { | ||
padding: 5px 0; | ||
margin-bottom: 10px; | ||
display: flex; | ||
justify-content: space-between; | ||
border-bottom: 2px solid #ccc; | ||
} | ||
.todoitem-text { | ||
flex: 1; | ||
margin-right: 10px; | ||
white-space: wrap; | ||
word-break: break-all; | ||
} | ||
.todoitem button { | ||
padding: 5px; | ||
color: #fff; | ||
background: #000; | ||
} |
19 changes: 19 additions & 0 deletions
19
members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.tsx
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,19 @@ | ||
import { Todo } from "../../types"; | ||
import './index.css' | ||
|
||
interface TodoItemProps { | ||
todo: Todo; | ||
onDelete: (id: number) => void; | ||
onToggle: (id: number) => void; | ||
} | ||
export default function TodoItem({ todo, onDelete, onToggle }: TodoItemProps) { | ||
return ( | ||
<li className="todoitem"> | ||
<div className="todoitem-text" style={{textDecoration: todo.completed ? 'line-through' : 'none'}}>{todo.text}</div> | ||
<div> | ||
<button onClick={() => onToggle(todo.id)}>toggle</button> | ||
<button onClick={() => onDelete(todo.id)}>delete</button> | ||
</div> | ||
</li> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
members/BigBear-JS/task1/TodoList/src/components/TodoList/index.css
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,3 @@ | ||
.todolist { | ||
width: 100%; | ||
} |
21 changes: 21 additions & 0 deletions
21
members/BigBear-JS/task1/TodoList/src/components/TodoList/index.tsx
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,21 @@ | ||
import { Todo } from "../../types" | ||
import TodoItem from "../TodoItem" | ||
import './index.css' | ||
|
||
interface TodoListProps { | ||
todos: Todo[]; | ||
onToggle: (id: number) => void; | ||
onDelete: (id: number) => void; | ||
} | ||
export default function TodoList({todos, onDelete, onToggle}: TodoListProps) { | ||
|
||
return ( | ||
<ul className="todolist"> | ||
{ | ||
todos.map(todo => { | ||
return <TodoItem key={todo.id} todo={todo} onToggle={onToggle} onDelete={onDelete} /> | ||
}) | ||
} | ||
</ul> | ||
) | ||
} |
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,7 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
html, body { | ||
height: 100%; | ||
} |
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,10 @@ | ||
import { StrictMode } from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import App from './App.tsx' | ||
import './index.css' | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
) |
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,5 @@ | ||
export interface Todo { | ||
id: number; | ||
text: string; | ||
completed: boolean; | ||
} |
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 @@ | ||
/// <reference types="vite/client" /> |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.