<commit_before>// @flow

import * as React from 'react'
import semver from 'semver'
import pkg from '../../../package.json'
import {useSelector, useDispatch} from 'react-redux'
import {ScrollView, StyleSheet} from 'react-native'
import {NoticeView, LoadingView} from '@frogpond/notice'
import {type ReduxState} from '../../redux'
import {getEnabledTools} from '../../redux/parts/help'
import * as wifi from './wifi'
import {ToolView} from './tool'

const CUSTOM_TOOLS = [wifi]

const shouldBeShown = conf =>
	!conf.hidden &&
	(!conf.versionRange || semver.satisfies(pkg.version, conf.versionRange))

const getToolView = config => {
	let customView = CUSTOM_TOOLS.find(tool => tool.toolName === config.key)
	if (!customView) {
		return [ToolView, config]
	}
	return [customView.ToolView, config]
}

export function HelpView() {
	let tools = useSelector((state: ReduxState) => state.help?.tools || [])
	let fetching = useSelector(
		(state: ReduxState) => state.help?.fetching || false,
	)

	let dispatch = useDispatch()
	let findEnabledTools = React.useCallback(() => dispatch(getEnabledTools()), [
		dispatch,
	])

	React.useEffect(() => findEnabledTools(), [findEnabledTools])

	if (fetching) {
		return <LoadingView text="Loading…" />
	}

	let views = tools
		.filter(shouldBeShown)
		.map(getToolView)<commit_msg>fix warning from a useEffect call<commit_after>// @flow

import * as React from 'react'
import semver from 'semver'
import pkg from '../../../package.json'
import {useSelector, useDispatch} from 'react-redux'
import {ScrollView, StyleSheet} from 'react-native'
import {NoticeView, LoadingView} from '@frogpond/notice'
import {type ReduxState} from '../../redux'
import {getEnabledTools} from '../../redux/parts/help'
import * as wifi from './wifi'
import {ToolView} from './tool'

const CUSTOM_TOOLS = [wifi]

const shouldBeShown = conf =>
	!conf.hidden &&
	(!conf.versionRange || semver.satisfies(pkg.version, conf.versionRange))

const getToolView = config => {
	let customView = CUSTOM_TOOLS.find(tool => tool.toolName === config.key)
	if (!customView) {
		return [ToolView, config]
	}
	return [customView.ToolView, config]
}

export function HelpView() {
	let tools = useSelector((state: ReduxState) => state.help?.tools || [])
	let fetching = useSelector(
		(state: ReduxState) => state.help?.fetching || false,
	)

	let dispatch = useDispatch()
	let findEnabledTools = React.useCallback(() => dispatch(getEnabledTools()), [
		dispatch,
	])

	React.useEffect(() => {
		findEnabledTools()
	}, [findEnabledTools])

	if (fetching) {
		return <LoadingView text="Loading…" />
	}

	let views = tools
		.filter(shouldBeShown)
		.map(getToolView)
{'fraction_non_alphanumeric': 0.15569763068822864, 'fraction_numerical': 0.0, 'mean_word_length': 4.6, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1849545', 'n_tokens_mistral': 894, 'n_tokens_neox': 869, 'n_words': 224}