// // https://mczachurski.dev // Copyright © 2023 Marcin Czachurski and the repository contributors. // Licensed under the MIT License. // import SwiftUI import PixelfedKit import NukeUI struct InstanceRow: View { @EnvironmentObject var routerPath: RouterPath private let instance: Instance private let action: (String) -> Void public init(instance: Instance, action: @escaping (String) -> Void) { self.instance = instance self.action = action } var body: some View { VStack(alignment: .leading) { HStack(alignment: .center) { LazyImage(url: instance.thumbnail) { state in if let image = state.image { image .clipShape(RoundedRectangle(cornerRadius: 4)) .aspectRatio(contentMode: .fit) } else if state.isLoading { placeholderView } else { placeholderView } } .priority(.high) .frame(width: 50, height: 50) HStack(alignment: .center) { VStack(alignment: .leading) { Text(instance.title ?? "") .font(.headline) .fontWeight(.bold) Text(instance.uri) .font(.subheadline) } Spacer() Button("Sign in") { HapticService.shared.fireHaptic(of: .buttonPress) self.action(instance.uri) } .buttonStyle(.borderedProminent) .padding(.vertical, 4) } } if let description = instance.description { MarkdownFormattedText(description.asMarkdown, withFontSize: 14) .environment(\.openURL, OpenURLAction { url in routerPath.handle(url: url) }) } if let stats = instance.stats { HStack { Image(systemName: "person.2.fill") Text("\(stats.userCount) users") Image(systemName: "photo.stack.fill") Text("\(stats.statusCount) posts") Spacer() } .padding(.top, 4) .foregroundColor(.lightGrayColor) .font(.caption) } } } @ViewBuilder private var placeholderView: some View { Image("PixelfedInstance") .resizable() .clipShape(RoundedRectangle(cornerRadius: 4)) .aspectRatio(contentMode: .fit) .frame(width: 50, height: 50) } }