Update MainView.swift
This commit is contained in:
parent
8f426bd719
commit
0753d91f29
@ -33,13 +33,16 @@ struct MainView: App {
|
||||
|
||||
private let detailWidth: CGFloat = 300
|
||||
|
||||
@StateObject
|
||||
private var server: WebServer = .init(port: 8000)
|
||||
|
||||
@StateObject
|
||||
private var content: Content = .init()
|
||||
|
||||
@State
|
||||
private var language: ContentLanguage = .english
|
||||
|
||||
@ObservedObject
|
||||
@StateObject
|
||||
private var selection: SelectedContent = .init()
|
||||
|
||||
@State
|
||||
@ -64,6 +67,7 @@ struct MainView: App {
|
||||
case .pages: PageListView()
|
||||
case .tags: TagListView()
|
||||
case .files: FileListView(selectedFile: $selection.file)
|
||||
case .browser: EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +82,9 @@ struct MainView: App {
|
||||
SelectedContentView<TagContentView>(selected: $selection.tag)
|
||||
case .files:
|
||||
SelectedContentView<FileContentView>(selected: $selection.file)
|
||||
case .browser:
|
||||
WebContentView()
|
||||
.environmentObject(server)
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,13 +99,16 @@ struct MainView: App {
|
||||
SelectedDetailView<TagDetailView>(selected: $selection.tag)
|
||||
case .files:
|
||||
SelectedDetailView<FileDetailView>(selected: $selection.file)
|
||||
case .browser:
|
||||
WebDetailView()
|
||||
.environmentObject(server)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
var addItemSheet: some View {
|
||||
switch selection.tab {
|
||||
case .posts:
|
||||
case .posts, .browser:
|
||||
AddPostView(selected: $selection.post)
|
||||
case .pages:
|
||||
AddPageView(selected: $selection.page)
|
||||
@ -131,6 +141,7 @@ struct MainView: App {
|
||||
Text("Pages").tag(MainViewTab.pages)
|
||||
Text("Tags").tag(MainViewTab.tags)
|
||||
Text("Files").tag(MainViewTab.files)
|
||||
Text("Preview").tag(MainViewTab.browser)
|
||||
}.pickerStyle(.segmented)
|
||||
}.frame(minWidth: 400)
|
||||
}
|
||||
@ -167,6 +178,11 @@ struct MainView: App {
|
||||
}
|
||||
}
|
||||
}
|
||||
ToolbarItem {
|
||||
Button(action: toggleWebServer) {
|
||||
Image(systemSymbol: server.isRunning ? .eye : .eyeSlash)
|
||||
}
|
||||
}
|
||||
ToolbarItem {
|
||||
Button(action: saveButtonPressed) {
|
||||
Image(systemSymbol: content.saveState.symbol)
|
||||
@ -251,5 +267,18 @@ struct MainView: App {
|
||||
showInitialSetupSheet = true
|
||||
}
|
||||
}
|
||||
|
||||
private func toggleWebServer() {
|
||||
guard !server.isRunning else {
|
||||
server.stopServer()
|
||||
return
|
||||
}
|
||||
guard let folder = content.storage.outputScope?.url.path() else {
|
||||
print("No output folder to start server")
|
||||
return
|
||||
}
|
||||
|
||||
server.startServer(in: folder)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user