mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-23 15:40:37 +00:00
Account: Internal isCurrentUser
This commit is contained in:
parent
0ac109c49b
commit
ee39840713
4 changed files with 10 additions and 12 deletions
|
@ -14,7 +14,7 @@ struct AccountTab: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack(path: $routeurPath.path) {
|
NavigationStack(path: $routeurPath.path) {
|
||||||
if let account = currentAccount.account {
|
if let account = currentAccount.account {
|
||||||
AccountDetailView(account: account, isCurrentUser: true)
|
AccountDetailView(account: account)
|
||||||
.withAppRouteur()
|
.withAppRouteur()
|
||||||
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,20 +17,16 @@ public struct AccountDetailView: View {
|
||||||
@StateObject private var viewModel: AccountDetailViewModel
|
@StateObject private var viewModel: AccountDetailViewModel
|
||||||
@State private var scrollOffset: CGFloat = 0
|
@State private var scrollOffset: CGFloat = 0
|
||||||
@State private var isFieldsSheetDisplayed: Bool = false
|
@State private var isFieldsSheetDisplayed: Bool = false
|
||||||
|
@State private var isCurrentUser: Bool = false
|
||||||
private let isCurrentUser: Bool
|
|
||||||
|
|
||||||
/// When coming from a URL like a mention tap in a status.
|
/// When coming from a URL like a mention tap in a status.
|
||||||
public init(accountId: String) {
|
public init(accountId: String) {
|
||||||
_viewModel = StateObject(wrappedValue: .init(accountId: accountId))
|
_viewModel = StateObject(wrappedValue: .init(accountId: accountId))
|
||||||
isCurrentUser = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When the account is already fetched by the parent caller.
|
/// When the account is already fetched by the parent caller.
|
||||||
public init(account: Account, isCurrentUser: Bool = false) {
|
public init(account: Account) {
|
||||||
_viewModel = StateObject(wrappedValue: .init(account: account,
|
_viewModel = StateObject(wrappedValue: .init(account: account))
|
||||||
isCurrentUser: isCurrentUser))
|
|
||||||
self.isCurrentUser = isCurrentUser
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
|
@ -72,6 +68,8 @@ public struct AccountDetailView: View {
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
guard reasons != .placeholder else { return }
|
guard reasons != .placeholder else { return }
|
||||||
|
isCurrentUser = currentAccount.account?.id == viewModel.accountId
|
||||||
|
viewModel.isCurrentUser = isCurrentUser
|
||||||
viewModel.client = client
|
viewModel.client = client
|
||||||
await viewModel.fetchAccount()
|
await viewModel.fetchAccount()
|
||||||
if viewModel.statuses.isEmpty {
|
if viewModel.statuses.isEmpty {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Env
|
||||||
class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
||||||
let accountId: String
|
let accountId: String
|
||||||
var client: Client?
|
var client: Client?
|
||||||
|
var isCurrentUser: Bool = false
|
||||||
|
|
||||||
enum AccountState {
|
enum AccountState {
|
||||||
case loading, data(account: Account), error(error: Error)
|
case loading, data(account: Account), error(error: Error)
|
||||||
|
@ -62,7 +63,6 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
||||||
private var account: Account?
|
private var account: Account?
|
||||||
|
|
||||||
private(set) var statuses: [Status] = []
|
private(set) var statuses: [Status] = []
|
||||||
private let isCurrentUser: Bool
|
|
||||||
|
|
||||||
/// When coming from a URL like a mention tap in a status.
|
/// When coming from a URL like a mention tap in a status.
|
||||||
init(accountId: String) {
|
init(accountId: String) {
|
||||||
|
@ -71,10 +71,9 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When the account is already fetched by the parent caller.
|
/// When the account is already fetched by the parent caller.
|
||||||
init(account: Account, isCurrentUser: Bool) {
|
init(account: Account) {
|
||||||
self.accountId = account.id
|
self.accountId = account.id
|
||||||
self.accountState = .data(account: account)
|
self.accountState = .data(account: account)
|
||||||
self.isCurrentUser = isCurrentUser
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchAccount() async {
|
func fetchAccount() async {
|
||||||
|
|
|
@ -128,7 +128,8 @@ class TimelineViewModel: ObservableObject, StatusesFetcher {
|
||||||
statuses.insert(event.status, at: 0)
|
statuses.insert(event.status, at: 0)
|
||||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||||
} else if pendingStatusesEnabled,
|
} else if pendingStatusesEnabled,
|
||||||
!statuses.contains(where: { $0.id == event.status.id }) {
|
!statuses.contains(where: { $0.id == event.status.id }),
|
||||||
|
!pendingStatuses.contains(where: { $0.id == event.status.id }){
|
||||||
pendingStatuses.insert(event.status, at: 0)
|
pendingStatuses.insert(event.status, at: 0)
|
||||||
pendingStatusesState = .stream
|
pendingStatusesState = .stream
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue