<commit_before>import {createSelector} from 'reselect'
import {
  parseQueryParams,
} from 'util/query_params'
import lbryuri from 'lbryuri'

export const _selectState = state => state.app || {}

export const selectIsLoaded = createSelector(
  _selectState,
  (state) => state.isLoaded
)

export const selectCurrentPath = createSelector(
  _selectState,
  (state) => state.currentPath
)

export const selectCurrentPage = createSelector(
  selectCurrentPath,
  (path) => {
    return path.replace(/^\//, '').split('?')[0]
  }
)

export const selectCurrentParams = createSelector(
  selectCurrentPath,
  (path) => {
    if (path === undefined) return {}
    if (!path.match(/\?/)) return {}

    return parseQueryParams(path.split('?')[1])
  }
)

export const selectPageTitle = createSelector(
  selectCurrentPage,
  selectCurrentParams,
  (page, params) => {
    switch (page) {
      case 'search':
        return params.query ? `Search results for ${params.query}` : 'Search'
      case 'settings':
        return 'Settings'
      case 'help':
        return 'Help'
      case 'report':
        return 'Report'
      case 'wallet':
      case 'send':
      case 'receive':
      case 'rewards':
        return page.charAt(0).toUpperCase() + page.slice(1)
      case 'show':
        return lbryuri.normalize(params.uri)
      case 'downloaded':
        return 'Downloads & Purchases'
      case 'published':
        return 'Publishes'
      case 'start':
        return 'Start'
      case 'publish':
        return 'Publish'
      case 'help':
        return 'Help'
      case 'developer':
        return 'Developer'
      case 'discover':
        return 'Home'
      default:
        return '';
    }
  }
)

export const selectPlatform = createSelector(
  _selectState,
  (state) => state.platform
)

export const selectUpdateUrl = createSelector(
  selectPlatform,
  (platform) => {
    switch (platform) {
      case 'darwin':
        return 'https://lbry.io/get/lbry.dmg';
      case 'linux':
        return 'https://lbry.io/get/lbry.deb';
      case 'win32':
        return 'https://lbry.io/get/lbry.exe';
      default:
        throw 'Unknown platform';
    }
  }
)

export const selectVersion = createSelector(
  _selectState,
  (state) => {
    return state.version
  }
)

export const selectUpgradeFilename = createSelector(
  selectPlatform,
  selectVersion,
  (platform, version) => {
    switch (platform) {
      case 'darwin':
        return `LBRY-${version}.dmg`;
      case 'linux':
        return `LBRY_${version}_amd64.deb`;
      case 'win32':
        return `LBRY.Setup.${version}.exe`;
      default:
        throw 'Unknown platform';
    }
  }
)

export const selectCurrentModal = createSelector(
  _selectState,
  (state) => state.modal
)<commit_msg>Fix upgrade filenames on Mac and Windows<commit_after>import {createSelector} from 'reselect'
import {
  parseQueryParams,
} from 'util/query_params'
import lbryuri from 'lbryuri'

export const _selectState = state => state.app || {}

export const selectIsLoaded = createSelector(
  _selectState,
  (state) => state.isLoaded
)

export const selectCurrentPath = createSelector(
  _selectState,
  (state) => state.currentPath
)

export const selectCurrentPage = createSelector(
  selectCurrentPath,
  (path) => {
    return path.replace(/^\//, '').split('?')[0]
  }
)

export const selectCurrentParams = createSelector(
  selectCurrentPath,
  (path) => {
    if (path === undefined) return {}
    if (!path.match(/\?/)) return {}

    return parseQueryParams(path.split('?')[1])
  }
)

export const selectPageTitle = createSelector(
  selectCurrentPage,
  selectCurrentParams,
  (page, params) => {
    switch (page) {
      case 'search':
        return params.query ? `Search results for ${params.query}` : 'Search'
      case 'settings':
        return 'Settings'
      case 'help':
        return 'Help'
      case 'report':
        return 'Report'
      case 'wallet':
      case 'send':
      case 'receive':
      case 'rewards':
        return page.charAt(0).toUpperCase() + page.slice(1)
      case 'show':
        return lbryuri.normalize(params.uri)
      case 'downloaded':
        return 'Downloads & Purchases'
      case 'published':
        return 'Publishes'
      case 'start':
        return 'Start'
      case 'publish':
        return 'Publish'
      case 'help':
        return 'Help'
      case 'developer':
        return 'Developer'
      case 'discover':
        return 'Home'
      default:
        return '';
    }
  }
)

export const selectPlatform = createSelector(
  _selectState,
  (state) => state.platform
)

export const selectUpdateUrl = createSelector(
  selectPlatform,
  (platform) => {
    switch (platform) {
      case 'darwin':
        return 'https://lbry.io/get/lbry.dmg';
      case 'linux':
        return 'https://lbry.io/get/lbry.deb';
      case 'win32':
        return 'https://lbry.io/get/lbry.exe';
      default:
        throw 'Unknown platform';
    }
  }
)

export const selectVersion = createSelector(
  _selectState,
  (state) => {
    return state.version
  }
)

export const selectUpgradeFilename = createSelector(
  selectPlatform,
  selectVersion,
  (platform, version) => {
    switch (platform) {
      case 'darwin':
        return `LBRY_${version}.dmg`;
      case 'linux':
        return `LBRY_${version}_amd64.deb`;
      case 'win32':
        return `LBRY_${version}.exe`;
      default:
        throw 'Unknown platform';
    }
  }
)

export const selectCurrentModal = createSelector(
  _selectState,
  (state) => state.modal
)
{'fraction_non_alphanumeric': 0.12951320280222742, 'fraction_numerical': 0.0035925992455541583, 'mean_word_length': 2.6825396825396823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6307752', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1713, 'n_words': 414}