Skip to content

Commit 2ec7575

Browse files
authored
Merge pull request #34 from OlegEremenko991/develop
Доработки
2 parents ce726c0 + b3d2b37 commit 2ec7575

File tree

22 files changed

+120
-80
lines changed

22 files changed

+120
-80
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@
12101210
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
12111211
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12121212
CODE_SIGN_STYLE = Automatic;
1213-
CURRENT_PROJECT_VERSION = 5;
1213+
CURRENT_PROJECT_VERSION = 6;
12141214
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
12151215
DEVELOPMENT_TEAM = CR68PP2Z3F;
12161216
ENABLE_PREVIEWS = YES;
@@ -1246,7 +1246,7 @@
12461246
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
12471247
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12481248
CODE_SIGN_STYLE = Automatic;
1249-
CURRENT_PROJECT_VERSION = 5;
1249+
CURRENT_PROJECT_VERSION = 6;
12501250
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
12511251
DEVELOPMENT_TEAM = CR68PP2Z3F;
12521252
ENABLE_PREVIEWS = YES;

SwiftUI-WorkoutApp/Preview Content/PreviewContent.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ extension SportsGround {
2222
extension UserResponse {
2323
static var preview: UserResponse {
2424
.init(
25-
userName: "TestUserName",
26-
fullName: "TestFullName",
25+
userName: "Kahar",
26+
fullName: "",
2727
28-
imageStringURL: "avatar_default",
28+
imageStringURL: "https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg",
2929
birthDateIsoString: "1990-11-25",
3030
createdIsoDateTimeSec: nil,
31-
userID: .zero,
31+
userID: 24798,
3232
cityID: 1,
3333
countryID: 17,
3434
genderCode: 1,
@@ -47,7 +47,33 @@ extension UserModel {
4747

4848
extension EventResponse {
4949
static var preview: EventResponse {
50-
try! Bundle.main.decodeJson([EventResponse].self, fileName: "oldEvents.json").first!
50+
.init(
51+
id: 4414,
52+
title: "Открытая тренировка участников SOTKA и воркаутеров #2 в 2022 году",
53+
eventDescription: "!!! ВРЕМЯ ТРЕНИРОВКИ - 12:00",
54+
fullAddress: nil,
55+
createDate: "2022-10-16T09:00:00+00:00",
56+
modifyDate: "2022-10-16T09:00:00+00:00",
57+
beginDate: "2022-10-16T09:00:00+00:00",
58+
countryID: 17,
59+
cityID: 1,
60+
commentsCount: 2,
61+
previewImageStringURL: "https://workout.su/thumbs/6_100x100_FFFFFF//uploads/userfiles/2022/10/2022-10-12-21-10-42-skz.jpg",
62+
sportsGroundID: 5464,
63+
latitude: "55.72681766162947",
64+
longitude: "37.50063106774381",
65+
participantsCount: 3,
66+
isCurrent: false,
67+
photos: [
68+
.init(
69+
id: 1,
70+
stringURL: "https://workout.su/uploads/userfiles/2022/10/2022-10-12-21-10-42-skz.jpg"
71+
)
72+
],
73+
authorName: "Kahar",
74+
author: .preview,
75+
trainHereOptional: false
76+
)
5177
}
5278
}
5379

SwiftUI-WorkoutApp/Screens/Common/Comments/Comments.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct Comments: View {
99

1010
var body: some View {
1111
Section("Комментарии") {
12-
List(items) { comment in
12+
ForEach(items) { comment in
1313
CommentViewCell(
1414
model: comment,
1515
reportClbk: reportClbk,
@@ -24,7 +24,7 @@ struct Comments: View {
2424
#if DEBUG
2525
struct Comments_Previews: PreviewProvider {
2626
static var previews: some View {
27-
Form {
27+
List {
2828
Comments(
2929
items: [.preview, .preview],
3030
reportClbk: { _ in },

SwiftUI-WorkoutApp/Screens/Common/SendMessage/SendMessageView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private extension SendMessageView {
8989
}
9090

9191
func showKeyboard() {
92+
guard !isFocused else { return }
9293
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
9394
isFocused.toggle()
9495
}

SwiftUI-WorkoutApp/Screens/Common/TextEntry/TextEntryView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private extension TextEntryView {
122122
}
123123

124124
func showKeyboard() {
125+
guard !isFocused else { return }
125126
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
126127
isFocused.toggle()
127128
}

SwiftUI-WorkoutApp/Screens/Common/UsersList/UsersListView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private extension UsersListView.Mode {
7373
case .friends, .friendsForChat:
7474
return "Друзья"
7575
case .eventParticipants:
76-
return "Пойдут на мероприятие"
76+
return "Участники мероприятия"
7777
case .groundParticipants:
7878
return "Здесь тренируются"
7979
case .blacklist:

SwiftUI-WorkoutApp/Screens/Events/Detail/EventDetailsView.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ struct EventDetailsView: View {
2828
}
2929

3030
var body: some View {
31-
Form {
31+
List {
3232
mainInfo
3333
locationInfo
3434
if viewModel.event.hasDescription {
3535
descriptionSection
3636
}
37-
if defaults.isAuthorized {
37+
if showParticipantSection {
3838
participantsSection
3939
}
4040
if let photos = viewModel.event.photos,
@@ -151,7 +151,7 @@ private extension EventDetailsView {
151151
}
152152

153153
var participantsSection: some View {
154-
Section("Участники") {
154+
Section {
155155
if viewModel.hasParticipants {
156156
participantsButton
157157
}
@@ -167,12 +167,8 @@ private extension EventDetailsView {
167167
NavigationLink {
168168
UsersListView(mode: .eventParticipants(list: viewModel.event.participants))
169169
} label: {
170-
HStack {
171-
Text("Идут")
172-
Spacer()
173-
Text("peopleTrainHere \(viewModel.event.participants.count)")
174-
.foregroundColor(.secondary)
175-
}
170+
Text("Участники")
171+
.badge("peopleTrainHere \(viewModel.event.participants.count)")
176172
}
177173
}
178174

@@ -196,9 +192,7 @@ private extension EventDetailsView {
196192
/// Обновляем состояние `trainHere` при получении изменений от `viewModel`
197193
///
198194
/// Например, если сервер вернул ошибку при попытке сменить статус
199-
func onChangeOfTrainHere(value: Bool) {
200-
trainHere = value
201-
}
195+
func onChangeOfTrainHere(value: Bool) { trainHere = value }
202196

203197
var authorSection: some View {
204198
Section("Организатор") {
@@ -290,6 +284,14 @@ private extension EventDetailsView {
290284
: false
291285
}
292286

287+
var showParticipantSection: Bool {
288+
if defaults.isAuthorized {
289+
return viewModel.hasParticipants || viewModel.isEventCurrent
290+
} else {
291+
return false
292+
}
293+
}
294+
293295
func closeAlert() {
294296
viewModel.clearErrorMessage()
295297
}

SwiftUI-WorkoutApp/Screens/Events/List/EventsListView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ private extension EventsListView {
8585

8686
var eventsList: some View {
8787
List(selectedEventType == .future ? $viewModel.futureEvents : $viewModel.pastEvents) { $event in
88-
NavigationLink {
89-
EventDetailsView(with: event, deleteClbk: refreshAction)
90-
} label: {
88+
NavigationLink(destination: EventDetailsView(with: event, deleteClbk: refreshAction)) {
9189
EventViewCell(for: $event)
9290
}
9391
}

SwiftUI-WorkoutApp/Screens/Messages/DialogList/DialogListView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,14 @@ private extension DialogListView {
9595

9696
var dialogList: some View {
9797
List {
98-
ForEach($viewModel.list) { $dialog in
98+
ForEach(viewModel.list) { dialog in
9999
NavigationLink {
100-
DialogView(dialog: $dialog)
100+
DialogView(
101+
dialog: dialog,
102+
markedAsReadClbk: {
103+
viewModel.markAsRead(dialog, with: defaults)
104+
}
105+
)
101106
} label: {
102107
GenericListCell(for: .dialog(dialog))
103108
}

SwiftUI-WorkoutApp/Screens/Messages/DialogList/DialogListViewModel.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class DialogListViewModel: ObservableObject {
1111
if !refresh { isLoading.toggle() }
1212
do {
1313
list = try await APIService(with: defaults).getDialogs()
14+
defaults.unreadMessagesCount = list.map(\.unreadMessagesCount).reduce(0, +)
1415
} catch {
1516
errorMessage = ErrorFilterService.message(from: error)
1617
}
@@ -31,5 +32,21 @@ final class DialogListViewModel: ObservableObject {
3132
isLoading.toggle()
3233
}
3334

35+
func markAsRead(_ dialog: DialogResponse, with defaults: DefaultsProtocol) {
36+
list = list.map { item in
37+
if item.id == dialog.id {
38+
var updatedDialog = dialog
39+
updatedDialog.unreadMessagesCount = 0
40+
return updatedDialog
41+
} else {
42+
return item
43+
}
44+
}
45+
guard dialog.unreadMessagesCount > 0,
46+
defaults.unreadMessagesCount >= dialog.unreadMessagesCount
47+
else { return }
48+
defaults.unreadMessagesCount -= dialog.unreadMessagesCount
49+
}
50+
3451
func clearErrorMessage() { errorMessage = "" }
3552
}

0 commit comments

Comments
 (0)