Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[PAY-1412] Reset player state on app load #3632

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/mobile/src/screens/root-screen/RootScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useCallback, useEffect, useState } from 'react'

import { accountSelectors, chatActions, Status } from '@audius/common'
import {
accountSelectors,
chatActions,
playerActions,
Status
} from '@audius/common'
import type { NavigatorScreenParams } from '@react-navigation/native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
import { getHasCompletedAccount } from 'common/store/pages/signon/selectors'
Expand All @@ -24,6 +29,7 @@ import { StatusBar } from './StatusBar'
const { getAccountStatus } = accountSelectors
const { fetchMoreChats, fetchUnreadMessagesCount, connect, disconnect } =
chatActions
const { reset } = playerActions

export type RootScreenParamList = {
HomeStack: NavigatorScreenParams<{
Expand Down Expand Up @@ -61,9 +67,12 @@ export const RootScreen = ({
!isLoaded &&
(accountStatus === Status.SUCCESS || accountStatus === Status.ERROR)
) {
// Reset the player when the app is loaded for the first time. Fixes an issue
// where after a crash, the player would persist the previous state. PAY-1412.
dispatch(reset({ shouldAutoplay: false }))
setIsLoaded(true)
}
}, [accountStatus, setIsLoaded, isLoaded])
}, [accountStatus, setIsLoaded, isLoaded, dispatch])

// Connect to chats websockets and prefetch chats
useEffect(() => {
Expand Down