Skip to content

Commit

Permalink
fix context api
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler committed Jul 7, 2021
1 parent b0604be commit 3c57e56
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"serve": "serve public"
},
"dependencies": {
"@patternfly/quickstarts": "1.0.0-rc.28",
"@patternfly/quickstarts": "1.0.0-rc.29",
"@patternfly/react-core": "^4.101.3",
"asciidoctor": "^2.2.1",
"react": "^16.14.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const App: React.FC<AppProps> = ({ children, showCardFooters }) => {
...resourceBundle,
"Start": "Let's go!",
"Continue": "Resume",
"Restart": "Start over"
"Restart": "Start over",
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patternfly/quickstarts",
"version": "1.0.0-rc.28",
"version": "1.0.0-rc.29",
"description": "PatternFly quick starts",
"files": [
"dist"
Expand Down
50 changes: 29 additions & 21 deletions packages/module/src/utils/quick-start-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export type FooterProps = {

export type QuickStartContextValues = {
allQuickStarts?: QuickStart[];
activeQuickStartID?: string;
allQuickStartStates?: AllQuickStartStates;
activeQuickStartState?: QuickStartState;
setAllQuickStarts?: React.Dispatch<React.SetStateAction<QuickStart[]>>;
activeQuickStartID?: string;
setActiveQuickStartID?: React.Dispatch<React.SetStateAction<string>>;
allQuickStartStates?: AllQuickStartStates;
setAllQuickStartStates?: React.Dispatch<React.SetStateAction<AllQuickStartStates>>;
activeQuickStartState?: QuickStartState;
setActiveQuickStart?: (quickStartId: string, totalTasks?: number) => void;
startQuickStart?: (quickStartId: string, totalTasks?: number) => void;
restartQuickStart?: (quickStartId: string, totalTasks: number) => void;
Expand All @@ -48,8 +48,8 @@ export type QuickStartContextValues = {
renderExtension?: (docContext: HTMLDocument, rootSelector: string) => React.ReactNode;
};
resourceBundle?: any;
setResourceBundle?: any;
getResource?: any;
setResourceBundle?: any;
language?: string;
setLanguage?: any;
filter?: {
Expand All @@ -68,14 +68,13 @@ export const QuickStartContextDefaults = {
allQuickStartStates: {},
activeQuickStartState: {},
setAllQuickStarts: () => {},
setActiveQuickStart: () => {},
startQuickStart: () => {},
restartQuickStart: () => {},
resourceBundle: en,
getResource: () => '',
language: 'en',
useQueryParams: true,
setFilter: () => {},
footer: null,
markdown: null
};
export const QuickStartContext = createContext<QuickStartContextValues>(QuickStartContextDefaults);

Expand Down Expand Up @@ -104,13 +103,15 @@ export const useValuesForQuickStartContext = (
useQueryParams,
allQuickStartStates,
allQuickStarts,
footer,
markdown
} = combinedValue;
const [quickStarts, setQuickStarts] = React.useState(combinedValue.allQuickStarts);
const [resourceBundle, setResourceBundle] = React.useState({
...en,
...combinedValue.resourceBundle,
});
const [language, setLanguage] = React.useState(combinedValue.language || 'en');
const [language, setLanguage] = React.useState(combinedValue.language);
const changeResourceBundle = (resourceBundle: any, language?: string) => {
language && setLanguage(language);
setResourceBundle({
Expand Down Expand Up @@ -374,31 +375,38 @@ export const useValuesForQuickStartContext = (
);

return {
...combinedValue,
allQuickStarts: quickStarts,
setAllQuickStarts: updateAllQuickStarts,
setAllQuickStarts: updateAllQuickStarts, // revisit if this should be in public context API
activeQuickStartID,
setActiveQuickStartID,
allQuickStartStates,
setAllQuickStartStates,
activeQuickStartState,
setActiveQuickStart: value.setActiveQuickStart || setActiveQuickStart,
startQuickStart: value.startQuickStart || startQuickStart,
restartQuickStart: value.restartQuickStart || restartQuickStart,
nextStep: value.nextStep || nextStep,
previousStep: value.previousStep || previousStep,
setQuickStartTaskNumber, // revisit if this should be in public context API
setQuickStartTaskStatus, // revisit if this should be in public context API
getQuickStartForId,
footer,
useQueryParams,
markdown,
resourceBundle,
getResource: findResource, // revisit if this should be in public context API
setResourceBundle: changeResourceBundle,
language,
setLanguage,
getResource: findResource,
// revisit if this should be in public context API
filter: {
keyword: filterKeyword,
status: {
statusTypes,
statusFilters,
},
},
setFilter,
activeQuickStartState,
setActiveQuickStart,
startQuickStart,
restartQuickStart,
nextStep,
previousStep,
setQuickStartTaskNumber,
setQuickStartTaskStatus,
getQuickStartForId,
setFilter, // revisit if this should be in public context API
};
};

Expand Down

0 comments on commit 3c57e56

Please sign in to comment.