@@ -8,9 +8,7 @@ public struct CommentRowView: View {
8
8
private let bodyText : String
9
9
private let isCommentByMainUser : Bool
10
10
private let isNetworkConnected : Bool
11
- private let reportAction : ( ) -> Void
12
- private let editAction : ( ) -> Void
13
- private let deleteAction : ( ) -> Void
11
+ private let action : ( Action ) -> Void
14
12
15
13
public init (
16
14
avatarURL: URL ? ,
@@ -19,19 +17,15 @@ public struct CommentRowView: View {
19
17
bodyText: String ,
20
18
isCommentByMainUser: Bool ,
21
19
isNetworkConnected: Bool ,
22
- reportAction: @escaping ( ) -> Void ,
23
- editAction: @escaping ( ) -> Void ,
24
- deleteAction: @escaping ( ) -> Void
20
+ action: @escaping ( Action ) -> Void
25
21
) {
26
22
self . avatarURL = avatarURL
27
23
self . userName = userName
28
24
self . dateText = dateText
29
25
self . bodyText = bodyText
30
26
self . isCommentByMainUser = isCommentByMainUser
31
27
self . isNetworkConnected = isNetworkConnected
32
- self . reportAction = reportAction
33
- self . editAction = editAction
34
- self . deleteAction = deleteAction
28
+ self . action = action
35
29
}
36
30
37
31
public var body : some View {
@@ -44,6 +38,8 @@ public struct CommentRowView: View {
44
38
}
45
39
. lineLimit ( 1 )
46
40
. frame ( maxWidth: . infinity, alignment: . leading)
41
+ . contentShape ( . rect)
42
+ . onTapGesture { action ( . openProfile) }
47
43
if isNetworkConnected {
48
44
menuButton
49
45
}
@@ -54,23 +50,40 @@ public struct CommentRowView: View {
54
50
}
55
51
}
56
52
53
+ public extension CommentRowView {
54
+ enum Action {
55
+ /// Пожаловаться
56
+ case report
57
+ /// Редактировать
58
+ case edit
59
+ /// Удалить
60
+ case delete
61
+ /// Открыть профиль автора комментария
62
+ case openProfile
63
+ }
64
+ }
65
+
57
66
private extension CommentRowView {
58
67
var leadingImage : some View {
59
- CachedImage ( url: avatarURL, mode: . commentAvatar)
60
- . borderedClipshape ( )
68
+ CachedImage (
69
+ url: avatarURL,
70
+ mode: . commentAvatar,
71
+ didTapImage: { _ in action ( . openProfile) }
72
+ )
73
+ . borderedCircleClipShape ( )
61
74
}
62
75
63
76
var menuButton : some View {
64
77
Menu {
65
78
if isCommentByMainUser {
66
- Button ( action: editAction ) {
79
+ Button ( action: { action ( . edit ) } ) {
67
80
Label ( " Изменить " , systemImage: Icons . Regular. pencil. rawValue)
68
81
}
69
- Button ( role: . destructive, action: deleteAction ) {
82
+ Button ( role: . destructive, action: { action ( . delete ) } ) {
70
83
Label ( " Удалить " , systemImage: Icons . Regular. trash. rawValue)
71
84
}
72
85
} else {
73
- Button ( role: . destructive, action: reportAction ) {
86
+ Button ( role: . destructive, action: { action ( . report ) } ) {
74
87
Label ( " Пожаловаться " , systemImage: Icons . Regular. exclamation. rawValue)
75
88
}
76
89
}
@@ -106,16 +119,29 @@ private extension CommentRowView {
106
119
107
120
#if DEBUG
108
121
#Preview {
109
- CommentRowView (
110
- avatarURL: . init( string: " https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg " ) !,
111
- userName: " Kahar " ,
112
- dateText: " 21 мая 2023 " ,
113
- bodyText: " Классная площадка, часто тренируюсь здесь с друзьями " ,
114
- isCommentByMainUser: false ,
115
- isNetworkConnected: true ,
116
- reportAction: { } ,
117
- editAction: { } ,
118
- deleteAction: { }
119
- )
122
+ VStack ( spacing: 20 ) {
123
+ CommentRowView (
124
+ avatarURL: . init( string: " https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg " ) !,
125
+ userName: " Kahar " ,
126
+ dateText: " 21 мая 2023 " ,
127
+ bodyText: " Классная площадка, часто тренируюсь здесь с друзьями " ,
128
+ isCommentByMainUser: false ,
129
+ isNetworkConnected: true ,
130
+ action: { option in
131
+ print ( " action: \( option) " )
132
+ }
133
+ )
134
+ CommentRowView (
135
+ avatarURL: . init( string: " https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg " ) !,
136
+ userName: " Kahar " ,
137
+ dateText: " 21 мая 2023 " ,
138
+ bodyText: " Классная площадка, часто тренируюсь здесь с друзьями " ,
139
+ isCommentByMainUser: true ,
140
+ isNetworkConnected: true ,
141
+ action: { option in
142
+ print ( " action: \( option) " )
143
+ }
144
+ )
145
+ }
120
146
}
121
147
#endif
0 commit comments