|
1 | 1 | import * as React from 'react'; |
2 | 2 | import QuickStartContent from './controller/QuickStartContent'; |
3 | 3 | import QuickStartFooter from './controller/QuickStartFooter'; |
4 | | -import { QuickStartContext, QuickStartContextValues } from './utils/quick-start-context'; |
| 4 | +import { |
| 5 | + getDefaultQuickStartState, |
| 6 | + QuickStartContext, |
| 7 | + QuickStartContextValues, |
| 8 | +} from './utils/quick-start-context'; |
5 | 9 | import { QuickStart, QuickStartStatus, QuickStartTaskStatus } from './utils/quick-start-types'; |
6 | 10 |
|
7 | 11 | interface QuickStartControllerProps { |
@@ -35,13 +39,26 @@ export const QuickStartController: React.FC<QuickStartControllerProps> = ({ |
35 | 39 | } = quickStart; |
36 | 40 | const totalTasks = tasks?.length; |
37 | 41 | const { |
| 42 | + activeQuickStartID, |
| 43 | + allQuickStartStates, |
| 44 | + setAllQuickStartStates, |
38 | 45 | activeQuickStartState, |
39 | 46 | setActiveQuickStart, |
40 | 47 | setQuickStartTaskNumber, |
41 | 48 | setQuickStartTaskStatus, |
42 | 49 | nextStep, |
43 | 50 | previousStep, |
44 | 51 | } = React.useContext<QuickStartContextValues>(QuickStartContext); |
| 52 | + React.useEffect(() => { |
| 53 | + // If activeQuickStartID was changed through prop from QuickStartContainer, need to init the state if it does not exist yet |
| 54 | + if (activeQuickStartID && !allQuickStartStates[activeQuickStartID]) { |
| 55 | + setAllQuickStartStates({ |
| 56 | + ...allQuickStartStates, |
| 57 | + [activeQuickStartID]: getDefaultQuickStartState(), |
| 58 | + }); |
| 59 | + } |
| 60 | + }, [activeQuickStartID, allQuickStartStates, setAllQuickStartStates]); |
| 61 | + |
45 | 62 | const status = activeQuickStartState?.status as QuickStartStatus; |
46 | 63 | const taskNumber = activeQuickStartState?.taskNumber as number; |
47 | 64 | const allTaskStatuses = tasks.map( |
|
0 commit comments