-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgraded frontend-build version #593
Changes from 12 commits
c8e76ba
86e15db
9f917d8
d5dd932
698d52f
1914ac9
67bc7d6
fbe59f5
656ef07
e478a32
d31f1e3
b0a3664
b9f3e23
8c1b8b4
8f6bcfe
9e4a052
5dee7ad
3063711
3f4a0ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import React, { createContext, useState } from 'react'; | ||
import React, { | ||
createContext, useCallback, useState, useMemo, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const ToastsContext = createContext(); | ||
|
||
const ToastsProvider = ({ children }) => { | ||
function ToastsProvider({ children }) { | ||
const [toasts, setToasts] = useState([]); | ||
|
||
const addToast = (message) => { | ||
|
@@ -16,21 +18,24 @@ const ToastsProvider = ({ children }) => { | |
]); | ||
}; | ||
|
||
const removeToast = (id) => { | ||
const removeToast = useCallback((id) => { | ||
const index = toasts.findIndex(toast => toast.id === id); | ||
setToasts((prevToasts) => { | ||
const newToasts = [...prevToasts]; | ||
newToasts.splice(index, 1); | ||
return newToasts; | ||
}); | ||
}; | ||
}, [toasts]); | ||
|
||
return ( | ||
<ToastsContext.Provider value={{ toasts, addToast, removeToast }}> | ||
<ToastsContext.Provider value={ | ||
useMemo(() => ({ toasts, addToast, removeToast }), [removeToast, toasts]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
> | ||
{children} | ||
</ToastsContext.Provider> | ||
); | ||
}; | ||
} | ||
|
||
ToastsProvider.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { Container } from '@edx/paragon'; | |
import { LoadingSpinner } from '../loading-spinner'; | ||
import { loginRefresh } from '../../utils/common'; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [curious] Why are we disabling this ESLint rule here versus defining the prop type for |
||
export default function LoginRefresh({ children }) { | ||
const { authenticatedUser } = useContext(AppContext); | ||
const { roles } = authenticatedUser; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { render, act } from '@testing-library/react'; | ||
import { AppContext } from '@edx/frontend-platform/react'; | ||
|
@@ -9,19 +9,23 @@ import * as utils from '../../utils/common'; | |
jest.mock('../../utils/common'); | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const LoginRefreshWithContext = ({ roles = [] }) => ( | ||
<AppContext.Provider value={{ | ||
authenticatedUser: { | ||
userId: 1, | ||
roles, | ||
}, | ||
}} | ||
> | ||
<LoginRefresh> | ||
<div>Hello!</div> | ||
</LoginRefresh> | ||
</AppContext.Provider> | ||
); /* eslint-enable react/prop-types */ | ||
function LoginRefreshWithContext({ roles = [] }) { | ||
return ( | ||
<AppContext.Provider value={ | ||
useMemo(() => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call |
||
authenticatedUser: { | ||
userId: 1, | ||
roles, | ||
}, | ||
}), [roles]) | ||
} | ||
> | ||
<LoginRefresh> | ||
<div>Hello!</div> | ||
</LoginRefresh> | ||
</AppContext.Provider> | ||
); | ||
} /* eslint-enable react/prop-types */ | ||
|
||
describe('<LoginRefresh />', () => { | ||
it('should call loginRefresh if the user has no roles', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's keep the version pinned like our other dependencies are.