Skip to content

Commit

Permalink
Sidebar: WIP settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed May 19, 2021
1 parent 47e3805 commit e95b365
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions RedditOs/Features/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ struct SettingsView: View {
}

Text("Filters")
.frame(width: 400, height: 150)
.tabItem {
Image(systemName: "stop.circle").imageScale(.large)
Text("Filters")
}

Text("Search")
.frame(width: 400, height: 150)
.tabItem {
Image(systemName: "magnifyingglass").imageScale(.large)
Text("Search")
}

Text("Accounts")
.frame(width: 400, height: 150)
.tabItem {
Image(systemName: "person").imageScale(.large)
Text("Accounts")
Expand Down
27 changes: 17 additions & 10 deletions RedditOs/Features/Settings/SidebarTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,34 @@
import SwiftUI

struct SidebarTabView: View {
@State private var items = ["Home", "Favorites", "Subscriptions", "Recently", "Multireddits"]
@State private var enabled = true
@AppStorage(SettingsKey.sidebar_enabled_section) var enabledSections = SidebarItem.allCases.map{ $0.rawValue }
private let sortedSections = SidebarItem.allCases.map{ $0.rawValue }

var body: some View {
Form {
Section(header: Text("Sidebar items")) {
ForEach(items, id: \.self) { item in
ForEach(SidebarItem.allCases) { item in
HStack {
Toggle(isOn: $enabled) {
Text(item)
}
Toggle(isOn: Binding(get: {
enabledSections.contains(item.rawValue)
}, set: { enabled in
if enabled {
enabledSections.append(item.rawValue)
enabledSections = enabledSections.sorted(by: { sortedSections.firstIndex(of: $0)! < sortedSections.firstIndex(of: $1)! })
} else {
enabledSections.removeAll(where: { $0 == item.rawValue })
}
}), label: {
Text(item.title())
})

}
}
}
}
.padding(20)
.frame(width: 400, height: 300)
}

func move(from source: IndexSet, to destination: Int) {
items.move(fromOffsets: source, toOffset: destination)
}
}

struct SidebarTabView_Previews: PreviewProvider {
Expand Down

0 comments on commit e95b365

Please sign in to comment.