openedx / openedx/frontend-platform

Implement Gatsby-friendly initialization wrapper

Open
#157 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.