Skip to content

Commit b04e8b4

Browse files
committed
Add file upload page
1 parent fb5cf14 commit b04e8b4

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.devcontainer/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
volumes:
99
- ..:/app
1010
command: sleep infinity
11+
ports:
12+
- 8080:8080
1113
environment:
1214
PORT: 8080
1315
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/postgres

app/upload/page.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use client";
2+
3+
import { useState, ChangeEvent, FormEvent } from "react";
4+
5+
export default function UploadPage() {
6+
const [file, setFile] = useState<File | null>(null);
7+
8+
const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => {
9+
if (e.target.files && e.target.files.length > 0) {
10+
setFile(e.target.files[0]);
11+
}
12+
};
13+
14+
async function handleSubmit(e: FormEvent<HTMLFormElement>) {
15+
e.preventDefault();
16+
if (!file) return;
17+
console.log("File submitted");
18+
}
19+
20+
return (
21+
<div className="flex min-h-screen items-center justify-center bg-gray-50 text-black">
22+
<div className="w-full max-w-md rounded-lg bg-white p-6 shadow-md">
23+
<h1 className="mb-4 text-xl font-bold">File Upload</h1>
24+
25+
<form onSubmit={handleSubmit}>
26+
<div className="mb-4">
27+
<input
28+
type="file"
29+
onChange={handleFileChange}
30+
className="block w-full text-sm text-gray-500 file:mr-4 file:rounded-md file:border-0 file:bg-blue-50 file:px-4 file:py-2 file:text-sm file:font-semibold file:text-blue-700 hover:file:bg-blue-100"
31+
/>
32+
</div>
33+
34+
<button
35+
type="submit"
36+
disabled={!file}
37+
className="w-full rounded-md bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-600 disabled:cursor-not-allowed disabled:bg-gray-300"
38+
>
39+
Upload
40+
</button>
41+
</form>
42+
43+
{file && (
44+
<div className="mt-4 rounded-md bg-gray-100 p-3">
45+
<p>
46+
<strong>Selected file:</strong> {file.name}
47+
</p>
48+
<p>
49+
<strong>Size:</strong> {(file.size / 1024).toFixed(2)} KB
50+
</p>
51+
<p>
52+
<strong>Type:</strong> {file.type}
53+
</p>
54+
</div>
55+
)}
56+
</div>
57+
</div>
58+
);
59+
}

0 commit comments

Comments
 (0)