@@ -30,13 +30,6 @@ function LogBoxContainer(props: Props): React.Node {
3030
3131 const logs = Array . from ( props . logs ) ;
3232
33- function getVisibleLog ( ) {
34- // TODO: currently returns the newest log but later will need to return
35- // the newest log of the highest level. For example, we want to show
36- // the latest error message even if there are newer warnings.
37- return logs [ logs . length - 1 ] ;
38- }
39-
4033 function handleInspectorDismissAll ( ) {
4134 props . onDismissAll ( ) ;
4235 }
@@ -59,8 +52,12 @@ function LogBoxContainer(props: Props): React.Node {
5952 setSelectedLog ( null ) ;
6053 }
6154
62- function handleRowPress ( index : number ) {
63- setSelectedLog ( logs . length - 1 ) ;
55+ function openLog ( log : LogBoxLog ) {
56+ let index = logs . length - 1 ;
57+ while ( index > 0 && logs [ index ] !== log ) {
58+ index -= 1 ;
59+ }
60+ setSelectedLog ( index ) ;
6461 }
6562
6663 if ( selectedLogIndex != null ) {
@@ -77,20 +74,42 @@ function LogBoxContainer(props: Props): React.Node {
7774 ) ;
7875 }
7976
80- return logs . length === 0 ? null : (
77+ if ( logs . length === 0 ) {
78+ return null ;
79+ }
80+
81+ const warnings = logs . filter ( log => log . level === 'warn' ) ;
82+ const errors = logs . filter ( log => log . level === 'error' ) ;
83+ return (
8184 < View style = { styles . list } >
82- < View style = { styles . toast } >
83- < LogBoxLogNotification
84- log = { getVisibleLog ( ) }
85- level = "warn"
86- totalLogCount = { logs . length }
87- onPressOpen = { handleRowPress }
88- onPressList = { ( ) => {
89- /* TODO: open log list */
90- } }
91- onPressDismiss = { handleInspectorDismissAll }
92- />
93- </ View >
85+ { warnings . length > 0 && (
86+ < View style = { styles . toast } >
87+ < LogBoxLogNotification
88+ log = { warnings [ warnings . length - 1 ] }
89+ level = "warn"
90+ totalLogCount = { warnings . length }
91+ onPressOpen = { ( ) => openLog ( warnings [ warnings . length - 1 ] ) }
92+ onPressList = { ( ) => {
93+ /* TODO: open log list */
94+ } }
95+ onPressDismiss = { handleInspectorDismissAll }
96+ />
97+ </ View >
98+ ) }
99+ { errors . length > 0 && (
100+ < View style = { styles . toast } >
101+ < LogBoxLogNotification
102+ log = { errors [ errors . length - 1 ] }
103+ level = "error"
104+ totalLogCount = { errors . length }
105+ onPressOpen = { ( ) => openLog ( errors [ errors . length - 1 ] ) }
106+ onPressList = { ( ) => {
107+ /* TODO: open log list */
108+ } }
109+ onPressDismiss = { handleInspectorDismissAll }
110+ />
111+ </ View >
112+ ) }
94113 < SafeAreaView style = { styles . safeArea } />
95114 </ View >
96115 ) ;
@@ -105,6 +124,7 @@ const styles = StyleSheet.create({
105124 } ,
106125 toast : {
107126 borderRadius : 8 ,
127+ marginBottom : 5 ,
108128 overflow : 'hidden' ,
109129 } ,
110130 safeArea : {
0 commit comments