Skip to content

Commit

Permalink
🐛 Fix new image upload refresh when URL is the same
Browse files Browse the repository at this point in the history
We now add a `v` query param containing the timestamp to make sure each newly created file URL is unique
  • Loading branch information
baptisteArno committed Nov 21, 2022
1 parent 2489318 commit fbd3304
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const UploadButton = ({
},
],
})
if (urls.length && urls[0]) onFileUploaded(urls[0])
if (urls.length && urls[0]) onFileUploaded(urls[0] + '?v=' + Date.now())
setIsUploading(false)
}

Expand All @@ -43,9 +43,7 @@ export const UploadButton = ({
id="file-input"
display="none"
onChange={handleInputChange}
accept={
fileType === 'image' ? '.jpg, .jpeg, .png, .svg, .gif' : '.mp3, .wav'
}
accept={fileType === 'image' ? '.jpg, .jpeg, .png, .gif' : '.mp3, .wav'}
/>
<Button
as="label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export const MyAccountForm = () => {
isSaving,
isOAuthProvider,
} = useUser()
const [reloadParam, setReloadParam] = useState('')

const handleFileUploaded = async (url: string) => {
setReloadParam(Date.now().toString())
updateUser({ image: url })
}

Expand All @@ -46,7 +44,7 @@ export const MyAccountForm = () => {
<HStack spacing={6}>
<Avatar
size="lg"
src={user?.image ? `${user.image}?${reloadParam}` : undefined}
src={user?.image ?? undefined}
name={user?.name ?? undefined}
/>
<Stack>
Expand Down

0 comments on commit fbd3304

Please sign in to comment.