import React from 'react' import {StyleSheet, TouchableOpacity, View} from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useFocusEffect} from '@react-navigation/native' import {usePalette} from '#/lib/hooks/usePalette' import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo' import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types' import {s} from '#/lib/styles' import {getEntries} from '#/logger/logDump' import {useTickEveryMinute} from '#/state/shell' import {useSetMinimalShellMode} from '#/state/shell' import {Text} from '#/view/com/util/text/Text' import {ViewHeader} from '#/view/com/util/ViewHeader' import {ScrollView} from '#/view/com/util/Views' import * as Layout from '#/components/Layout' export function LogScreen({}: NativeStackScreenProps< CommonNavigatorParams, 'Log' >) { const pal = usePalette('default') const {_} = useLingui() const setMinimalShellMode = useSetMinimalShellMode() const [expanded, setExpanded] = React.useState([]) const timeAgo = useGetTimeAgo() const tick = useTickEveryMinute() useFocusEffect( React.useCallback(() => { setMinimalShellMode(false) }, [setMinimalShellMode]), ) const toggler = (id: string) => () => { if (expanded.includes(id)) { setExpanded(expanded.filter(v => v !== id)) } else { setExpanded([...expanded, id]) } } return ( {getEntries() .slice(0) .map(entry => { return ( {entry.level === 'debug' ? ( ) : ( )} {String(entry.message)} {entry.metadata && Object.keys(entry.metadata).length ? ( ) : undefined} {timeAgo(entry.timestamp, tick)} {expanded.includes(entry.id) ? ( {JSON.stringify(entry.metadata, null, 2)} ) : undefined} ) })} ) } const styles = StyleSheet.create({ entry: { flexDirection: 'row', borderTopWidth: 1, paddingVertical: 10, paddingHorizontal: 6, }, summary: { flex: 1, }, ts: { width: 40, }, details: { paddingVertical: 10, paddingHorizontal: 6, }, })