diff --git a/members/BigBear-JS/task1/TodoList/.gitignore b/members/BigBear-JS/task1/TodoList/.gitignore new file mode 100644 index 000000000..a547bf36d --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/.gitignore @@ -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? diff --git a/members/BigBear-JS/task1/TodoList/README.md b/members/BigBear-JS/task1/TodoList/README.md new file mode 100644 index 000000000..74872fd4a --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/README.md @@ -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, + }, +}) +``` diff --git a/members/BigBear-JS/task1/TodoList/eslint.config.js b/members/BigBear-JS/task1/TodoList/eslint.config.js new file mode 100644 index 000000000..092408a9f --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/eslint.config.js @@ -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 }, + ], + }, + }, +) diff --git a/members/BigBear-JS/task1/TodoList/index.html b/members/BigBear-JS/task1/TodoList/index.html new file mode 100644 index 000000000..e4b78eae1 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/members/BigBear-JS/task1/TodoList/package.json b/members/BigBear-JS/task1/TodoList/package.json new file mode 100644 index 000000000..05b186098 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/package.json @@ -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" + } +} diff --git a/members/BigBear-JS/task1/TodoList/public/vite.svg b/members/BigBear-JS/task1/TodoList/public/vite.svg new file mode 100644 index 000000000..e7b8dfb1b --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/App.css b/members/BigBear-JS/task1/TodoList/src/App.css new file mode 100644 index 000000000..01e0c5dce --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/App.css @@ -0,0 +1,4 @@ +.todolist-container { + margin: auto; + width: 300px; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/App.tsx b/members/BigBear-JS/task1/TodoList/src/App.tsx new file mode 100644 index 000000000..947bdfd0c --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/App.tsx @@ -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(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 ( +
+
+ + +
+ ) +} + +export default App diff --git a/members/BigBear-JS/task1/TodoList/src/assets/react.svg b/members/BigBear-JS/task1/TodoList/src/assets/react.svg new file mode 100644 index 000000000..6c87de9bb --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.css b/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.css new file mode 100644 index 000000000..d18c684ea --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.css @@ -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; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.tsx b/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.tsx new file mode 100644 index 000000000..74fe859b1 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/AddTodo/index.tsx @@ -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('') + const addText = () => { + if (text.trim() === '') { + alert('Please enter a todo') + return + } + onAdd(text) + setText('') + } + + return ( +
+ setText(e.target.value)} + /> + +
+ ) +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/Header/index.css b/members/BigBear-JS/task1/TodoList/src/components/Header/index.css new file mode 100644 index 000000000..2b88729e2 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/Header/index.css @@ -0,0 +1,3 @@ +.header { + text-align: center; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/Header/index.tsx b/members/BigBear-JS/task1/TodoList/src/components/Header/index.tsx new file mode 100644 index 000000000..6f7c8f0f9 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/Header/index.tsx @@ -0,0 +1,8 @@ +import './index.css' + +interface HeaderProps { + title: string +} +export default function Header({ title }: HeaderProps) { + return

{title}

+} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.css b/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.css new file mode 100644 index 000000000..485097226 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.css @@ -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; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.tsx b/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.tsx new file mode 100644 index 000000000..7ab26cf1d --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/TodoItem/index.tsx @@ -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 ( +
  • +
    {todo.text}
    +
    + + +
    +
  • + ) +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.css b/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.css new file mode 100644 index 000000000..1d3f5b6d1 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.css @@ -0,0 +1,3 @@ +.todolist { + width: 100%; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.tsx b/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.tsx new file mode 100644 index 000000000..9be40ca21 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/components/TodoList/index.tsx @@ -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 ( + + ) +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/index.css b/members/BigBear-JS/task1/TodoList/src/index.css new file mode 100644 index 000000000..a79ae0e25 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/index.css @@ -0,0 +1,7 @@ +* { + margin: 0; + padding: 0; +} +html, body { + height: 100%; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/main.tsx b/members/BigBear-JS/task1/TodoList/src/main.tsx new file mode 100644 index 000000000..6f4ac9bcc --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/main.tsx @@ -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( + + + , +) diff --git a/members/BigBear-JS/task1/TodoList/src/types.ts b/members/BigBear-JS/task1/TodoList/src/types.ts new file mode 100644 index 000000000..e950706c1 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/types.ts @@ -0,0 +1,5 @@ +export interface Todo { + id: number; + text: string; + completed: boolean; +} \ No newline at end of file diff --git a/members/BigBear-JS/task1/TodoList/src/vite-env.d.ts b/members/BigBear-JS/task1/TodoList/src/vite-env.d.ts new file mode 100644 index 000000000..11f02fe2a --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/members/BigBear-JS/task1/TodoList/tsconfig.app.json b/members/BigBear-JS/task1/TodoList/tsconfig.app.json new file mode 100644 index 000000000..f0a235055 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/tsconfig.app.json @@ -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"] +} diff --git a/members/BigBear-JS/task1/TodoList/tsconfig.json b/members/BigBear-JS/task1/TodoList/tsconfig.json new file mode 100644 index 000000000..1ffef600d --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [], + "references": [ + { "path": "./tsconfig.app.json" }, + { "path": "./tsconfig.node.json" } + ] +} diff --git a/members/BigBear-JS/task1/TodoList/tsconfig.node.json b/members/BigBear-JS/task1/TodoList/tsconfig.node.json new file mode 100644 index 000000000..0d3d71446 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/tsconfig.node.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["vite.config.ts"] +} diff --git a/members/BigBear-JS/task1/TodoList/vite.config.ts b/members/BigBear-JS/task1/TodoList/vite.config.ts new file mode 100644 index 000000000..5a33944a9 --- /dev/null +++ b/members/BigBear-JS/task1/TodoList/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], +})