IceCubesApp/IceCubesApp/App/Tabs/Settings/InstanceInfoView.swift

62 lines
1.7 KiB
Swift
Raw Normal View History

2022-12-29 13:07:58 +00:00
import DesignSystem
2023-01-17 10:36:01 +00:00
import Models
2022-12-29 13:07:58 +00:00
import NukeUI
2023-01-17 10:36:01 +00:00
import SwiftUI
2022-12-29 13:07:58 +00:00
struct InstanceInfoView: View {
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2023-01-17 10:36:01 +00:00
2022-12-29 13:07:58 +00:00
let instance: Instance
2023-01-17 10:36:01 +00:00
2022-12-29 13:07:58 +00:00
var body: some View {
2023-01-06 16:14:34 +00:00
Form {
2023-01-07 17:12:56 +00:00
InstanceInfoSection(instance: instance)
2022-12-29 13:07:58 +00:00
}
.navigationTitle("instance.info.navigation-title")
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-01-06 16:14:34 +00:00
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2022-12-29 13:07:58 +00:00
}
}
2023-01-07 17:12:56 +00:00
public struct InstanceInfoSection: View {
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2023-01-17 10:36:01 +00:00
2023-01-07 17:12:56 +00:00
let instance: Instance
2023-01-17 10:36:01 +00:00
2023-01-07 17:12:56 +00:00
public var body: some View {
Section("instance.info.section.info") {
LabeledContent("instance.info.name", value: instance.title)
2023-01-07 17:12:56 +00:00
Text(instance.shortDescription)
LabeledContent("instance.info.email", value: instance.email)
LabeledContent("instance.info.version") {
Text(instance.version).monospaced()
}
LabeledContent("instance.info.users", value: format(instance.stats.userCount))
LabeledContent("instance.info.posts", value: format(instance.stats.statusCount))
LabeledContent("instance.info.domains", value: format(instance.stats.domainCount))
2023-01-07 17:12:56 +00:00
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-01-07 17:12:56 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-01-17 10:36:01 +00:00
2023-01-18 18:10:45 +00:00
if let rules = instance.rules {
Section("instance.info.section.rules") {
2023-01-18 18:10:45 +00:00
ForEach(rules) { rule in
Text(rule.text.trimmingCharacters(in: .whitespacesAndNewlines))
2023-01-18 18:10:45 +00:00
}
2023-01-07 17:12:56 +00:00
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-01-18 18:10:45 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-01-07 17:12:56 +00:00
}
}
2023-02-26 05:45:57 +00:00
private func format(_ int: Int) -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter.string(from: NSNumber(value: int))!
}
2023-01-07 17:12:56 +00:00
}