fix: dispatch ADD_START, correlate preview/lookup responses with the current attempt
This commit is contained in:
@@ -24,9 +24,9 @@ export type ScanAction =
|
||||
| { type: 'DETECT'; code: string }
|
||||
| { type: 'CANDIDATES'; code: string; candidates: Candidate[] }
|
||||
| { type: 'NOT_FOUND'; code: string }
|
||||
| { type: 'ERROR'; kind: ScanErrorKind; code: string | null }
|
||||
| { type: 'ERROR'; kind: ScanErrorKind; code: string | null; source: 'lookup' | 'preview'; candidateId?: number }
|
||||
| { type: 'SELECT'; candidate: Candidate }
|
||||
| { type: 'PREVIEW'; preview: ReleasePreview }
|
||||
| { type: 'PREVIEW'; preview: ReleasePreview; candidateId: number }
|
||||
| { type: 'SET_MATCH'; albumId: number }
|
||||
| { type: 'CLEAR_MATCH' }
|
||||
| { type: 'ADD_START' }
|
||||
@@ -43,7 +43,10 @@ export function scanReducer(state: ScanState, action: ScanAction): ScanState {
|
||||
case 'NOT_FOUND':
|
||||
return state.phase === 'looking' ? { phase: 'error', kind: 'not_found', code: action.code } : state
|
||||
case 'ERROR':
|
||||
return state.phase === 'looking' || state.phase === 'candidates' || state.phase === 'confirm'
|
||||
if (action.source === 'lookup') {
|
||||
return state.phase === 'looking' ? { phase: 'error', kind: action.kind, code: action.code } : state
|
||||
}
|
||||
return state.phase === 'confirm' && state.candidate.id === action.candidateId
|
||||
? { phase: 'error', kind: action.kind, code: action.code }
|
||||
: state
|
||||
case 'SELECT':
|
||||
@@ -59,7 +62,9 @@ export function scanReducer(state: ScanState, action: ScanAction): ScanState {
|
||||
}
|
||||
: state
|
||||
case 'PREVIEW':
|
||||
return state.phase === 'confirm' ? { ...state, preview: action.preview } : state
|
||||
return state.phase === 'confirm' && state.candidate.id === action.candidateId
|
||||
? { ...state, preview: action.preview }
|
||||
: state
|
||||
case 'SET_MATCH':
|
||||
return state.phase === 'confirm' ? { ...state, matchAlbumId: action.albumId } : state
|
||||
case 'CLEAR_MATCH':
|
||||
|
||||
Reference in New Issue
Block a user