2022-01-29 11:10:04 +00:00
//
// C h a t P r e v i e w V i e w . s w i f t
// S i m p l e X
//
// C r e a t e d b y E v g e n y P o b e r e z k i n o n 2 8 / 0 1 / 2 0 2 2 .
// C o p y r i g h t © 2 0 2 2 S i m p l e X C h a t . A l l r i g h t s r e s e r v e d .
//
import SwiftUI
struct ChatPreviewView : View {
2022-02-02 12:51:39 +00:00
@ ObservedObject var chat : Chat
2022-01-29 11:10:04 +00:00
var body : some View {
2022-02-02 12:51:39 +00:00
let cItem = chat . chatItems . last
2022-01-31 21:28:07 +00:00
return VStack ( spacing : 4 ) {
HStack ( alignment : . top ) {
2022-02-02 12:51:39 +00:00
Text ( chat . chatInfo . localDisplayName )
2022-01-31 21:28:07 +00:00
. font ( . title3 )
. fontWeight ( . bold )
. padding ( . leading , 8 )
. padding ( . top , 4 )
. frame ( maxHeight : . infinity , alignment : . topLeading )
Spacer ( )
2022-02-02 12:51:39 +00:00
if let cItem = cItem {
Text ( getDateFormatter ( ) . string ( from : cItem . meta . itemTs ) )
2022-01-31 21:28:07 +00:00
. font ( . subheadline )
. padding ( . trailing , 8 )
. padding ( . top , 4 )
. frame ( minWidth : 60 , alignment : . trailing )
. foregroundColor ( . secondary )
}
}
2022-02-02 12:51:39 +00:00
if let cItem = cItem {
Text ( cItem . content . text )
2022-01-31 21:28:07 +00:00
. frame ( minWidth : 0 , maxWidth : . infinity , minHeight : 44 , maxHeight : 44 , alignment : . topLeading )
. padding ( [ . leading , . trailing ] , 8 )
. padding ( . bottom , 4 )
. padding ( . top , 1 )
}
2022-02-01 17:34:06 +00:00
// e l s e i f c a s e l e t . d i r e c t ( c o n t a c t ) = c h a t P r e v i e w . c h a t I n f o , ! c o n t a c t . c o n n e c t e d {
// T e x t ( " C o n n e c t i n g . . . " )
// . f r a m e ( m i n W i d t h : 0 , m a x W i d t h : . i n f i n i t y , m i n H e i g h t : 4 4 , m a x H e i g h t : 4 4 , a l i g n m e n t : . t o p L e a d i n g )
// . p a d d i n g ( [ . l e a d i n g , . t r a i l i n g ] , 8 )
// . p a d d i n g ( . b o t t o m , 4 )
// . p a d d i n g ( . t o p , 1 )
// }
2022-01-31 21:28:07 +00:00
}
2022-01-29 11:10:04 +00:00
}
}
struct ChatPreviewView_Previews : PreviewProvider {
static var previews : some View {
2022-01-30 00:35:20 +04:00
Group {
2022-02-02 12:51:39 +00:00
ChatPreviewView ( chat : Chat (
2022-01-31 21:28:07 +00:00
chatInfo : sampleDirectChatInfo ,
chatItems : [ ]
) )
2022-02-02 12:51:39 +00:00
ChatPreviewView ( chat : Chat (
2022-01-31 21:28:07 +00:00
chatInfo : sampleDirectChatInfo ,
chatItems : [ chatItemSample ( 1 , . directSnd , Date . now , " hello " ) ]
) )
2022-02-02 12:51:39 +00:00
ChatPreviewView ( chat : Chat (
2022-01-31 21:28:07 +00:00
chatInfo : sampleGroupChatInfo ,
chatItems : [ chatItemSample ( 1 , . directSnd , Date . now , " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. " ) ]
) )
2022-01-30 00:35:20 +04:00
}
2022-01-31 21:28:07 +00:00
. previewLayout ( . fixed ( width : 360 , height : 80 ) )
2022-01-29 11:10:04 +00:00
}
}