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

56 lines
1.6 KiB
Swift
Raw Normal View History

2022-12-29 14:07:58 +01:00
import DesignSystem
2023-01-17 11:36:01 +01:00
import Models
2022-12-29 14:07:58 +01:00
import NukeUI
2023-01-17 11:36:01 +01:00
import SwiftUI
2022-12-29 14:07:58 +01:00
struct InstanceInfoView: View {
@EnvironmentObject private var theme: Theme
2023-01-17 11:36:01 +01:00
2022-12-29 14:07:58 +01:00
let instance: Instance
2023-01-17 11:36:01 +01:00
2022-12-29 14:07:58 +01:00
var body: some View {
2023-01-06 17:14:34 +01:00
Form {
2023-01-07 18:12:56 +01:00
InstanceInfoSection(instance: instance)
2022-12-29 14:07:58 +01:00
}
.navigationTitle("instance.info.navigation-title")
2023-01-06 17:14:34 +01:00
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
2022-12-29 14:07:58 +01:00
}
}
2023-01-07 18:12:56 +01:00
public struct InstanceInfoSection: View {
@EnvironmentObject private var theme: Theme
2023-01-17 11:36:01 +01:00
2023-01-07 18:12:56 +01:00
let instance: Instance
2023-01-17 11:36:01 +01:00
2023-01-07 18:12:56 +01:00
public var body: some View {
Section("instance.info.section.info") {
LabeledContent("instance.info.name", value: instance.title)
2023-01-07 18:12:56 +01: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 18:12:56 +01:00
}
.listRowBackground(theme.primaryBackgroundColor)
2023-01-17 11:36:01 +01:00
2023-01-18 19:10:45 +01:00
if let rules = instance.rules {
Section("instance.info.section.rules") {
2023-01-18 19:10:45 +01:00
ForEach(rules) { rule in
Text(rule.text.trimmingCharacters(in: .whitespacesAndNewlines))
2023-01-18 19:10:45 +01:00
}
2023-01-07 18:12:56 +01:00
}
2023-01-18 19:10:45 +01:00
.listRowBackground(theme.primaryBackgroundColor)
2023-01-07 18:12:56 +01:00
}
}
2023-02-26 06:45:57 +01:00
private func format(_ int: Int) -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter.string(from: NSNumber(value: int))!
}
2023-01-07 18:12:56 +01:00
}