Passpass119 commited on
Commit
4ed92bb
·
verified ·
1 Parent(s): 1a7e1cf

Add 8 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM node:18-alpine AS base
3
+
4
+ # Install dependencies only when needed
5
+ FROM base AS deps
6
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7
+ RUN apk add --no-cache libc6-compat
8
+ WORKDIR /app
9
+
10
+ # Install dependencies based on the preferred package manager
11
+ COPY package.json package-lock.json* ./
12
+ RUN npm install
13
+
14
+ # Uncomment the following lines if you want to use a secret at buildtime,
15
+ # for example to access your private npm packages
16
+ # RUN --mount=type=secret,id=HF_EXAMPLE_SECRET,mode=0444,required=true # $(cat /run/secrets/HF_EXAMPLE_SECRET)
17
+
18
+ # Rebuild the source code only when needed
19
+ FROM base AS builder
20
+ WORKDIR /app
21
+ COPY --from=deps /app/node_modules ./node_modules
22
+ COPY . .
23
+
24
+ # Next.js collects completely anonymous telemetry data about general usage.
25
+ # Learn more here: https://nextjs.org/telemetry
26
+ # Uncomment the following line in case you want to disable telemetry during the build.
27
+ # ENV NEXT_TELEMETRY_DISABLED 1
28
+
29
+ RUN npm run build
30
+
31
+ # Production image, copy all the files and run next
32
+ FROM base AS runner
33
+ WORKDIR /app
34
+
35
+ ENV NODE_ENV production
36
+ # Uncomment the following line in case you want to disable telemetry during runtime.
37
+ # ENV NEXT_TELEMETRY_DISABLED 1
38
+
39
+ RUN addgroup --system --gid 1001 nodejs
40
+ RUN adduser --system --uid 1001 nextjs
41
+
42
+ COPY --from=builder /app/public ./public
43
+
44
+ # Automatically leverage output traces to reduce image size
45
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
46
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
47
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
48
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
49
+ # COPY --from=builder --chown=nextjs:nodejs /app/.next/cache/fetch-cache ./.next/cache/fetch-cache
50
+
51
+ USER nextjs
52
+
53
+ EXPOSE 3000
54
+
55
+ ENV PORT 3000
56
+
57
+ CMD ["node", "server.js"]
package.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "todo-list",
3
+ "version": "1.0.0",
4
+ "description": "A simple todo list app using Next.js",
5
+ "main": "main.js",
6
+ "dependencies": {
7
+ "react": "18.2.0",
8
+ "react-dom": "18.2.0",
9
+ "typescript": "5.1.6"
10
+ },
11
+ "scripts": {
12
+ "build": "next build",
13
+ "start": "next start"
14
+ }
15
+ }
public/index.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Todo List</title>
6
+ </head>
7
+ <body>
8
+ <div id="root"></div>
9
+ <script src="main.js"></script>
10
+ </body>
11
+ </html>
src/components/Todo.tsx ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const Todo = ({ todo, createTodo }: { todo: Todo, createTodo: (title: string, deadline: string, status: string) => void }) => {
2
+ const handleClick = () => {
3
+ const titleInput = prompt('Enter a new title for the todo');
4
+ const deadlineInput = prompt('Enter a new deadline for the todo');
5
+ const statusInput = prompt('Enter a new status for the todo');
6
+ createTodo(titleInput ?? todo.title, deadlineInput ?? todo.deadline, statusInput ?? todo.status);
7
+ };
8
+
9
+ return (
10
+ <li>
11
+ <h2>{todo.title}</h2>
12
+ <p>{todo.deadline}</p>
13
+ <p>{todo.status}</p>
14
+ <button onClick={handleClick}>Edit</button>
15
+ </li>
16
+ );
17
+ };
18
+
19
+ export default Todo;
src/components/TodoList.tsx ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Todo from '../components/Todo';
2
+
3
+ const TodoList = ({ todos, createTodo }: { todos: Todo[], createTodo: (title: string, deadline: string, status: string) => void }) => {
4
+ return (
5
+ <ul>
6
+ {todos.map((todo) => (
7
+ <Todo key={todo.id} todo={todo} createTodo={createTodo} />
8
+ ))}
9
+ </ul>
10
+ );
11
+ };
12
+
13
+ export default TodoList;
src/pages/index.tsx ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react';
2
+ import TodoList from '../components/TodoList';
3
+
4
+ const App = () => {
5
+ const [todos, setTodos] = useState([]);
6
+
7
+ const createTodo = (title, deadline, status) => {
8
+ const newTodo = {
9
+ title,
10
+ deadline,
11
+ status,
12
+ };
13
+ setTodos([...todos, newTodo]);
14
+ };
15
+
16
+ return (
17
+ <div>
18
+ <h1>Todo List</h1>
19
+ <TodoList todos={todos} createTodo={createTodo} />
20
+ </div>
21
+ );
22
+ };
23
+
24
+ export default App;
src/types.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ interface Todo {
2
+ id: number;
3
+ title: string;
4
+ deadline: string;
5
+ status: string;
6
+ }
tsconfig.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "noEmit": true,
10
+ "esModuleInterop": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "node",
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "jsx": "preserve",
16
+ "incremental": true,
17
+ "plugins": [
18
+ {
19
+ "name": "next"
20
+ }
21
+ ],
22
+ "paths": {
23
+ "@/*": ["./src/*"]
24
+ }
25
+ },
26
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
27
+ "exclude": ["node_modules"]
28
+ }