NetNewsWire/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift

106 lines
2.6 KiB
Swift
Raw Normal View History

//
// SidebarToolbarModifier.swift
// Multiplatform iOS
//
// Created by Stuart Breckenridge on 30/6/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
struct SidebarToolbarModifier: ViewModifier {
2020-07-03 18:06:43 +02:00
@EnvironmentObject private var refreshProgress: RefreshProgressModel
@EnvironmentObject private var defaults: AppDefaults
@EnvironmentObject private var sidebarModel: SidebarModel
@StateObject private var viewModel = SidebarToolbarModel()
2020-07-03 18:06:43 +02:00
@ViewBuilder func body(content: Content) -> some View {
#if os(iOS)
content
.toolbar {
2020-07-05 22:11:45 +02:00
ToolbarItem(placement: .primaryAction) {
Button {
2020-07-12 17:52:42 +02:00
withAnimation {
sidebarModel.isReadFiltered.toggle()
}
} label: {
2020-07-12 17:52:42 +02:00
if sidebarModel.isReadFiltered {
AppAssets.filterActiveImage.font(.title3)
} else {
AppAssets.filterInactiveImage.font(.title3)
}
}
.help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds")
2020-07-05 22:11:45 +02:00
}
ToolbarItem(placement: .bottomBar) {
Button {
viewModel.sheetToShow = .settings
} label: {
AppAssets.settingsImage.font(.title3)
}
.help("Settings")
}
2020-07-03 18:06:43 +02:00
ToolbarItem(placement: .bottomBar) {
Spacer()
}
ToolbarItem(placement: .bottomBar) {
switch refreshProgress.state {
case .refreshProgress(let progress):
ProgressView(value: progress)
.frame(width: 100)
case .lastRefreshDateText(let text):
Text(text)
.lineLimit(1)
.font(.caption)
.foregroundColor(.secondary)
case .none:
EmptyView()
}
}
ToolbarItem(placement: .bottomBar) {
Spacer()
}
2020-07-03 18:06:43 +02:00
ToolbarItem(placement: .bottomBar, content: {
2020-07-27 10:09:39 +02:00
Menu(content: {
Button { viewModel.sheetToShow = .web } label: { Text("Add Web Feed") }
2020-07-27 10:13:07 +02:00
Button { viewModel.sheetToShow = .twitter } label: { Text("Add Twitter Feed") }
Button { viewModel.sheetToShow = .reddit } label: { Text("Add Reddit Feed") }
2020-07-27 10:09:39 +02:00
Button { viewModel.sheetToShow = .folder } label: { Text("Add Folder") }
}, label: {
AppAssets.addMenuImage.font(.title3)
2020-07-27 10:09:39 +02:00
})
})
}
.sheet(isPresented: $viewModel.showSheet, onDismiss: { viewModel.sheetToShow = .none }) {
if viewModel.sheetToShow == .web {
AddWebFeedView(isPresented: $viewModel.showSheet)
}
if viewModel.sheetToShow == .folder {
AddFolderView(isPresented: $viewModel.showSheet)
}
if viewModel.sheetToShow == .settings {
SettingsView()
.preferredColorScheme(AppDefaults.userInterfaceColorScheme)
}
2020-07-03 18:06:43 +02:00
}
#else
content
.toolbar {
ToolbarItem {
Spacer()
}
}
#endif
}
}