Skip to content

Commit 78fe562

Browse files
committed
Add avatar upload functionality to profile page
1 parent 6198724 commit 78fe562

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

web-interface/src/routes/profile.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { SquarePen } from 'lucide-react'
33
import { getUser } from '#/util.ts'
44
import { useImmer } from 'use-immer'
55
import { Button } from '#/components/Buttons.tsx'
6+
import { useRef } from 'react'
7+
import type { ChangeEvent } from 'react'
68

79
export const Route = createFileRoute('/profile')({
810
component: ProfilePage,
@@ -43,6 +45,16 @@ function ProfilePage() {
4345
password: '',
4446
confirmPassword: '',
4547
})
48+
const avatarUploadRef = useRef<HTMLInputElement>(null)
49+
50+
function handleAvatarUpload(event: ChangeEvent<HTMLInputElement>) {
51+
const file = event.target.files?.[0]
52+
53+
if (!file) return
54+
55+
// TODO: call API to upload avatar
56+
console.log(`Uploaded image ${file.name}`)
57+
}
4658

4759
function handleSave() {
4860
// TODO: call API to update profile
@@ -186,15 +198,19 @@ function ProfilePage() {
186198
/>
187199
<div className="absolute bottom-3 left-3">
188200
<Button
189-
onClick={() => {
190-
// TODO: open file picker to upload new avatar
191-
console.log('Edit profile picture')
192-
}}
201+
onClick={() => avatarUploadRef.current?.click()}
193202
variant="normal"
194203
fontSize="base"
195204
>
196205
Edit <SquarePen size={16} />
197206
</Button>
207+
<input
208+
type="file"
209+
className="hidden"
210+
accept="image/*"
211+
ref={avatarUploadRef}
212+
onChange={handleAvatarUpload}
213+
/>
198214
</div>
199215
</div>
200216
</div>

0 commit comments

Comments
 (0)