mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-03-14 22:22:41 +00:00
Premium posts tab on linked standard account
This commit is contained in:
parent
76220bd930
commit
9364fc8cc8
4 changed files with 39 additions and 15 deletions
|
@ -21,7 +21,6 @@ public struct AccountDetailView: View {
|
|||
@Environment(RouterPath.self) private var routerPath
|
||||
|
||||
@State private var viewModel: AccountDetailViewModel
|
||||
@State private var isCurrentUser: Bool = false
|
||||
@State private var showBlockConfirmation: Bool = false
|
||||
@State private var isEditingRelationshipNote: Bool = false
|
||||
@State private var showTranslateView: Bool = false
|
||||
|
@ -57,8 +56,7 @@ public struct AccountDetailView: View {
|
|||
.applyAccountDetailsRowStyle(theme: theme)
|
||||
|
||||
Picker("", selection: $viewModel.selectedTab) {
|
||||
ForEach(isCurrentUser ? AccountDetailViewModel.Tab.currentAccountTabs : AccountDetailViewModel.Tab.accountTabs,
|
||||
id: \.self)
|
||||
ForEach(viewModel.tabs, id: \.self)
|
||||
{ tab in
|
||||
if tab == .boosts {
|
||||
Image("Rocket")
|
||||
|
@ -97,8 +95,7 @@ public struct AccountDetailView: View {
|
|||
}
|
||||
.onAppear {
|
||||
guard reasons != .placeholder else { return }
|
||||
isCurrentUser = currentAccount.account?.id == viewModel.accountId
|
||||
viewModel.isCurrentUser = isCurrentUser
|
||||
viewModel.isCurrentUser = currentAccount.account?.id == viewModel.accountId
|
||||
viewModel.client = client
|
||||
|
||||
// Avoid capturing non-Sendable `self` just to access the view model.
|
||||
|
@ -298,7 +295,7 @@ public struct AccountDetailView: View {
|
|||
}
|
||||
}
|
||||
|
||||
if isCurrentUser {
|
||||
if viewModel.isCurrentUser {
|
||||
Button {
|
||||
routerPath.presentedSheet = .accountEditInfo
|
||||
} label: {
|
||||
|
|
|
@ -16,7 +16,7 @@ import SwiftUI
|
|||
}
|
||||
|
||||
enum Tab: Int {
|
||||
case statuses, favorites, bookmarks, replies, boosts, media
|
||||
case statuses, favorites, bookmarks, replies, boosts, media, premiumPosts
|
||||
|
||||
static var currentAccountTabs: [Tab] {
|
||||
[.statuses, .replies, .boosts, .favorites, .bookmarks]
|
||||
|
@ -25,6 +25,10 @@ import SwiftUI
|
|||
static var accountTabs: [Tab] {
|
||||
[.statuses, .replies, .boosts, .media]
|
||||
}
|
||||
|
||||
static var premiumAccountTabs: [Tab] {
|
||||
[.statuses, .premiumPosts, .replies, .boosts, .media]
|
||||
}
|
||||
|
||||
var iconName: String {
|
||||
switch self {
|
||||
|
@ -34,6 +38,7 @@ import SwiftUI
|
|||
case .replies: "bubble.left.and.bubble.right"
|
||||
case .boosts: ""
|
||||
case .media: "photo.on.rectangle.angled"
|
||||
case .premiumPosts: "dollarsign"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,9 +50,21 @@ import SwiftUI
|
|||
case .replies: "accessibility.tabs.profile.picker.posts-and-replies"
|
||||
case .boosts: "accessibility.tabs.profile.picker.boosts"
|
||||
case .media: "accessibility.tabs.profile.picker.media"
|
||||
case .premiumPosts: "Premium Posts"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var tabs: [Tab] {
|
||||
if isCurrentUser {
|
||||
return Tab.currentAccountTabs
|
||||
} else if account?.isLinkedToPremiumAccount == true && premiumAccount != nil {
|
||||
return Tab.premiumAccountTabs
|
||||
} else {
|
||||
return Tab.accountTabs
|
||||
}
|
||||
}
|
||||
|
||||
var accountState: AccountState = .loading
|
||||
var statusesState: StatusesState = .loading
|
||||
|
@ -68,7 +85,7 @@ import SwiftUI
|
|||
var selectedTab = Tab.statuses {
|
||||
didSet {
|
||||
switch selectedTab {
|
||||
case .statuses, .replies, .boosts, .media:
|
||||
case .statuses, .replies, .boosts, .media, .premiumPosts:
|
||||
tabTask?.cancel()
|
||||
tabTask = Task {
|
||||
await fetchNewestStatuses(pullToRefresh: false)
|
||||
|
@ -172,8 +189,12 @@ import SwiftUI
|
|||
do {
|
||||
statusesState = .loading
|
||||
boosts = []
|
||||
var accountIdToFetch = accountId
|
||||
if selectedTab == .premiumPosts, let accountId = premiumAccount?.id {
|
||||
accountIdToFetch = accountId
|
||||
}
|
||||
statuses =
|
||||
try await client.get(endpoint: Accounts.statuses(id: accountId,
|
||||
try await client.get(endpoint: Accounts.statuses(id: accountIdToFetch,
|
||||
sinceId: nil,
|
||||
tag: nil,
|
||||
onlyMedia: selectedTab == .media,
|
||||
|
@ -210,10 +231,14 @@ import SwiftUI
|
|||
func fetchNextPage() async throws {
|
||||
guard let client else { return }
|
||||
switch selectedTab {
|
||||
case .statuses, .replies, .boosts, .media:
|
||||
case .statuses, .replies, .boosts, .media, .premiumPosts:
|
||||
guard let lastId = statuses.last?.id else { return }
|
||||
var accountIdToFetch = accountId
|
||||
if selectedTab == .premiumPosts, let accountId = premiumAccount?.id {
|
||||
accountIdToFetch = accountId
|
||||
}
|
||||
let newStatuses: [Status] =
|
||||
try await client.get(endpoint: Accounts.statuses(id: accountId,
|
||||
try await client.get(endpoint: Accounts.statuses(id: accountIdToFetch,
|
||||
sinceId: lastId,
|
||||
tag: nil,
|
||||
onlyMedia: selectedTab == .media,
|
||||
|
@ -252,7 +277,7 @@ import SwiftUI
|
|||
|
||||
private func reloadTabState() {
|
||||
switch selectedTab {
|
||||
case .statuses, .replies, .media:
|
||||
case .statuses, .replies, .media, .premiumPosts:
|
||||
statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||
case .boosts:
|
||||
statusesState = .display(statuses: boosts, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||
|
@ -301,7 +326,7 @@ extension AccountDetailViewModel {
|
|||
forceVersion: .v2)
|
||||
if let premiumAccount = results?.accounts.first {
|
||||
self.premiumAccount = premiumAccount
|
||||
var relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [premiumAccount.id]))
|
||||
let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [premiumAccount.id]))
|
||||
self.premiumRelationship = relationships.first
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public struct StatusRowView: View {
|
|||
@Environment(\.accessibilityVoiceOverEnabled) private var accessibilityVoiceOverEnabled
|
||||
@Environment(\.isStatusFocused) private var isFocused
|
||||
@Environment(\.indentationLevel) private var indentationLevel
|
||||
|
||||
@Environment(RouterPath.self) private var routerPath: RouterPath
|
||||
|
||||
@Environment(QuickLook.self) private var quickLook
|
||||
@Environment(Theme.self) private var theme
|
||||
@Environment(Client.self) private var client
|
||||
|
|
|
@ -3,10 +3,12 @@ import Env
|
|||
import SwiftUI
|
||||
|
||||
struct StatusRowPremiumView: View {
|
||||
@Environment(\.isHomeTimeline) private var isHomeTimeline
|
||||
|
||||
let viewModel: StatusRowViewModel
|
||||
|
||||
var body: some View {
|
||||
if viewModel.status.account.isPremiumAccount {
|
||||
if isHomeTimeline, viewModel.status.account.isPremiumAccount {
|
||||
Text("From a subscribed premium account")
|
||||
.font(.scaledFootnote)
|
||||
.foregroundStyle(.secondary)
|
||||
|
|
Loading…
Reference in a new issue