-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from openedx/mfrank/adding-skills-context
feat: added skills context
- Loading branch information
Showing
14 changed files
with
152 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { SkillsBuilderModal } from './skills-builder-modal'; | ||
import { SkillsBuilderProvider } from './skills-builder-context'; | ||
|
||
const SkillsBuilder = () => ( | ||
<SkillsBuilderProvider> | ||
<SkillsBuilderModal /> | ||
</SkillsBuilderProvider> | ||
); | ||
|
||
export default SkillsBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { | ||
SET_GOAL, | ||
} from './constants'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const setGoal = (payload) => ({ | ||
type: SET_GOAL, | ||
payload, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const SET_GOAL = 'SET_GOAL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
SET_GOAL, | ||
} from './constants'; | ||
|
||
export function skillsReducer(state, action) { | ||
switch (action.type) { | ||
case SET_GOAL: | ||
return { | ||
...state, | ||
currentGoal: action.payload, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export const skillsInitialState = { | ||
currentGoal: '', | ||
}; | ||
|
||
export default skillsReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { skillsReducer } from '../reducer'; | ||
import { | ||
SET_GOAL, | ||
} from '../constants'; | ||
|
||
describe('skillsReducer', () => { | ||
const testState = { | ||
currentGoal: '', | ||
}; | ||
|
||
it('does not remove present data when SET_GOAL action is dispatched', () => { | ||
const newSkillsPayload = 'test-goal'; | ||
const returnedState = skillsReducer(testState, { type: SET_GOAL, payload: newSkillsPayload }); | ||
const finalState = { | ||
...testState, | ||
currentGoal: 'test-goal', | ||
}; | ||
expect(returnedState).toEqual(finalState); | ||
}); | ||
}); |
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
src/skills-builder/skills-builder-context/SkillsBuilderProvider.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { createContext, useReducer, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import reducer, { skillsInitialState } from '../data/reducer'; | ||
|
||
export const SkillsBuilderContext = createContext(); | ||
|
||
export const SkillsBuilderProvider = ({ children }) => { | ||
const [state, dispatch] = useReducer(reducer, skillsInitialState); | ||
const value = useMemo(() => ([state, dispatch]), [state]); | ||
|
||
return ( | ||
<SkillsBuilderContext.Provider value={value}> | ||
{children} | ||
</SkillsBuilderContext.Provider> | ||
); | ||
}; | ||
|
||
SkillsBuilderProvider.propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { SkillsBuilderProvider, SkillsBuilderContext } from './SkillsBuilderProvider'; |
63 changes: 63 additions & 0 deletions
63
src/skills-builder/skills-builder-modal/SkillsBuilderModal.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useContext, useState } from 'react'; | ||
import { | ||
ActionRow, | ||
Button, | ||
Container, | ||
FullscreenModal, | ||
Form, | ||
} from '@edx/paragon'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { | ||
setGoal, | ||
} from '../data/actions'; | ||
import messages from './messages'; | ||
import { SkillsBuilderContext } from '../skills-builder-context'; | ||
|
||
const SkillsBuilderModal = () => { | ||
const onCloseHandle = () => { | ||
window.history.back(); | ||
}; | ||
|
||
const [state, dispatch] = useContext(SkillsBuilderContext); | ||
|
||
const [learnerGoal, setLearnerGoal] = useState(''); | ||
|
||
return ( | ||
<FullscreenModal | ||
title="Skills Builder" | ||
isOpen | ||
onClose={onCloseHandle} | ||
footerNode={( | ||
<ActionRow> | ||
<Button variant="tertiary"> | ||
<FormattedMessage {...messages.goBackButton} /> | ||
</Button> | ||
<ActionRow.Spacer /> | ||
<Button> | ||
<FormattedMessage {...messages.nextStepButton} /> | ||
</Button> | ||
</ActionRow> | ||
)} | ||
> | ||
<Container> | ||
<h3>Your current goal: {state.currentGoal}</h3> | ||
<br /> | ||
<Form.Group controlId="currentLearnerGoal"> | ||
<Form.Control | ||
type="text" | ||
floatingLabel="Goal" | ||
value={learnerGoal} | ||
onChange={(e) => setLearnerGoal(e.target.value)} | ||
/> | ||
</Form.Group> | ||
<Button | ||
onClick={() => dispatch(setGoal(learnerGoal))} | ||
> | ||
Submit | ||
</Button> | ||
</Container> | ||
</FullscreenModal> | ||
); | ||
}; | ||
|
||
export default SkillsBuilderModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as SkillsBuilderModal } from './SkillsBuilderModal'; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/skills/test/SkillsBuilder.test.jsx → ...kills-builder/test/SkillsBuilder.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.