From 3810b29fb6f6bf217da93e3510d9ebad851f7f11 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 25 Aug 2025 19:25:02 +0300 Subject: ALF log screen (#8845) --- src/screens/Log.tsx | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/screens/Log.tsx (limited to 'src/screens/Log.tsx') diff --git a/src/screens/Log.tsx b/src/screens/Log.tsx new file mode 100644 index 000000000..2dd7fe84c --- /dev/null +++ b/src/screens/Log.tsx @@ -0,0 +1,128 @@ +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)} + + + )} + + ) + })} + + + ) +} -- cgit 1.4.1