File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { SquarePen } from 'lucide-react'
33import { getUser } from '#/util.ts'
44import { useImmer } from 'use-immer'
55import { Button } from '#/components/Buttons.tsx'
6+ import { useRef } from 'react'
7+ import type { ChangeEvent } from 'react'
68
79export 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 >
You can’t perform that action at this time.
0 commit comments