Skip to content

Commit

Permalink
[C-5509] Fix track title reset on replace track edit (#10708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Shanks authored Dec 13, 2024
1 parent 1aed8b5 commit 5f58ad2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/mobile/src/screens/edit-track-screen/EditTrackForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect, useState } from 'react'
import { useCallback, useContext, useEffect, useRef, useState } from 'react'

import { useFeatureFlag } from '@audius/common/hooks'
import { DownloadQuality } from '@audius/common/models'
Expand Down Expand Up @@ -111,6 +111,7 @@ export const EditTrackForm = (props: EditTrackFormProps) => {
const [{ value: streamUrl }] = useField('stream.url')
const [, { touched: isTitleTouched }, { setValue: setTitle }] =
useField('title')
const hasTitleEverBeenTouched = useRef(false)

const handleOverflowMenuOpen = useCallback(() => {
setIsOverflowMenuOpen(true)
Expand Down Expand Up @@ -150,12 +151,18 @@ export const EditTrackForm = (props: EditTrackFormProps) => {
}
}, [dirty, navigation, dispatch])

useEffect(() => {
if (isTitleTouched) {
hasTitleEverBeenTouched.current = true
}
}, [isTitleTouched])

// Update title when the file is replaced
useEffect(() => {
if (isUpload && track && !isTitleTouched) {
if (isUpload && track && !hasTitleEverBeenTouched.current) {
setTitle(track.metadata.title)
}
}, [isTitleTouched, isUpload, setTitle, track])
}, [isUpload, setTitle, track])

const handleReplaceAudio = useCallback(() => {
if (!track) return
Expand Down

0 comments on commit 5f58ad2

Please sign in to comment.