<commit_before>// @flow
import * as I from 'immutable'
import {
  compose,
  connect,
  lifecycle,
  type Dispatch,
  type TypedState,
  setDisplayName,
} from '../../util/container'
import * as Constants from '../../constants/fs'
import * as FsGen from '../../actions/fs-gen'
import * as React from 'react'
import * as Types from '../../constants/types/fs'
import DefaultView from './default-view-container'
import ImageView from './image-view'
import TextView from './text-view'
import AVView from './av-view'
import PdfView from './pdf-view'
import {Box, Text} from '../../common-adapters'
import {globalStyles, globalColors, platformStyles} from '../../styles'
import {isAndroid} from '../../constants/platform'

type Props = {
  path: Types.Path,
  routePath: I.List<string>,
}

const mapStateToProps = (state: TypedState, {path}: Props) => {
  const _pathItem = state.fs.pathItems.get(path) || Constants.makeFile()
  return {
    _serverInfo: state.fs.localHTTPServerInfo,
    mimeType: _pathItem.type === 'file' ? _pathItem.mimeType : '',
    isSymlink: _pathItem.type === 'symlink',
  }
}

const mapDispatchToProps = (dispatch: Dispatch, {path}: Props) => ({
  loadMimeType: () => dispatch(FsGen.createMimeTypeLoad({path})),
})

const mergeProps = ({_serverInfo, mimeType, isSymlink}, {loadMimeType}, {path}) => ({
  url: Constants.generateFileURL(path, _serverInfo),
  mimeType,
  isSymlink,
  path,
  loadMimeType,
})

const Renderer = ({mimeType, isSymlink, url, path, routePath, loadMimeType}) => {
  if (isSymlink) {
    return <DefaultView path={path} routePath={routePath} />
  }

  if (mimeType === '') {
    return (
      <Box style={stylesLoadingContainer}>
        <Text type="BodySmall" style={stylesLoadingText}>
          Loading ...
        </Text>
      </Box>
    )
  }

  switch (Constants.viewTypeFromMimeType(mimeType)) {
    case 'default':
      return <DefaultView path={path} routePath={routePath} />
    case 'text':
      return <TextView url={url} routePath={routePath} />
    case 'image':
      return <ImageView url={url} routePath={routePath} />
    case 'av':
      return <AVView url={url} routePath={routePath} />
    case 'pdf':
      return isAndroid ? ( // Android WebView doesn't support PDF. Come on Android!
        <DefaultView path={path} routePath={routePath} />
      ) : (
        <PdfView url={url} routePath={routePath} />
      )
    default:
      return <Text type="BodyError">This shouldn't happen</Text><commit_msg>[DESKTOP-6888] fs: Disable PDF viewing on all platforms. (#12100)<commit_after>// @flow
import * as I from 'immutable'
import {
  compose,
  connect,
  lifecycle,
  type Dispatch,
  type TypedState,
  setDisplayName,
} from '../../util/container'
import * as Constants from '../../constants/fs'
import * as FsGen from '../../actions/fs-gen'
import * as React from 'react'
import * as Types from '../../constants/types/fs'
import DefaultView from './default-view-container'
import ImageView from './image-view'
import TextView from './text-view'
import AVView from './av-view'
import {Box, Text} from '../../common-adapters'
import {globalStyles, globalColors, platformStyles} from '../../styles'

type Props = {
  path: Types.Path,
  routePath: I.List<string>,
}

const mapStateToProps = (state: TypedState, {path}: Props) => {
  const _pathItem = state.fs.pathItems.get(path) || Constants.makeFile()
  return {
    _serverInfo: state.fs.localHTTPServerInfo,
    mimeType: _pathItem.type === 'file' ? _pathItem.mimeType : '',
    isSymlink: _pathItem.type === 'symlink',
  }
}

const mapDispatchToProps = (dispatch: Dispatch, {path}: Props) => ({
  loadMimeType: () => dispatch(FsGen.createMimeTypeLoad({path})),
})

const mergeProps = ({_serverInfo, mimeType, isSymlink}, {loadMimeType}, {path}) => ({
  url: Constants.generateFileURL(path, _serverInfo),
  mimeType,
  isSymlink,
  path,
  loadMimeType,
})

const Renderer = ({mimeType, isSymlink, url, path, routePath, loadMimeType}) => {
  if (isSymlink) {
    return <DefaultView path={path} routePath={routePath} />
  }

  if (mimeType === '') {
    return (
      <Box style={stylesLoadingContainer}>
        <Text type="BodySmall" style={stylesLoadingText}>
          Loading ...
        </Text>
      </Box>
    )
  }

  switch (Constants.viewTypeFromMimeType(mimeType)) {
    case 'default':
      return <DefaultView path={path} routePath={routePath} />
    case 'text':
      return <TextView url={url} routePath={routePath} />
    case 'image':
      return <ImageView url={url} routePath={routePath} />
    case 'av':
      return <AVView url={url} routePath={routePath} />
    case 'pdf':
      // Security risks to links in PDF viewing. See DESKTOP-6888.
      return <DefaultView path={path} routePath={routePath} />
    default:
      return <Text type="BodyError">This shouldn't happen</Text>
{'fraction_non_alphanumeric': 0.15818858560794044, 'fraction_numerical': 0.002688172043010753, 'mean_word_length': 3.520560747663551, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 40, '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': '397811', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1550, 'n_words': 388}