openedx / openedx/frontend-platform
Implement Gatsby-friendly initialization wrapper
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 39
- Forks
- 91
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
import React, { useEffect, useState } from 'react';
import { Provider } from 'react-redux';
import 'regenerator-runtime/runtime';
import { AppProvider } from '@edx/frontend-platform/react';
import {
configure as configureAuth,
AxiosJwtAuthService,
getAuthenticatedHttpClient,
fetchAuthenticatedUser
} from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform/config';
import {
configure as configureLogging,
getLoggingService,
NewRelicLoggingService,
} from '@edx/frontend-platform/logging';
import {
configure as configureAnalytics,
SegmentAnalyticsService
} from '@edx/frontend-platform/analytics';
import {
configure as configureI18n,
} from '@edx/frontend-platform/i18n'
import store from './src/store';
// eslint-disable-next-line react/display-name,react/prop-types
export default ({ children }) => {
const [ready, setReady] = useState(false);
useEffect(() => {
configureLogging(NewRelicLoggingService, {
config: getConfig(),
});
configureAuth(AxiosJwtAuthService, {
loggingService: getLoggingService(),
config: getConfig(),
});
// Analytics
configureAnalytics(SegmentAnalyticsService, {
config: getConfig(),
loggingService: getLoggingService(),
httpClient: getAuthenticatedHttpClient(),
});
// Internationalization
configureI18n({
messages: {},
config: getConfig(),
loggingService: getLoggingService(),
});
fetchAuthenticatedUser().then(() => {
setReady(true);
})
}, []);
if (!ready) {
return null;
}
return (
<AppProvider store={store}>{children}</AppProvider>
);
}```
This class, when used in `wrapRootElement` allows for basic usage of frontend-platform services in a Gatsby-based project. The initialize function can't be used because it's async.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Gatsby wrapRootElement entry point and compare the requested wrapper with the existing async initialize function mentioned in the issue. The work is done when the wrapper configures logging, authentication, analytics, and internationalization, waits for fetchAuthenticatedUser, and then renders AppProvider with the store and children.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- authentication, frontend, internationalization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100