Skip to content

Commit

Permalink
Feed Headers (#837)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Andrews <[email protected]>
  • Loading branch information
Sjmarf and EricBAndrews authored Jan 4, 2024
1 parent 1612488 commit ce2363f
Show file tree
Hide file tree
Showing 45 changed files with 1,790 additions and 1,480 deletions.
74 changes: 36 additions & 38 deletions Mlem.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Mlem/API/Models/Community/APISubscribedStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum APISubscribedStatus: String, Decodable {

var isSubscribed: Bool {
switch self {
case .subscribed:
case .subscribed, .pending:
true
default:
false
Expand Down
6 changes: 3 additions & 3 deletions Mlem/Enums/FeedType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ enum FeedType: String, Encodable, SettingsOptions, AssociatedColor {
return .red
}
}

case all = "All"
case local = "Local"

case subscribed = "Subscribed"
case local = "Local"
case all = "All"
}

extension FeedType: AssociatedIcon {
Expand Down
10 changes: 5 additions & 5 deletions Mlem/Enums/Settings/PostSortType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ extension PostSortType: SettingsOptions {
var label: String {
switch self {
case .newComments:
return "New comments"
return "New Comments"
case .mostComments:
return "Most comments"
return "Most Comments"
case .topHour:
return "Hour"
case .topSixHour:
return "Six hours"
return "Six Hours"
case .topTwelveHour:
return "Twelve hours"
return "Twelve Hours"
case .topDay:
return "Day"
case .topWeek:
Expand All @@ -182,7 +182,7 @@ extension PostSortType: SettingsOptions {
case .topYear:
return "Year"
case .topAll:
return "All time"
return "All Time"
default:
return rawValue
}
Expand Down
14 changes: 7 additions & 7 deletions Mlem/Extensions/Mocks/APICommunityAggregates+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ extension APICommunityAggregates {
static func mock(
id: Int = 0,
communityId: Int = 0,
subscribers: Int = 0,
posts: Int = 0,
comments: Int = 0,
subscribers: Int = 42349,
posts: Int = 300,
comments: Int = 5000,
published: Date = .mock,
usersActiveDay: Int = 0,
usersActiveWeek: Int = 0,
usersActiveMonth: Int = 0,
usersActiveHalfYear: Int = 0
usersActiveDay: Int = 3040,
usersActiveWeek: Int = 20044,
usersActiveMonth: Int = 50403,
usersActiveHalfYear: Int = 73032
) -> APICommunityAggregates {
.init(
id: id,
Expand Down
13 changes: 2 additions & 11 deletions Mlem/Extensions/View Modifiers/View+HandleLemmyLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,15 @@ struct HandleLemmyLinksDisplay: ViewModifier {
.navigationDestination(for: AppRoute.self) { route in
switch route {
case let .community(community):
FeedView(community: community, feedType: .all)
CommunityView(community: community)
.environmentObject(appState)
.environmentObject(filtersTracker)
.environmentObject(quickLookState)
case let .communityLinkWithContext(context):
FeedView(community: context.community, feedType: context.feedType)
FeedParentView(community: context.community, feedType: context.feedType)
.environmentObject(appState)
.environmentObject(filtersTracker)
.environmentObject(quickLookState)
case let .communitySidebarLinkWithContext(context):
CommunitySidebarView(
community: context.community
)
.environmentObject(filtersTracker)
case let .apiPostView(post):
let postModel = PostModel(from: post)
let postTracker = PostTracker(
Expand Down Expand Up @@ -77,10 +72,6 @@ struct HandleLemmyLinksDisplay: ViewModifier {
case let .lazyLoadPostLinkWithContext(post):
LazyLoadExpandedPost(post: post.post, scrollTarget: post.scrollTarget)
.environmentObject(quickLookState)
case let .userModeratorLink(user):
UserModeratorView(userDetails: user.user, moderatedCommunities: user.moderatedCommunities)
.environmentObject(appState)
.environmentObject(quickLookState)
case let .settings(page):
settingsDestination(for: page)
case let .aboutSettings(page):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct NavigationBarColorModifier: ViewModifier {
} else {
content
.toolbarBackground(Color.systemBackground, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarBackground(visibility, for: .navigationBar)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Mlem/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ struct Icons {
static let updated: String = "clock.arrow.2.circlepath"
static let favorite: String = "star"
static let favoriteFill: String = "star.fill"
static let unfavorite: String = "star.slash"
static let unfavoriteFill: String = "star.slash.fill"
static let personFill: String = "person.fill"
static let close: String = "multiply"
static let cakeDay: String = "birthday.cake"
Expand All @@ -160,6 +162,7 @@ struct Icons {
static let filter: String = "line.3.horizontal.decrease.circle"
static let filterFill: String = "line.3.horizontal.decrease.circle.fill"
static let menu: String = "ellipsis"
static let menuCircle: String = "ellipsis.circle"
static let `import`: String = "square.and.arrow.down"
static let attachment: String = "paperclip"
static let edit: String = "pencil"
Expand Down
59 changes: 54 additions & 5 deletions Mlem/Models/Content/Community/CommunityModel+MenuFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ import Foundation
import SwiftUI

extension CommunityModel {
func subscribeMenuFunction(_ callback: @escaping (_ item: Self) -> Void = { _ in }) throws -> MenuFunction {
func newPostMenuFunction(editorTracker: EditorTracker, postTracker: PostTracker? = nil) -> MenuFunction {
return .standardMenuFunction(
text: "New Post",
imageName: Icons.sendFill,
destructiveActionPrompt: nil,
enabled: true
) {
editorTracker.openEditor(with: PostEditorModel(
community: self,
postTracker: postTracker
))
}
}

func subscribeMenuFunction(_ callback: @escaping (_ item: Self) -> Void = { _ in }) throws -> StandardMenuFunction {
guard let subscribed else {
throw CommunityError.noData
}
return .standardMenuFunction(
return .init(
text: subscribed ? "Unsubscribe" : "Subscribe",
imageName: subscribed ? Icons.unsubscribe : Icons.subscribe,
destructiveActionPrompt: subscribed ? "Are you sure you want to unsubscribe from \(name)?" : nil,
destructiveActionPrompt: subscribed ? "Are you sure you want to unsubscribe from \(name!)?" : nil,
enabled: true,
callback: {
Task {
Expand All @@ -31,6 +45,24 @@ extension CommunityModel {
)
}

func favoriteMenuFunction(_ callback: @escaping (_ item: Self) -> Void = { _ in }) -> StandardMenuFunction {
return .init(
text: favorited ? "Unfavorite" : "Favorite",
imageName: favorited ? Icons.unfavorite : Icons.favorite,
destructiveActionPrompt: favorited ? "Really unfavorite \(community.name)?" : nil,
enabled: true
) {
Task {
do {
var new = self
try await new.toggleFavorite(callback)
} catch {
errorHandler.handle(error)
}
}
}
}

func blockMenuFunction(_ callback: @escaping (_ item: Self) -> Void = { _ in }) throws -> MenuFunction {
guard let blocked else {
throw CommunityError.noData
Expand All @@ -53,11 +85,28 @@ extension CommunityModel {
)
}

func menuFunctions(_ callback: @escaping (_ item: Self) -> Void = { _ in }) -> [MenuFunction] {
func menuFunctions(
_ callback: @escaping (_ item: Self) -> Void = { _ in },
editorTracker: EditorTracker? = nil,
postTracker: PostTracker? = nil
) -> [MenuFunction] {
var functions: [MenuFunction] = .init()
if let editorTracker {
functions.append(newPostMenuFunction(editorTracker: editorTracker, postTracker: postTracker))
}
if let function = try? subscribeMenuFunction(callback) {
functions.append(function)
functions.append(.standard(function))
}
functions.append(.standard(favoriteMenuFunction(callback)))
functions.append(
.standardMenuFunction(
text: "Copy Name",
imageName: Icons.copy,
destructiveActionPrompt: nil,
enabled: true,
callback: copyFullyQualifiedName
)
)
functions.append(.shareMenuFunction(url: communityUrl))
if let function = try? blockMenuFunction(callback) {
functions.append(function)
Expand Down
36 changes: 33 additions & 3 deletions Mlem/Models/Content/Community/CommunityModel+SwipeActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension CommunityModel {
hapticManager.play(haptic: .lightSuccess, priority: .low)

if subscribed, let confirmDestructive {
if case .standard(let function) = try? subscribeMenuFunction(callback) {
if let function = try? subscribeMenuFunction(callback) {
confirmDestructive(function)
}
} else {
Expand All @@ -43,14 +43,44 @@ extension CommunityModel {
)
}

func favoriteSwipeAction(
_ callback: @escaping (_ item: Self) -> Void = { _ in },
confirmDestructive: ((StandardMenuFunction) -> Void)? = nil
) -> SwipeAction {
let (emptySymbolName, fullSymbolName) = (favorited)
? (Icons.unfavorite, Icons.unfavoriteFill)
: (Icons.favorite, Icons.favoriteFill)
return SwipeAction(
symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName),
color: favorited ? .red : .blue,
action: {
Task {
hapticManager.play(haptic: .lightSuccess, priority: .low)

if favorited, let confirmDestructive {
confirmDestructive(favoriteMenuFunction(callback))
} else {
var new = self
try await new.toggleFavorite(callback)
}
}
}
)
}

func swipeActions(
_ callback: @escaping (_ item: Self) -> Void = { _ in },
confirmDestructive: ((StandardMenuFunction) -> Void)? = nil
) -> SwipeConfiguration {
var trailingActions: [SwipeAction] = []
if let action = try? subscribeSwipeAction(callback, confirmDestructive: confirmDestructive) {
trailingActions.append(action)
let subscribeAction = try? subscribeSwipeAction(callback, confirmDestructive: confirmDestructive)
let favoriteAction = favoriteSwipeAction(callback, confirmDestructive: confirmDestructive)

if let subscribeAction {
trailingActions.append(subscribeAction)
}
trailingActions.append(favoriteAction)

return SwipeConfiguration(leadingActions: [], trailingActions: trailingActions)
}
}
Loading

0 comments on commit ce2363f

Please sign in to comment.