import {useCallback, useState} from 'react' import {LayoutAnimation, View} from 'react-native' import {Pressable} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useFocusEffect} from '@react-navigation/native' import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo' import { type CommonNavigatorParams, type NativeStackScreenProps, } from '#/lib/routes/types' import {getEntries} from '#/logger/logDump' import {useTickEveryMinute} from '#/state/shell' import {useSetMinimalShellMode} from '#/state/shell' import {atoms as a, useTheme} from '#/alf' import { ChevronBottom_Stroke2_Corner0_Rounded as ChevronBottomIcon, ChevronTop_Stroke2_Corner0_Rounded as ChevronTopIcon, } from '#/components/icons/Chevron' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfoIcon} from '#/components/icons/CircleInfo' import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning' import * as Layout from '#/components/Layout' import {Text} from '#/components/Typography' export function LogScreen({}: NativeStackScreenProps< CommonNavigatorParams, 'Log' >) { const t = useTheme() const {_} = useLingui() const setMinimalShellMode = useSetMinimalShellMode() const [expanded, setExpanded] = useState([]) const timeAgo = useGetTimeAgo() const tick = useTickEveryMinute() useFocusEffect( useCallback(() => { setMinimalShellMode(false) }, [setMinimalShellMode]), ) const toggler = (id: string) => () => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) if (expanded.includes(id)) { setExpanded(expanded.filter(v => v !== id)) } else { setExpanded([...expanded, id]) } } return ( System log {getEntries() .slice(0) .map(entry => { return ( {entry.level === 'warn' || entry.level === 'error' ? ( ) : ( )} {String(entry.message)} {entry.metadata && Object.keys(entry.metadata).length > 0 && (expanded.includes(entry.id) ? ( ) : ( ))} {timeAgo(entry.timestamp, tick)} {expanded.includes(entry.id) && ( {JSON.stringify(entry.metadata, null, 2)} )} ) })} ) }