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