Skip to content

Commit 1c8f4a2

Browse files
authored
Рефактор навигации на паре экранов (#253)
Обновил навигацию для экранов: - Площадка - Мероприятие - Диалоги
1 parent 2a07f37 commit 1c8f4a2

File tree

5 files changed

+170
-112
lines changed

5 files changed

+170
-112
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@
846846
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
847847
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
848848
CODE_SIGN_STYLE = Automatic;
849-
CURRENT_PROJECT_VERSION = 7;
849+
CURRENT_PROJECT_VERSION = 8;
850850
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
851851
DEVELOPMENT_TEAM = CR68PP2Z3F;
852852
ENABLE_PREVIEWS = YES;
@@ -896,7 +896,7 @@
896896
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
897897
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
898898
CODE_SIGN_STYLE = Automatic;
899-
CURRENT_PROJECT_VERSION = 7;
899+
CURRENT_PROJECT_VERSION = 8;
900900
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
901901
DEVELOPMENT_TEAM = CR68PP2Z3F;
902902
ENABLE_PREVIEWS = YES;

SwiftUI-WorkoutApp/Screens/Common/CommentsView.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct CommentsView: View {
1010
let reportClbk: (CommentResponse) -> Void
1111
let deleteClbk: (Int) -> Void
1212
let editClbk: (CommentResponse) -> Void
13-
@Binding var isCreatingComment: Bool
13+
let createCommentClbk: () -> Void
1414

1515
var body: some View {
1616
VStack(spacing: 16) {
@@ -35,10 +35,8 @@ struct CommentsView: View {
3535
}
3636
}
3737
if defaults.isAuthorized {
38-
Button("Добавить комментарий") {
39-
isCreatingComment.toggle()
40-
}
41-
.buttonStyle(SWButtonStyle(mode: .filled, size: .large))
38+
Button("Добавить комментарий", action: createCommentClbk)
39+
.buttonStyle(SWButtonStyle(mode: .filled, size: .large))
4240
}
4341
}
4442
}
@@ -51,7 +49,7 @@ struct CommentsView: View {
5149
reportClbk: { _ in },
5250
deleteClbk: { _ in },
5351
editClbk: { _ in },
54-
isCreatingComment: .constant(false)
52+
createCommentClbk: {}
5553
)
5654
.padding(.horizontal)
5755
.environmentObject(DefaultsService())
@@ -63,7 +61,7 @@ struct CommentsView: View {
6361
reportClbk: { _ in },
6462
deleteClbk: { _ in },
6563
editClbk: { _ in },
66-
isCreatingComment: .constant(false)
64+
createCommentClbk: {}
6765
)
6866
.padding(.horizontal)
6967
.environmentObject(DefaultsService())

SwiftUI-WorkoutApp/Screens/Events/EventDetailsView.swift

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ struct EventDetailsView: View {
88
@Environment(\.dismiss) private var dismiss
99
@Environment(\.networkConnected) private var isNetworkConnected
1010
@EnvironmentObject private var defaults: DefaultsService
11+
@State private var navigationDestination: NavigationDestination?
12+
@State private var sheetItem: SheetItem?
1113
@State private var isLoading = false
1214
@State private var showErrorAlert = false
1315
@State private var alertMessage = ""
1416
@State private var showDeleteDialog = false
15-
@State private var sheetItem: SheetItem?
1617
@State private var goingToEventTask: Task<Void, Never>?
1718
@State private var deleteCommentTask: Task<Void, Never>?
1819
@State private var deletePhotoTask: Task<Void, Never>?
1920
@State private var deleteEventTask: Task<Void, Never>?
2021
@State private var refreshButtonTask: Task<Void, Never>?
21-
/// Мероприятие для редактирования
22-
///
23-
/// Задаем при нажатии на кнопку редактирования,
24-
/// чтобы в нем были актуальные данные
25-
@State private var eventToEdit: EventResponse?
2622
@State var event: EventResponse
2723
let onDeletion: (Int) -> Void
2824

@@ -53,7 +49,7 @@ struct EventDetailsView: View {
5349
.background {
5450
NavigationLink(
5551
destination: lazyDestination,
56-
isActive: $eventToEdit.mappedToBool()
52+
isActive: $navigationDestination.mappedToBool()
5753
)
5854
}
5955
.loadingOverlay(if: isLoading)
@@ -82,15 +78,21 @@ struct EventDetailsView: View {
8278
}
8379

8480
private extension EventDetailsView {
85-
enum SheetItem: Identifiable, Equatable {
81+
enum NavigationDestination {
82+
case eventAuthor(UserResponse)
83+
case eventParticipants([UserResponse])
84+
case editEvent(EventResponse)
85+
}
86+
87+
enum SheetItem: Identifiable {
8688
var id: Int {
8789
switch self {
8890
case .newComment: 1
8991
case .editComment: 2
9092
}
9193
}
9294

93-
case newComment
95+
case newComment(_ eventId: Int)
9496
case editComment(CommentResponse)
9597
}
9698
}
@@ -182,8 +184,8 @@ private extension EventDetailsView {
182184
var participantsSection: some View {
183185
Group {
184186
if event.hasParticipants {
185-
NavigationLink {
186-
UsersListView(mode: .eventParticipants(list: event.participants))
187+
Button {
188+
navigationDestination = .eventParticipants(event.participants)
187189
} label: {
188190
FormRowView(
189191
title: "Участники",
@@ -238,25 +240,29 @@ private extension EventDetailsView {
238240
}
239241
}
240242

243+
@ViewBuilder
241244
var authorSection: some View {
242-
let user = event.author
243-
return SectionView(headerWithPadding: "Организатор", mode: .regular) {
244-
NavigationLink(destination: UserDetailsView(for: user)) {
245-
UserRowView(
246-
mode: .regular(
247-
.init(
248-
imageURL: user?.avatarURL,
249-
name: user?.userName ?? "",
250-
address: SWAddress(user?.countryID, user?.cityID)?.address ?? ""
245+
if let user = event.author {
246+
SectionView(headerWithPadding: "Организатор", mode: .regular) {
247+
Button {
248+
navigationDestination = .eventAuthor(user)
249+
} label: {
250+
UserRowView(
251+
mode: .regular(
252+
.init(
253+
imageURL: user.avatarURL,
254+
name: user.userName ?? "",
255+
address: SWAddress(user.countryID, user.cityID)?.address ?? ""
256+
)
251257
)
252258
)
259+
}
260+
.disabled(
261+
!defaults.isAuthorized
262+
|| isEventAuthor
263+
|| !isNetworkConnected
253264
)
254265
}
255-
.disabled(
256-
!defaults.isAuthorized
257-
|| isEventAuthor
258-
|| !isNetworkConnected
259-
)
260266
}
261267
}
262268

@@ -266,12 +272,7 @@ private extension EventDetailsView {
266272
reportClbk: reportComment,
267273
deleteClbk: deleteComment,
268274
editClbk: { sheetItem = .editComment($0) },
269-
isCreatingComment: .init(
270-
get: { sheetItem == .newComment },
271-
set: { newValue in
272-
sheetItem = newValue ? .newComment : nil
273-
}
274-
)
275+
createCommentClbk: { sheetItem = .newComment(event.id) }
275276
)
276277
}
277278

@@ -282,15 +283,22 @@ private extension EventDetailsView {
282283
}
283284

284285
var editEventButton: some View {
285-
Button { eventToEdit = event } label: {
286+
Button { navigationDestination = .editEvent(event) } label: {
286287
Label("Изменить", systemImage: Icons.Regular.pencil.rawValue)
287288
}
288289
}
289290

290291
@ViewBuilder
291292
var lazyDestination: some View {
292-
if let eventToEdit {
293-
EventFormView(mode: .editExisting(eventToEdit), refreshClbk: refreshAction)
293+
if let navigationDestination {
294+
switch navigationDestination {
295+
case let .eventAuthor(user):
296+
UserDetailsView(for: user)
297+
case let .eventParticipants(users):
298+
UsersListView(mode: .eventParticipants(list: users))
299+
case let .editEvent(eventToEdit):
300+
EventFormView(mode: .editExisting(eventToEdit), refreshClbk: refreshAction)
301+
}
294302
}
295303
}
296304

@@ -319,9 +327,9 @@ private extension EventDetailsView {
319327
),
320328
refreshClbk: refreshAction
321329
)
322-
case .newComment:
330+
case let .newComment(eventId):
323331
TextEntryView(
324-
mode: .newForEvent(id: event.id),
332+
mode: .newForEvent(id: eventId),
325333
refreshClbk: refreshAction
326334
)
327335
}

SwiftUI-WorkoutApp/Screens/Messages/DialogListView.swift

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct DialogListView: View {
88
@Environment(\.networkConnected) private var isNetworkConnected
99
@EnvironmentObject private var defaults: DefaultsService
1010
@State private var dialogs = [DialogResponse]()
11+
@State private var selectedDialog: DialogResponse?
1112
@State private var isLoading = false
1213
@State private var showErrorAlert = false
1314
@State private var errorTitle = ""
@@ -107,25 +108,34 @@ private extension DialogListView {
107108
.opacity(dialogs.isEmpty ? 0 : 1)
108109
}
109110
.animation(.default, value: dialogs.count)
111+
.background(
112+
NavigationLink(
113+
destination: lazyDestination,
114+
isActive: $selectedDialog.mappedToBool()
115+
)
116+
)
117+
}
118+
119+
@ViewBuilder
120+
var lazyDestination: some View {
121+
if let selectedDialog {
122+
DialogView(dialog: selectedDialog) { markAsRead($0) }
123+
}
110124
}
111125

112126
func dialogListItem(_ model: DialogResponse) -> some View {
113-
DialogRowView(
114-
model: .init(
115-
avatarURL: model.anotherUserImageURL,
116-
authorName: model.anotherUserName ?? "",
117-
dateText: model.lastMessageDateString,
118-
messageText: model.lastMessageFormatted,
119-
unreadCount: model.unreadMessagesCount
127+
Button {
128+
selectedDialog = model
129+
} label: {
130+
DialogRowView(
131+
model: .init(
132+
avatarURL: model.anotherUserImageURL,
133+
authorName: model.anotherUserName ?? "",
134+
dateText: model.lastMessageDateString,
135+
messageText: model.lastMessageFormatted,
136+
unreadCount: model.unreadMessagesCount
137+
)
120138
)
121-
)
122-
.background {
123-
NavigationLink {
124-
DialogView(dialog: model) { markAsRead($0) }
125-
} label: {
126-
EmptyView()
127-
}
128-
.opacity(0)
129139
}
130140
}
131141

0 commit comments

Comments
 (0)