From 2083f72b2b0a203ae2974177c65351c895d6d5a1 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Fri, 10 Feb 2023 12:12:22 +0100 Subject: [PATCH] Better view separation for StatusRowView --- .../Status/Row/StatusActionsView.swift | 84 +---------------- .../Status/Row/StatusRowDetailView.swift | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 83 deletions(-) create mode 100644 Packages/Status/Sources/Status/Row/StatusRowDetailView.swift diff --git a/Packages/Status/Sources/Status/Row/StatusActionsView.swift b/Packages/Status/Sources/Status/Row/StatusActionsView.swift index 95a414d9..9d265b6c 100644 --- a/Packages/Status/Sources/Status/Row/StatusActionsView.swift +++ b/Packages/Status/Sources/Status/Row/StatusActionsView.swift @@ -5,7 +5,6 @@ import Network import SwiftUI struct StatusActionsView: View { - @Environment(\.openURL) private var openURL @EnvironmentObject private var theme: Theme @EnvironmentObject private var routerPath: RouterPath @ObservedObject var viewModel: StatusRowViewModel @@ -91,92 +90,11 @@ struct StatusActionsView: View { } } if viewModel.isFocused { - summaryView - .task { - await viewModel.fetchActionsAccounts() - } - } - } - } - - @ViewBuilder - private var summaryView: some View { - Divider() - HStack { - Text(viewModel.status.createdAt.asDate, style: .date) + - Text("status.summary.at-time") + - Text(viewModel.status.createdAt.asDate, style: .time) + - Text(" ·") - Image(systemName: viewModel.status.visibility.iconName) - Spacer() - Text(viewModel.status.application?.name ?? "") - .underline() - .onTapGesture { - if let url = viewModel.status.application?.website { - openURL(url) - } - } - } - .font(.scaledCaption) - .foregroundColor(.gray) - - if let editedAt = viewModel.status.editedAt { - Divider() - HStack { - Text("status.summary.edited-time") + - Text(editedAt.asDate, style: .date) + - Text("status.summary.at-time") + - Text(editedAt.asDate, style: .time) - Spacer() - } - .onTapGesture { - routerPath.presentedSheet = .statusEditHistory(status: viewModel.status.id) - } - .underline() - .font(.scaledCaption) - .foregroundColor(.gray) - } - - if viewModel.favoritesCount > 0 { - Divider() - NavigationLink(value: RouterDestinations.favoritedBy(id: viewModel.status.id)) { - HStack { - Text("status.summary.n-favorites \(viewModel.favoritesCount)") - .font(.scaledCallout) - Spacer() - makeAccountsScrollView(accounts: viewModel.favoriters) - Image(systemName: "chevron.right") - } - .frame(height: 20) - } - } - if viewModel.reblogsCount > 0 { - Divider() - NavigationLink(value: RouterDestinations.rebloggedBy(id: viewModel.status.id)) { - HStack { - Text("status.summary.n-boosts \(viewModel.reblogsCount)") - .font(.scaledCallout) - Spacer() - makeAccountsScrollView(accounts: viewModel.rebloggers) - Image(systemName: "chevron.right") - } - .frame(height: 20) + StatusRowDetailView(viewModel: viewModel) } } } - private func makeAccountsScrollView(accounts: [Account]) -> some View { - ScrollView(.horizontal, showsIndicators: false) { - LazyHStack(spacing: 0) { - ForEach(accounts) { account in - AvatarView(url: account.avatar, size: .list) - .padding(.leading, -4) - } - } - .padding(.leading, .layoutPadding) - } - } - private func handleAction(action: Actions) { Task { HapticManager.shared.fireHaptic(of: .notification(.success)) diff --git a/Packages/Status/Sources/Status/Row/StatusRowDetailView.swift b/Packages/Status/Sources/Status/Row/StatusRowDetailView.swift new file mode 100644 index 00000000..36dbe0de --- /dev/null +++ b/Packages/Status/Sources/Status/Row/StatusRowDetailView.swift @@ -0,0 +1,94 @@ +import SwiftUI +import Env +import DesignSystem +import Models + +struct StatusRowDetailView: View { + @Environment(\.openURL) private var openURL + @EnvironmentObject private var routerPath: RouterPath + + @ObservedObject var viewModel: StatusRowViewModel + + var body: some View { + Group { + Divider() + HStack { + Text(viewModel.status.createdAt.asDate, style: .date) + + Text("status.summary.at-time") + + Text(viewModel.status.createdAt.asDate, style: .time) + + Text(" ·") + Image(systemName: viewModel.status.visibility.iconName) + Spacer() + Text(viewModel.status.application?.name ?? "") + .underline() + .onTapGesture { + if let url = viewModel.status.application?.website { + openURL(url) + } + } + } + .font(.scaledCaption) + .foregroundColor(.gray) + + if let editedAt = viewModel.status.editedAt { + Divider() + HStack { + Text("status.summary.edited-time") + + Text(editedAt.asDate, style: .date) + + Text("status.summary.at-time") + + Text(editedAt.asDate, style: .time) + Spacer() + } + .onTapGesture { + routerPath.presentedSheet = .statusEditHistory(status: viewModel.status.id) + } + .underline() + .font(.scaledCaption) + .foregroundColor(.gray) + } + + if viewModel.favoritesCount > 0 { + Divider() + NavigationLink(value: RouterDestinations.favoritedBy(id: viewModel.status.id)) { + HStack { + Text("status.summary.n-favorites \(viewModel.favoritesCount)") + .font(.scaledCallout) + Spacer() + makeAccountsScrollView(accounts: viewModel.favoriters) + Image(systemName: "chevron.right") + } + .frame(height: 20) + } + } + if viewModel.reblogsCount > 0 { + Divider() + NavigationLink(value: RouterDestinations.rebloggedBy(id: viewModel.status.id)) { + HStack { + Text("status.summary.n-boosts \(viewModel.reblogsCount)") + .font(.scaledCallout) + Spacer() + makeAccountsScrollView(accounts: viewModel.rebloggers) + Image(systemName: "chevron.right") + } + .frame(height: 20) + } + } + } + .task { + await viewModel.fetchActionsAccounts() + } + } + + private func makeAccountsScrollView(accounts: [Account]) -> some View { + ScrollView(.horizontal, showsIndicators: false) { + LazyHStack(spacing: 0) { + ForEach(accounts) { account in + AvatarView(url: account.avatar, size: .list) + .padding(.leading, -4) + } + } + .padding(.leading, .layoutPadding) + } + } + +}