mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-14 05:21:12 +00:00
Better view separation for StatusRowView
This commit is contained in:
parent
b963a74dc4
commit
2083f72b2b
2 changed files with 95 additions and 83 deletions
|
@ -5,7 +5,6 @@ import Network
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct StatusActionsView: View {
|
struct StatusActionsView: View {
|
||||||
@Environment(\.openURL) private var openURL
|
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
@EnvironmentObject private var routerPath: RouterPath
|
@EnvironmentObject private var routerPath: RouterPath
|
||||||
@ObservedObject var viewModel: StatusRowViewModel
|
@ObservedObject var viewModel: StatusRowViewModel
|
||||||
|
@ -91,92 +90,11 @@ struct StatusActionsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if viewModel.isFocused {
|
if viewModel.isFocused {
|
||||||
summaryView
|
StatusRowDetailView(viewModel: viewModel)
|
||||||
.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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
private func handleAction(action: Actions) {
|
||||||
Task {
|
Task {
|
||||||
HapticManager.shared.fireHaptic(of: .notification(.success))
|
HapticManager.shared.fireHaptic(of: .notification(.success))
|
||||||
|
|
94
Packages/Status/Sources/Status/Row/StatusRowDetailView.swift
Normal file
94
Packages/Status/Sources/Status/Row/StatusRowDetailView.swift
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue