-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
extension Array: RawRepresentable where Element: Codable { | ||
public init?(rawValue: String) { | ||
guard let data = rawValue.data(using: .utf8), | ||
let result = try? JSONDecoder().decode([Element].self, from: data) | ||
else { | ||
return nil | ||
} | ||
self = result | ||
} | ||
|
||
public var rawValue: String { | ||
guard let data = try? JSONEncoder().encode(self), | ||
let result = String(data: data, encoding: .utf8) | ||
else { | ||
return "[]" | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// GeneralTabView.swift | ||
// RedditOs | ||
// | ||
// Created by Thomas Ricouard on 17/05/2021. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct GeneralTabView: View { | ||
@AppStorage(SettingsKey.subreddit_display_mode) private var displayMode: SubredditPostRow.DisplayMode = .large | ||
@AppStorage(SettingsKey.subreddit_defaut_sort_order) private var sortOrder: SubredditViewModel.SortOrder = .hot | ||
|
||
var body: some View { | ||
Form { | ||
Section(header: Text("Default Subreddit settings")) { | ||
|
||
Picker("Display layout style", selection: $displayMode) { | ||
ForEach(SubredditPostRow.DisplayMode.allCases, id: \.self) { mode in | ||
Label(mode.rawValue, systemImage: mode.symbol()).tag(mode) | ||
} | ||
} | ||
|
||
Picker(selection: $sortOrder, label: Text("Sort order")) { | ||
ForEach(SubredditViewModel.SortOrder.allCases, id: \.self) { sort in | ||
Text(sort.rawValue.capitalized).tag(sort) | ||
} | ||
} | ||
|
||
} | ||
} | ||
.padding() | ||
.frame(width: 400, height: 150) | ||
} | ||
} | ||
|
||
struct GeneralTabView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
GeneralTabView() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// SidebarTabView.swift | ||
// RedditOs | ||
// | ||
// Created by Thomas Ricouard on 17/05/2021. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SidebarTabView: View { | ||
@State private var items = ["Home", "Favorites", "Subscriptions", "Recently", "Multireddits"] | ||
@State private var enabled = true | ||
var body: some View { | ||
Form { | ||
Section(header: Text("Sidebar items")) { | ||
ForEach(items, id: \.self) { item in | ||
HStack { | ||
Toggle(isOn: $enabled) { | ||
Text(item) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.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 { | ||
static var previews: some View { | ||
SidebarTabView() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// SidebarViewModel.swift | ||
// RedditOs | ||
// | ||
// Created by Thomas Ricouard on 17/05/2021. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
enum SidebarItem: String, CaseIterable, Identifiable { | ||
case home, account, favorites, subscription, multi | ||
|
||
var id: String { | ||
rawValue | ||
} | ||
|
||
func title() -> String { | ||
switch self { | ||
case .home: | ||
return "Home" | ||
case .account: | ||
return "Account" | ||
case .favorites: | ||
return "Favorites" | ||
case .subscription: | ||
return "Subscriptions" | ||
case .multi: | ||
return "Multireddits" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters