Various fixes + fix Explore navigation

This commit is contained in:
Thomas Ricouard 2023-03-02 20:15:07 +01:00
parent d7f1ef45fe
commit 37ed178c3f
10 changed files with 47 additions and 52 deletions

View file

@ -9,6 +9,7 @@ import Models
import Status import Status
import SwiftUI import SwiftUI
import Timeline import Timeline
import Explore
@MainActor @MainActor
extension View { extension View {
@ -43,6 +44,10 @@ extension View {
AccountsListView(mode: .rebloggedBy(statusId: id)) AccountsListView(mode: .rebloggedBy(statusId: id))
case let .accountsList(accounts): case let .accountsList(accounts):
AccountsListView(mode: .accountsList(accounts: accounts)) AccountsListView(mode: .accountsList(accounts: accounts))
case .trendingTimeline:
TimelineView(timeline: .constant(.trending), scrollToTopSignal: .constant(0))
case let .tagsList(tags):
TagsListView(tags: tags)
} }
} }
} }

View file

@ -36,7 +36,7 @@ class EditAccountViewModel: ObservableObject {
guard let client else { return } guard let client else { return }
do { do {
let account: Account = try await client.get(endpoint: Accounts.verifyCredentials) let account: Account = try await client.get(endpoint: Accounts.verifyCredentials)
displayName = account.displayName displayName = account.displayName ?? ""
note = account.source?.note ?? "" note = account.source?.note ?? ""
postPrivacy = account.source?.privacy ?? .pub postPrivacy = account.source?.privacy ?? .pub
isSensitive = account.source?.sensitive ?? false isSensitive = account.source?.sensitive ?? false

View file

@ -10,10 +10,10 @@ public extension Account {
} }
var safeDisplayName: String { var safeDisplayName: String {
if displayName.isEmpty || displayName == "" { if let displayName, !displayName.isEmpty {
return "@\(username)" return displayName
} }
return displayName return "@\(username)"
} }
var displayNameWithoutEmojis: String { var displayNameWithoutEmojis: String {

View file

@ -19,6 +19,8 @@ public enum RouterDestination: Hashable {
case favoritedBy(id: String) case favoritedBy(id: String)
case rebloggedBy(id: String) case rebloggedBy(id: String)
case accountsList(accounts: [Account]) case accountsList(accounts: [Account])
case trendingTimeline
case tagsList(tags: [Tag])
} }
public enum SheetDestination: Identifiable { public enum SheetDestination: Identifiable {

View file

@ -133,21 +133,7 @@ public struct ExploreView: View {
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
} }
} }
NavigationLink { NavigationLink(value: RouterDestination.accountsList(accounts: viewModel.suggestedAccounts)) {
List {
ForEach(viewModel.suggestedAccounts) { account in
if let relationship = viewModel.suggestedAccountsRelationShips.first(where: { $0.id == account.id }) {
AccountsListRow(viewModel: .init(account: account, relationShip: relationship))
.listRowBackground(theme.primaryBackgroundColor)
}
}
}
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
.listStyle(.plain)
.navigationTitle("explore.section.suggested-users")
.navigationBarTitleDisplayMode(.inline)
} label: {
Text("see-more") Text("see-more")
.foregroundColor(theme.tintColor) .foregroundColor(theme.tintColor)
} }
@ -163,20 +149,7 @@ public struct ExploreView: View {
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
.padding(.vertical, 4) .padding(.vertical, 4)
} }
NavigationLink { NavigationLink(value: RouterDestination.tagsList(tags: viewModel.trendingTags)) {
List {
ForEach(viewModel.trendingTags) { tag in
TagRowView(tag: tag)
.listRowBackground(theme.primaryBackgroundColor)
.padding(.vertical, 4)
}
}
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
.listStyle(.plain)
.navigationTitle("explore.section.trending.tags")
.navigationBarTitleDisplayMode(.inline)
} label: {
Text("see-more") Text("see-more")
.foregroundColor(theme.tintColor) .foregroundColor(theme.tintColor)
} }
@ -193,20 +166,7 @@ public struct ExploreView: View {
.padding(.vertical, 8) .padding(.vertical, 8)
} }
NavigationLink { NavigationLink(value: RouterDestination.trendingTimeline) {
List {
ForEach(viewModel.trendingStatuses) { status in
StatusRowView(viewModel: { .init(status: status, client: client, routerPath: routerPath) })
.listRowBackground(theme.primaryBackgroundColor)
.padding(.vertical, 8)
}
}
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
.listStyle(.plain)
.navigationTitle("explore.section.trending.posts")
.navigationBarTitleDisplayMode(.inline)
} label: {
Text("see-more") Text("see-more")
.foregroundColor(theme.tintColor) .foregroundColor(theme.tintColor)
} }

View file

@ -0,0 +1,28 @@
import SwiftUI
import Models
import DesignSystem
public struct TagsListView: View {
@EnvironmentObject private var theme: Theme
let tags: [Tag]
public init(tags: [Tag]) {
self.tags = tags
}
public var body: some View {
List {
ForEach(tags) { tag in
TagRowView(tag: tag)
.listRowBackground(theme.primaryBackgroundColor)
.padding(.vertical, 4)
}
}
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
.listStyle(.plain)
.navigationTitle("explore.section.trending.tags")
.navigationBarTitleDisplayMode(.inline)
}
}

View file

@ -46,7 +46,7 @@ public struct ListAddAccountView: View {
} }
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor) .background(theme.secondaryBackgroundColor)
.navigationTitle("lists.add-remove-\(viewModel.account.displayName)") .navigationTitle("lists.add-remove-\(viewModel.account.safeDisplayName)")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
ToolbarItem { ToolbarItem {

View file

@ -41,7 +41,7 @@ public final class Account: Codable, Identifiable, Hashable, Sendable, Equatable
public let id: String public let id: String
public let username: String public let username: String
public let displayName: String public let displayName: String?
public let avatar: URL public let avatar: URL
public let header: URL public let header: URL
public let acct: String public let acct: String
@ -67,7 +67,7 @@ public final class Account: Codable, Identifiable, Hashable, Sendable, Equatable
return header.lastPathComponent != "missing.png" return header.lastPathComponent != "missing.png"
} }
public init(id: String, username: String, displayName: String, avatar: URL, header: URL, acct: String, note: HTMLString, createdAt: ServerDate, followersCount: Int, followingCount: Int, statusesCount: Int, lastStatusAt: String? = nil, fields: [Account.Field], locked: Bool, emojis: [Emoji], url: URL? = nil, source: Account.Source? = nil, bot: Bool, discoverable: Bool? = nil) { public init(id: String, username: String, displayName: String?, avatar: URL, header: URL, acct: String, note: HTMLString, createdAt: ServerDate, followersCount: Int, followingCount: Int, statusesCount: Int, lastStatusAt: String? = nil, fields: [Account.Field], locked: Bool, emojis: [Emoji], url: URL? = nil, source: Account.Source? = nil, bot: Bool, discoverable: Bool? = nil) {
self.id = id self.id = id
self.username = username self.username = username
self.displayName = displayName self.displayName = displayName

View file

@ -145,7 +145,7 @@ public struct StatusRowView: View {
-100 -100
} }
.environmentObject( .environmentObject(
StatusDataControllerProvider.shared.dataController(for: viewModel.status.reblog ?? viewModel.status, StatusDataControllerProvider.shared.dataController(for: viewModel.finalStatus,
client: client) client: client)
) )
} }

View file

@ -24,7 +24,7 @@ struct StatusRowHeaderView: View {
} }
} }
.accessibilityElement() .accessibilityElement()
.accessibilityLabel(Text("\(viewModel.finalStatus.account.displayName)")) .accessibilityLabel(Text("\(viewModel.finalStatus.account.safeDisplayName)"))
} }
@ViewBuilder @ViewBuilder