<commit_before>import React, { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet'
import { Redirect, Link } from 'react-router-dom'
import {
  Navbar,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  DropdownToggle,
  DropdownMenu,
  DropdownItem,
  Dropdown
} from 'reactstrap'
import { useStaticResolver, useQuery, useCommand } from 'resolve-react-hooks'
import { UserProfile } from '../../common/types'
import Loading from './Loading'

const UserInfo = (props: { user: UserProfile | string | null }): any => {
  // const [deleted, setDeleted] = useState(false)
  const [state, setState] = useState({
    deleted: null,
    gatheringStarted: null,
    open: false
  })
  const { deleted, gatheringStarted, open } = state
  const { user } = props
  const toggle = () => {
    setState({ ...state, open: !open })
  }
  const deleteMe = useCommand(
    {
      type: 'delete',
      aggregateId: typeof user === 'object' && user !== null ? user.id : null,
      aggregateName: 'user-profile',
      payload: {}
    },
    (error, result) => {
      if (error == null) {
        setState({ ...state, deleted: true })
      }
    },
    [user]
  ) as () => void

  const gatherPersonalData = useCommand(
    {
      type: 'gatherPersonalData',
      aggregateId: typeof user === 'object' && user !== null ? user.id : null,
      aggregateName: 'user-profile',
      payload: {}
    },
    (error, result) => {
      if (error == null) {
        setState({ ...state, gatheringStarted: true, open: true })
      }
    },
    [user]
  ) as () => void

  if (typeof user === 'string') {
    return <Loading />
  }

  if (user === null) {
    return null
  }

  if (deleted) {
    return <Redirect to="/" />
  }

  const { archive = null } = user
  const { id: archiveId } = archive || {}

  const archiveItem =
    gatheringStarted || archiveId === null ? (
      <DropdownItem disabled>Being gathered now...</DropdownItem>
    ) : (
      <DropdownItem>
        Download <span>#{archiveId}</span>
      </DropdownItem>
    )

  const archiveSubmenu = archive ? (
    <React.Fragment>
      <DropdownItem divider />
      <DropdownItem header>Archive</DropdownItem>
      {archiveItem}
    </React.Fragment>
  ) : null

  return (
    <React.Fragment>
      <Dropdown isOpen={open} nav inNavbar toggle={toggle}>
        <DropdownToggle nav caret>
          {user.nickname}
        </DropdownToggle>
        <DropdownMenu right>
          <DropdownItem tag={Link} to="/profile">
            Update my profile
          </DropdownItem>
          <DropdownItem onClick={gatherPersonalData}>
            Gather my personal data
          </DropdownItem>
          <DropdownItem onClick={deleteMe}>Delete my profile</DropdownItem>
          {archiveSubmenu}
        </DropdownMenu>
      </Dropdown>
    </React.Fragment>
  )
}

const Header = () => {
  const asset = useStaticResolver()

  const [user, setUser] = useState<UserProfile | string | null>('unknown')
  const getUser = useQuery(
    {
      name: 'user-profiles',<commit_msg>minor ui fix<commit_after>import React, { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet'
import { Redirect, Link } from 'react-router-dom'
import {
  Navbar,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  DropdownToggle,
  DropdownMenu,
  DropdownItem,
  Dropdown
} from 'reactstrap'
import { useStaticResolver, useQuery, useCommand } from 'resolve-react-hooks'
import { UserProfile } from '../../common/types'
import Loading from './Loading'

const UserInfo = (props: { user: UserProfile | string | null }): any => {
  // const [deleted, setDeleted] = useState(false)
  const [state, setState] = useState({
    deleted: null,
    gatheringStarted: null,
    open: false
  })
  const { deleted, gatheringStarted, open } = state
  const { user } = props
  const toggle = () => {
    setState({ ...state, open: !open })
  }
  const deleteMe = useCommand(
    {
      type: 'delete',
      aggregateId: typeof user === 'object' && user !== null ? user.id : null,
      aggregateName: 'user-profile',
      payload: {}
    },
    (error, result) => {
      if (error == null) {
        setState({ ...state, deleted: true })
      }
    },
    [user]
  ) as () => void

  const gatherPersonalData = useCommand(
    {
      type: 'gatherPersonalData',
      aggregateId: typeof user === 'object' && user !== null ? user.id : null,
      aggregateName: 'user-profile',
      payload: {}
    },
    (error, result) => {
      if (error == null) {
        setState({ ...state, gatheringStarted: true, open: true })
      }
    },
    [user]
  ) as () => void

  if (typeof user === 'string') {
    return <Loading />
  }

  if (user === null) {
    return null
  }

  if (deleted) {
    return <Redirect to="/" />
  }

  const { archive = null } = user
  const { id: archiveId } = archive || {}

  const archiveItem =
    gatheringStarted || archiveId === null ? (
      <DropdownItem disabled>Being gathered now...</DropdownItem>
    ) : (
      <DropdownItem>
        Download <span>#{archiveId}</span>
      </DropdownItem>
    )

  const archiveSubmenu =
    archive || gatheringStarted ? (
      <React.Fragment>
        <DropdownItem divider />
        <DropdownItem header>Archive</DropdownItem>
        {archiveItem}
      </React.Fragment>
    ) : null

  return (
    <React.Fragment>
      <Dropdown isOpen={open} nav inNavbar toggle={toggle}>
        <DropdownToggle nav caret>
          {user.nickname}
        </DropdownToggle>
        <DropdownMenu right>
          <DropdownItem tag={Link} to="/profile">
            Update my profile
          </DropdownItem>
          <DropdownItem onClick={gatherPersonalData}>
            Gather my personal data
          </DropdownItem>
          <DropdownItem onClick={deleteMe}>Delete my profile</DropdownItem>
          {archiveSubmenu}
        </DropdownMenu>
      </Dropdown>
    </React.Fragment>
  )
}

const Header = () => {
  const asset = useStaticResolver()

  const [user, setUser] = useState<UserProfile | string | null>('unknown')
  const getUser = useQuery(
    {
      name: 'user-profiles',
{'fraction_non_alphanumeric': 0.1410612244897959, 'fraction_numerical': 0.0, 'mean_word_length': 2.4866249288560045, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3743734', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1890, 'n_words': 472}