mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-28 06:50:08 +01:00
♻️ Cleaned up view a lot more, fix initial state
This commit is contained in:
@@ -11,18 +11,6 @@ import SwiftUI
|
|||||||
struct StartupAlertView: View {
|
struct StartupAlertView: View {
|
||||||
@ObservedObject var viewModel: StartupAlertViewModel
|
@ObservedObject var viewModel: StartupAlertViewModel
|
||||||
|
|
||||||
/// Whether the bottom section (description text and/or past output) has content to display.
|
|
||||||
/// This is used to conditionally show the section and its divider,
|
|
||||||
/// avoiding empty padded sections and double dividers.
|
|
||||||
private var hasBottomContent: Bool {
|
|
||||||
let hasDescription = !viewModel.check.descriptionText.isEmpty && viewModel.state == .idle
|
|
||||||
|
|
||||||
let hasOutput = !viewModel.outputLines.isEmpty
|
|
||||||
&& (viewModel.state == .idle || viewModel.state == .completed)
|
|
||||||
|
|
||||||
return hasDescription || hasOutput
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
StartupAlertHeaderView(
|
StartupAlertHeaderView(
|
||||||
@@ -30,44 +18,35 @@ struct StartupAlertView: View {
|
|||||||
subtitleText: viewModel.check.subtitleText
|
subtitleText: viewModel.check.subtitleText
|
||||||
)
|
)
|
||||||
|
|
||||||
if viewModel.state == .running
|
// Fix command description: only shown in idle state when a fix is available
|
||||||
|| viewModel.state == .failed
|
if viewModel.state == .idle && viewModel.hasFix {
|
||||||
|| (viewModel.hasFix && viewModel.state == .idle) {
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
|
||||||
if viewModel.state == .running || viewModel.state == .failed {
|
|
||||||
StartupOutputView(
|
|
||||||
lines: viewModel.outputLines,
|
|
||||||
isRunning: viewModel.state == .running
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
StartupFixCommandView(
|
StartupFixCommandView(
|
||||||
command: viewModel.check.fixDescription ?? ""
|
command: viewModel.check.fixDescription ?? ""
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(15)
|
.padding(15)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasBottomContent {
|
// Terminal output: shown during and after fix execution
|
||||||
|
if !viewModel.outputLines.isEmpty
|
||||||
|
&& (viewModel.state == .running || viewModel.state == .completed || viewModel.state == .failed) {
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
|
||||||
if !viewModel.check.descriptionText.isEmpty,
|
|
||||||
viewModel.state == .idle {
|
|
||||||
MarkdownTextView(viewModel.check.descriptionText, fontSize: 12)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !viewModel.outputLines.isEmpty,
|
|
||||||
viewModel.state == .idle || viewModel.state == .completed {
|
|
||||||
StartupOutputView(
|
StartupOutputView(
|
||||||
lines: viewModel.outputLines,
|
lines: viewModel.outputLines,
|
||||||
isRunning: false
|
isRunning: viewModel.state == .running
|
||||||
)
|
)
|
||||||
|
.padding(15)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Description text: shown in idle state
|
||||||
|
if !viewModel.check.descriptionText.isEmpty && viewModel.state == .idle {
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
MarkdownTextView(viewModel.check.descriptionText, fontSize: 12)
|
||||||
.padding(15)
|
.padding(15)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class StartupAlertViewModel: ObservableObject {
|
|||||||
|
|
||||||
init(check: EnvironmentCheck) {
|
init(check: EnvironmentCheck) {
|
||||||
self.check = check
|
self.check = check
|
||||||
self.state = check.fixCommand != nil ? .idle : .completed
|
self.state = .idle
|
||||||
}
|
}
|
||||||
|
|
||||||
init(check: EnvironmentCheck, state: State, outputLines: [OutputLine] = []) {
|
init(check: EnvironmentCheck, state: State, outputLines: [OutputLine] = []) {
|
||||||
|
|||||||
Reference in New Issue
Block a user