2023-02-01 13:22:43 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2023-02-19 10:32:38 +01:00
|
|
|
import PixelfedKit
|
2023-02-01 13:22:43 +01:00
|
|
|
import NukeUI
|
|
|
|
|
|
|
|
struct InstanceRow: View {
|
2023-02-19 12:49:44 +01:00
|
|
|
@EnvironmentObject var routerPath: RouterPath
|
|
|
|
|
2023-02-01 13:22:43 +01:00
|
|
|
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") {
|
2023-02-19 12:49:44 +01:00
|
|
|
HapticService.shared.fireHaptic(of: .buttonPress)
|
2023-02-01 13:22:43 +01:00
|
|
|
self.action(instance.uri)
|
|
|
|
}
|
|
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-19 12:49:44 +01:00
|
|
|
if let description = instance.description {
|
|
|
|
MarkdownFormattedText(description.asMarkdown, withFontSize: 14)
|
|
|
|
.environment(\.openURL, OpenURLAction { url in
|
|
|
|
routerPath.handle(url: url)
|
|
|
|
})
|
|
|
|
}
|
2023-02-19 12:11:25 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2023-02-01 13:22:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var placeholderView: some View {
|
|
|
|
Image("PixelfedInstance")
|
|
|
|
.resizable()
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 4))
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
.frame(width: 50, height: 50)
|
|
|
|
}
|
|
|
|
}
|