Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SettingsView public #68

Merged
merged 1 commit into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/PulseUI/Features/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ extension MainViewModel {
}
#endif
#if os(iOS) || os(tvOS)
case .settings: SettingsView(model: settingsModel, console: consoleModel)
case .settings:
NavigationView {
SettingsView(model: settingsModel, console: consoleModel)
}
#endif
default: fatalError()
}
Expand Down
118 changes: 63 additions & 55 deletions Sources/PulseUI/Features/Settings/SettingsView-ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,87 @@ import PulseCore
import UniformTypeIdentifiers

@available(iOS 13.0, *)
struct SettingsView: View {
public struct SettingsView: View {
@ObservedObject var model: SettingsViewModel
@ObservedObject var console: ConsoleViewModel

@State private var isDocumentBrowserPresented = false

var body: some View {
NavigationView {
Form {
if let details = model.details {
Section {
NavigationLink(destination: StoreDetailsView(model: details)) {
HStack {
Image(systemName: "info.circle")
.foregroundColor(Color.primary)
Text("Store Info")
.foregroundColor(Color.primary)
}
public init(store: LoggerStore = .default) {
self.model = SettingsViewModel(store: store)
self.console = ConsoleViewModel(store: store, contentType: .all)
}

init(model: SettingsViewModel, console: ConsoleViewModel) {
self.model = model
self.console = console
}

public var body: some View {
Form {
if let details = model.details {
Section {
NavigationLink(destination: StoreDetailsView(model: details)) {
HStack {
Image(systemName: "info.circle")
.foregroundColor(Color.primary)
Text("Store Info")
.foregroundColor(Color.primary)
}
}
}
}

if !model.isReadonly {
Section {
if #available(iOS 14.0, *) {
Button(action: {
isDocumentBrowserPresented = true
}) {
HStack {
Image(systemName: "doc")
.foregroundColor(Color.primary)
Text("Browse Files")
.foregroundColor(Color.primary)
}
}
.fullScreenCover(isPresented: $isDocumentBrowserPresented) {
DocumentBrowser()
}
}

ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
if !model.isReadonly {
Section {
if #available(iOS 14.0, *) {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
Button(action: {
isDocumentBrowserPresented = true
}) {
HStack {
Image(systemName: "doc")
.foregroundColor(Color.primary)
Text("Browse Files")
.foregroundColor(Color.primary)
}
}
.fullScreenCover(isPresented: $isDocumentBrowserPresented) {
DocumentBrowser()
}
}

ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
if let url = URL(string: "/~https://github.com/sponsors/kean") {
UIApplication.shared.open(url)
}
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
if #available(iOS 14.0, *) {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
}
}
}
.navigationBarTitle("Settings")
.navigationBarItems(leading: model.onDismiss.map { Button(action: $0) { Image(systemName: "xmark") } })
}.navigationViewStyle(StackNavigationViewStyle())
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
if let url = URL(string: "/~https://github.com/sponsors/kean") {
UIApplication.shared.open(url)
}
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
}
}
.navigationBarTitle("Settings")
.navigationBarItems(leading: model.onDismiss.map { Button(action: $0) { Image(systemName: "xmark") } })
}
}

Expand Down
65 changes: 36 additions & 29 deletions Sources/PulseUI/Features/Settings/SettingsView-tvos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,49 @@ struct SettingsView: View {

@State var isSponsorAlertShown = false

var body: some View {
NavigationView {
Form {
if !model.isReadonly {
Section {
ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
}
public init(store: LoggerStore = .default) {
self.model = SettingsViewModel(store: store)
self.console = ConsoleViewModel(store: store, contentType: .all)
}

init(model: SettingsViewModel, console: ConsoleViewModel) {
self.model = model
self.console = console
}

public var body: some View {
Form {
if !model.isReadonly {
Section {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
}
Section {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
isSponsorAlertShown = true
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
isSponsorAlertShown = true
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
}
.frame(maxWidth: 800)
}
.navigationViewStyle(StackNavigationViewStyle())
.frame(maxWidth: 800)
.alert(isPresented: $isSponsorAlertShown, content: {
Alert(title: Text("Sponsor"), message: Text("Please visit /~https://github.com/sponsors/kean to sponsor"), dismissButton: .cancel(Text("Ok")))
})
Expand Down