summaryrefslogtreecommitdiff
path: root/JuickNext/View
diff options
context:
space:
mode:
Diffstat (limited to 'JuickNext/View')
-rw-r--r--JuickNext/View/ContentView.swift48
-rw-r--r--JuickNext/View/FeedView.swift22
2 files changed, 49 insertions, 21 deletions
diff --git a/JuickNext/View/ContentView.swift b/JuickNext/View/ContentView.swift
index 22e74e0..3912c59 100644
--- a/JuickNext/View/ContentView.swift
+++ b/JuickNext/View/ContentView.swift
@@ -11,26 +11,56 @@ import SwiftUI
struct ContentView: View {
@Environment(\.horizontalSizeClass) private var size
- let today = FeedView("Today", url: "https://api.juick.com/messages?popular=1")
- let discussions = FeedView("Discussions", url: "https://api.juick.com/messages/discussions")
- let discover = FeedView("Discover", url: "https://api.juick.com/messages")
+ let today = Feed(title: "Today", url: "https://api.juick.com/messages?popular=1")
+ let discussions = Feed(title: "Discussions", url: "https://api.juick.com/messages/discussions")
+ let discover = Feed(title: "Discover", url: "https://api.juick.com/messages")
+
+ @State private var showFeed : Bool = false
+ @State private var selectedFeed: Feed? = nil
+
var body: some View {
let view = (size == .compact) ?
AnyView(TabView {
- today.tabItem {
+ FeedView(today).tabItem {
Image("ei-clock")
}
- discussions.tabItem {
+ FeedView(discussions).tabItem {
Image("ei-bell")
}
- discover.tabItem {
+ FeedView(discover).tabItem {
Image("Discover")
}
}): AnyView(NavigationView {
+ let tabs = [today, discussions, discover]
VStack {
- Text("Discussions")
- Text("Discover")
- Text("Chats")
+ List {
+ ForEach(tabs, id: \.title) {
+ tab in
+ Button(action: {
+ selectedFeed = tab
+ showFeed.toggle()
+ }, label: {
+ Text(tab.title)
+ })
+ }
+ }.background {
+ if let feed = selectedFeed {
+ NavigationLink(
+ destination: FeedView(feed),
+ isActive: $showFeed,
+ label: {
+ VStack {
+ Text(feed.title)
+ }
+ })
+ } else {
+ EmptyView()
+ }
+ }
+ }.toolbar {
+ ToolbarItem(placement: .principal) {
+ Text("Juick")
+ }
}
})
view
diff --git a/JuickNext/View/FeedView.swift b/JuickNext/View/FeedView.swift
index 3a612e8..cd0569f 100644
--- a/JuickNext/View/FeedView.swift
+++ b/JuickNext/View/FeedView.swift
@@ -11,11 +11,11 @@ import SwiftUI
struct FeedView: View {
@ObservedObject var messageFetcher : MessageFetcher
- let title: String
+ let feed: Feed
- init(_ title: String, url: String) {
- self.title = title
- messageFetcher = MessageFetcher(url: url)
+ init(_ feed: Feed) {
+ self.feed = feed
+ messageFetcher = MessageFetcher(url: feed.url)
}
private var stateContent: AnyView {
@@ -38,13 +38,11 @@ struct FeedView: View {
}
var body: some View {
- NavigationView {
- VStack {
- stateContent
- }.toolbar {
- ToolbarItem(placement: .principal) {
- Text(title)
- }
+ VStack {
+ stateContent
+ }.toolbar {
+ ToolbarItem(placement: .principal) {
+ Text(feed.title)
}
}
}
@@ -52,6 +50,6 @@ struct FeedView: View {
struct FeedView_Previews: PreviewProvider {
static var previews: some View {
- FeedView("Discover", url: "https://api.juick.com/messages")
+ FeedView(Feed(title:"Discover", url: "https://api.juick.com/messages"))
}
}