fix(mobile): delete cleanup audio files on retry and isolate screen busy state across user switches
This commit is contained in:
parent
bd3c1a98d9
commit
cc3f7460be
5 changed files with 376 additions and 45 deletions
|
|
@ -39,6 +39,7 @@ export default function TeamsScreen({ navigation }: TeamsScreenProps): React.Rea
|
|||
const loadGeneration = useRef(0)
|
||||
const mountedRef = useRef(true)
|
||||
const userIdRef = useRef<string | null>(user?.id ?? null)
|
||||
const scopeGenerationRef = useRef(0)
|
||||
const [teams, setTeams] = useState<TeamSummary[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
|
|
@ -80,7 +81,16 @@ export default function TeamsScreen({ navigation }: TeamsScreenProps): React.Rea
|
|||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
userIdRef.current = user?.id ?? null
|
||||
const nextUserId = user?.id ?? null
|
||||
if (userIdRef.current === nextUserId) return
|
||||
userIdRef.current = nextUserId
|
||||
scopeGenerationRef.current += 1
|
||||
setTeams([])
|
||||
setError(null)
|
||||
setEditorOpen(false)
|
||||
setName('')
|
||||
setEditorBusy(false)
|
||||
setEditorError(null)
|
||||
}, [user?.id])
|
||||
|
||||
useFocusEffect(useCallback(() => {
|
||||
|
|
@ -91,20 +101,26 @@ export default function TeamsScreen({ navigation }: TeamsScreenProps): React.Rea
|
|||
const submitCreate = async (): Promise<void> => {
|
||||
if (user === null || editorBusy) return
|
||||
const actorUserId = user.id
|
||||
const actorScope = scopeGenerationRef.current
|
||||
const isCurrentActor = (): boolean => (
|
||||
mountedRef.current
|
||||
&& userIdRef.current === actorUserId
|
||||
&& scopeGenerationRef.current === actorScope
|
||||
)
|
||||
setEditorBusy(true)
|
||||
setEditorError(null)
|
||||
try {
|
||||
const team = await createTeam(actorUserId, name)
|
||||
if (!mountedRef.current || userIdRef.current !== actorUserId) return
|
||||
if (!isCurrentActor()) return
|
||||
setTeams((current) => [team, ...current.filter((row) => row.id !== team.id)])
|
||||
setName('')
|
||||
setEditorOpen(false)
|
||||
navigation.navigate('TeamDetail', { teamId: team.id })
|
||||
} catch (requestError) {
|
||||
if (!mountedRef.current || userIdRef.current !== actorUserId) return
|
||||
if (!isCurrentActor()) return
|
||||
setEditorError(teamErrorCode(requestError))
|
||||
} finally {
|
||||
if (mountedRef.current) setEditorBusy(false)
|
||||
if (isCurrentActor()) setEditorBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue