Skip to content

Commit

Permalink
[iOS] UI bug on iPad when using filters in Discussion (#333)
Browse files Browse the repository at this point in the history
* fix: iPad register and login buttons

* fix: IPad sign up view

* fix: iPad Course outline view

* feat: added IPAD_STRETCH config parameter

* fix: size bug on small device

* fix: iPad stretch for content types

* fix: player on iPad and small devices

* fix: stretch for search bar on discussions page

* fix: discussion search bar stretch

* fix: bug of player on small devices

* fix: removed stretching for sign up/sign in views

* feat: removed feature flag

* feat: added readable content size

* fix: added readable content size to startup screen

* fix: sign in, sign up, reset password readable paddings

* fix: scroll bar position for edit profile view

* fix: social buttons

* feat: added readability and accessibility injections

* fix: resize of content and added readability for content types

* fix: readability width calculation

* feat: added Discussons paddings

* feat: added iPad paddings for Dates tab

* feat: added injection to html webview

* feat: added readable for profile

* feat: added padding for tab menu

* feat: added paddings to dashboard view

* fix: merge conflict

* feat: moved filter buttons

* feat: added paddings to Delete Account View

* feat: added paddings for native discovery view

* feat: added padding for CourseVerticalsView

* feat: added paddings for responses view

* feat: added paddings to UserProfileView

* fix: do not block scroll from side for UserProfileView

* chore: review's changes

* chore: merge conflicts

* chore: merge conflict

* chore: warning

* fix: UI bug on iPad when using filters in Discussion #308

* fix: merge conflicts

* chore: merge conflict

* chore: removed extra horizontal padding

* Revert "chore: removed extra horizontal padding"

This reverts commit 933f366.

* chore: removed extra horizontal padding

* chore: refactor

* chore: label alignment

* chore: merge conflicts

* chore: status bar fix

* chore: merge conflict

* chore: set title to be visible

* chore: do not show title on iPad

* chore: removed useless code and fix warnings

* chore: review's require changes

* chore: fixed warnings

* chore: merge fix
  • Loading branch information
forgotvas authored Mar 26, 2024
1 parent 2bc8c4f commit 513a883
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 79 deletions.
25 changes: 22 additions & 3 deletions Discussion/Discussion/Domain/Model/ThreadType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,36 @@ public enum ThreadType {
case courseTopics(topicID: String)
}

public enum ThreadsFilter {
public enum ThreadsFilter: Identifiable {
public var id: String {
localizedValue
}

case allThreads
case unread
case unanswered

var localizedValue: String {
switch self {
case .allThreads:
return DiscussionLocalization.Posts.Filter.allPosts
case .unread:
return DiscussionLocalization.Posts.Filter.unread
case .unanswered:
return DiscussionLocalization.Posts.Filter.unanswered
}
}
}

public enum SortType {
public enum SortType: Identifiable {
public var id: String {
localizedValue
}

case recentActivity
case mostActivity
case mostVotes

var localizedValue: String {
switch self {
case .recentActivity:
Expand Down
93 changes: 69 additions & 24 deletions Discussion/Discussion/Presentation/Posts/PostsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import Theme
public struct PostsView: View {

@ObservedObject private var viewModel: PostsViewModel
@State private var showingAlert = false
@State private var showFilterSheet = false
@State private var showSortSheet = false
private let router: DiscussionRouter
private let title: String
private let currentBlockID: String
private let courseID: String
private var showTopMenu: Bool
private var isPad: Bool {
UIDevice.current.userInterfaceIdiom == .pad
}

public init(
courseID: String,
Expand Down Expand Up @@ -73,25 +77,10 @@ public struct PostsView: View {
VStack {
HStack {
Group {
Button(action: {
viewModel.generateButtons(type: .filter)
showingAlert = true
}, label: {
CoreAssets.filter.swiftUIImage.renderingMode(.template)
.foregroundColor(Theme.Colors.accentXColor)
Text(viewModel.filterTitle.localizedValue)
})
filterButton
Spacer()
Button(action: {
viewModel.generateButtons(type: .sort)
showingAlert = true
}, label: {
CoreAssets.sort.swiftUIImage.renderingMode(.template)
.foregroundColor(Theme.Colors.accentXColor)
Text(viewModel.sortTitle.localizedValue)
})
}
.foregroundColor(Theme.Colors.accentColor)
sortButton
}.foregroundColor(Theme.Colors.accentColor)
}
.font(Theme.Fonts.labelMedium)
.padding(.horizontal, 24)
Expand Down Expand Up @@ -210,7 +199,6 @@ public struct PostsView: View {
}
}
.accessibilityAction {}
.animation(nil)
.onRightSwipeGesture {
router.back()
}
Expand Down Expand Up @@ -241,13 +229,70 @@ public struct PostsView: View {
Theme.Colors.background
.ignoresSafeArea()
)
// MARK: - Action Sheet
.actionSheet(isPresented: $showingAlert, content: {
ActionSheet(title: Text(DiscussionLocalization.Posts.Alert.makeSelection), buttons: viewModel.filterButtons)
})
}
}

private var filterButton: some View {
Button(
action: {
showFilterSheet = true
},
label: {
CoreAssets.filter.swiftUIImage
.renderingMode(.template)
.foregroundColor(Theme.Colors.accentXColor)
Text(viewModel.filterTitle.localizedValue)
}
)
.confirmationDialog(
DiscussionLocalization.Posts.Alert.makeSelection,
isPresented: $showFilterSheet,
titleVisibility: isPad ? .automatic : .visible,
actions: {
ForEach(viewModel.filterInfos) { info in
Button(
action: {
viewModel.filter(by: info)
},
label: {
Text(info.localizedValue)
}
)
}
}
)
}

private var sortButton: some View {
Button(
action: {
showSortSheet = true
},
label: {
CoreAssets.sort.swiftUIImage.renderingMode(.template)
.foregroundColor(Theme.Colors.accentXColor)
Text(viewModel.sortTitle.localizedValue)
}
)
.confirmationDialog(
DiscussionLocalization.Posts.Alert.makeSelection,
isPresented: $showSortSheet,
titleVisibility: isPad ? .automatic : .visible,
actions: {
ForEach(viewModel.sortInfos) { info in
Button(
action: {
viewModel.sort(by: info)
},
label: {
Text(info.localizedValue)
}
)
}
}
)
}

@MainActor
private func reloadPage(onSuccess: @escaping () -> Void) {
Task {
Expand Down
78 changes: 26 additions & 52 deletions Discussion/Discussion/Presentation/Posts/PostsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ import SwiftUI
import Combine
import Core

public extension ThreadsFilter {

var localizedValue: String {
switch self {
case .allThreads:
return DiscussionLocalization.Posts.Filter.allPosts
case .unread:
return DiscussionLocalization.Posts.Filter.unread
case .unanswered:
return DiscussionLocalization.Posts.Filter.unanswered
}
}
}

public class PostsViewModel: ObservableObject {

public var nextPage = 1
Expand All @@ -40,7 +26,7 @@ public class PostsViewModel: ObservableObject {
@Published var filteredPosts: [DiscussionPost] = []
@Published var filterTitle: ThreadsFilter = .allThreads {
willSet {
if let courseID {
if courseID != nil {
resetPosts()
Task {
_ = await getPosts(pageNumber: 1)
Expand All @@ -50,15 +36,30 @@ public class PostsViewModel: ObservableObject {
}
@Published var sortTitle: SortType = .recentActivity {
willSet {
if let courseID {
if courseID != nil {
resetPosts()
Task {
_ = await getPosts(pageNumber: 1)
}
}
}
}
@Published var filterButtons: [ActionSheet.Button] = []

var filterInfos: [ThreadsFilter] {
[
.allThreads,
.unread,
.unanswered
]
}

var sortInfos: [SortType] {
[
.recentActivity,
.mostActivity,
.mostVotes
]
}

public var courseID: String?
var errorMessage: String? {
Expand Down Expand Up @@ -113,41 +114,14 @@ public class PostsViewModel: ObservableObject {
totalPages = 1
}

public func generateButtons(type: ButtonType) {
switch type {
case .sort:
self.filterButtons = [
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Sort.recentActivity)) {
self.sortTitle = .recentActivity
self.filteredPosts = self.discussionPosts
},
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Sort.mostActivity)) {
self.sortTitle = .mostActivity
self.filteredPosts = self.discussionPosts
},
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Sort.mostVotes)) {
self.sortTitle = .mostVotes
self.filteredPosts = self.discussionPosts
},
.cancel()
]
case .filter:
self.filterButtons = [
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Filter.allPosts)) {
self.filterTitle = .allThreads
self.filteredPosts = self.discussionPosts
},
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Filter.unread)) {
self.filterTitle = .unread
self.filteredPosts = self.discussionPosts
},
ActionSheet.Button.default(Text(DiscussionLocalization.Posts.Filter.unanswered)) {
self.filterTitle = .unanswered
self.filteredPosts = self.discussionPosts
},
.cancel()
]
}
public func sort(by value: SortType) {
self.sortTitle = value
self.filteredPosts = self.discussionPosts
}

public func filter(by value: ThreadsFilter) {
self.filterTitle = value
self.filteredPosts = self.discussionPosts
}

func generatePosts(threads: ThreadLists?) -> [DiscussionPost] {
Expand Down

0 comments on commit 513a883

Please sign in to comment.