<commit_before>import React from 'react'
import ReactDOMFactories from 'react-dom-factories'
import { CFMGoogleDriveProviderOptions } from '../app-options'
import { CloudFileManagerClient } from '../client'
import { createReactClassFactory } from '../create-react-factory'
import tr  from '../utils/translate'
import {
  cloudContentFactory, CloudMetadata, ProviderCloseCallback, ProviderInterface,
  ProviderListCallback, ProviderLoadCallback, ProviderRemoveCallback, ProviderSaveCallback
}  from './provider-interface'

enum ELoadState {
  notLoaded = "not-loaded",
  loaded = "loaded",
  errored = "errored"
}

const {div, button, span} = ReactDOMFactories
const GoogleDriveAuthorizationDialog = createReactClassFactory({
  displayName: 'GoogleDriveAuthorizationDialog',

  getInitialState() {
    return {gapiLoadState: this.props.provider.gapiLoadState}
  },

  // See comments in AuthorizeMixin for detailed description of the issues here.
  // The short version is that we need to maintain synchronized instance variable
  // and state to track authorization status while avoiding calling setState on
  // unmounted components, which doesn't work and triggers a React warning.

  UNSAFE_componentWillMount() {
    return this.props.provider._waitForGAPILoad().then(() => {
      if (this._isMounted) {
        return this.setState({gapiLoadState: this.props.provider.gapiLoadState})
      }
    })
  },

  componentDidMount() {
    this._isMounted = true
    this.setState({gapiLoadState: this.props.provider.gapiLoadState})
  },

  componentWillUnmount() {
    return this._isMounted = false
  },

  authenticate() {
    return this.props.provider.authorize(GoogleDriveProvider.SHOW_POPUP)
  },

  render() {
    const messageMap: Record<ELoadState, React.ReactChild> = {<commit_msg>Support response to initial authorization state in the various file dialogs.<commit_after>import React from 'react'
import ReactDOMFactories from 'react-dom-factories'
import { CFMGoogleDriveProviderOptions } from '../app-options'
import { CloudFileManagerClient } from '../client'
import { createReactClassFactory } from '../create-react-factory'
import tr  from '../utils/translate'
import {
  cloudContentFactory, CloudMetadata, ProviderCloseCallback, ProviderInterface,
  ProviderListCallback, ProviderLoadCallback, ProviderRemoveCallback, ProviderSaveCallback
}  from './provider-interface'

enum ELoadState {
  notLoaded = "not-loaded",
  loaded = "loaded",
  errored = "errored"
}

const {div, button, span} = ReactDOMFactories
const GoogleDriveAuthorizationDialog = createReactClassFactory({
  displayName: 'GoogleDriveAuthorizationDialog',

  getInitialState() {
    return {gapiLoadState: this.props.provider.gapiLoadState}
  },

  // See comments in AuthorizeMixin for detailed description of the issues here.
  // The short version is that we need to maintain synchronized instance variable
  // and state to track authorization status while avoiding calling setState on
  // unmounted components, which doesn't work and triggers a React warning.

  UNSAFE_componentWillMount() {
    return this.props.provider._waitForGAPILoad().then(() => {
      if (this._isMounted) {
        return this.setState({gapiLoadState: this.props.provider.gapiLoadState})
      }
    })
  },

  componentDidMount() {
    this._isMounted = true
    this.setState({gapiLoadState: this.props.provider.gapiLoadState})
  },

  componentWillUnmount() {
    return this._isMounted = false
  },

  authenticate() {
    // we rely on the fact that the prior call to authorized has set the callback
    // we need here
    return this.props.provider.authorize(this.props.provider.authCallback)
  },

  render() {
    const messageMap: Record<ELoadState, React.ReactChild> = {
{'fraction_non_alphanumeric': 0.0973592958122166, 'fraction_numerical': 0.0, 'mean_word_length': 4.403458213256484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206533', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1023, 'n_words': 280}