From 2088d0196956a9321f1dc2afaf82125bd1775a90 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 15 May 2024 10:43:24 +0300 Subject: Regular size layout --- JuickNext/Models.swift | 5 +++++ JuickNext/View/ContentView.swift | 48 ++++++++++++++++++++++++++++++++-------- JuickNext/View/FeedView.swift | 22 +++++++++--------- 3 files changed, 54 insertions(+), 21 deletions(-) (limited to 'JuickNext') diff --git a/JuickNext/Models.swift b/JuickNext/Models.swift index 77a12f5..f0d8109 100644 --- a/JuickNext/Models.swift +++ b/JuickNext/Models.swift @@ -45,3 +45,8 @@ struct Message : Model { case id = "mid", user, text = "body", attachment, entities, tags } } + +struct Feed { + var title: String + var url: String +} 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")) } } -- cgit v1.2.3