Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
navigation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcan committed May 6, 2023
1 parent fe5a153 commit 0efdd24
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 79 deletions.
4 changes: 4 additions & 0 deletions swiftsky.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
36953D2229ED3B6900D9CF8B /* repogetRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36953D2129ED3B6900D9CF8B /* repogetRecord.swift */; };
3698CE9529F3AF0D00B9288A /* gtranslate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3698CE9429F3AF0D00B9288A /* gtranslate.swift */; };
36A7B1EA29F7F1CC00EB94E1 /* feedgetLikes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A7B1E929F7F1CC00EB94E1 /* feedgetLikes.swift */; };
36AA95C02A063BAC003DADC9 /* Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36AA95BF2A063BAC003DADC9 /* Navigation.swift */; };
36AEF58F29C48F0800B68B24 /* swiftskyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36AEF58E29C48F0800B68B24 /* swiftskyApp.swift */; };
36AEF59329C48F0900B68B24 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36AEF59229C48F0900B68B24 /* Assets.xcassets */; };
36AEF59629C48F0900B68B24 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36AEF59529C48F0900B68B24 /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -101,6 +102,7 @@
36953D2129ED3B6900D9CF8B /* repogetRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = repogetRecord.swift; sourceTree = "<group>"; };
3698CE9429F3AF0D00B9288A /* gtranslate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = gtranslate.swift; sourceTree = "<group>"; };
36A7B1E929F7F1CC00EB94E1 /* feedgetLikes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = feedgetLikes.swift; sourceTree = "<group>"; };
36AA95BF2A063BAC003DADC9 /* Navigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigation.swift; sourceTree = "<group>"; };
36AEF58B29C48F0800B68B24 /* swiftsky.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = swiftsky.app; sourceTree = BUILT_PRODUCTS_DIR; };
36AEF58E29C48F0800B68B24 /* swiftskyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = swiftskyApp.swift; sourceTree = "<group>"; };
36AEF59229C48F0900B68B24 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -158,6 +160,7 @@
3629C9EC29F2AEFA00352001 /* GlobalViewModel.swift */,
36E82F4A29F69FA000EAD7B5 /* TranslateViewModel.swift */,
36548D472A013350006AEDD8 /* PushNotifications.swift */,
36AA95BF2A063BAC003DADC9 /* Navigation.swift */,
);
path = models;
sourceTree = "<group>";
Expand Down Expand Up @@ -425,6 +428,7 @@
3629C9E829F2809700352001 /* TextViewWrapper.swift in Sources */,
36AEF5C229C492EB00B68B24 /* HomeView.swift in Sources */,
36E07D1529CA310E00A315C5 /* embedrecord.swift in Sources */,
36AA95C02A063BAC003DADC9 /* Navigation.swift in Sources */,
36EA529129C5ECF7006D5F10 /* feedgetAuthorFeed.swift in Sources */,
36AEF5C029C492C500B68B24 /* AvatarView.swift in Sources */,
36AEF58F29C48F0800B68B24 /* swiftskyApp.swift in Sources */,
Expand Down
11 changes: 11 additions & 0 deletions swiftsky/models/Navigation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Navigation.swift
// swiftsky
//

enum Navigation: Hashable {
case profile(String)
case thread(String)
case followers(String)
case following(String)
}
4 changes: 2 additions & 2 deletions swiftsky/views/EmbedPostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SwiftUI
struct EmbedPostView: View {
@State var embedrecord: EmbedRecordViewRecord
@State var usernamehover: Bool = false
@Binding var path: NavigationPath
@Binding var path: [Navigation]
var markdown: String {
var markdown = String()
let rt = RichText(text: embedrecord.value.text, facets: embedrecord.value.facets)
Expand Down Expand Up @@ -38,7 +38,7 @@ struct EmbedPostView: View {
let displayname = embedrecord.author.displayName ?? embedrecord.author.handle

Button {
path.append(embedrecord.author)
path.append(.profile(embedrecord.author.did))
} label: {
Text("\(displayname) \(Text(embedrecord.author.handle).foregroundColor(.secondary))")
.fontWeight(.semibold)
Expand Down
6 changes: 3 additions & 3 deletions swiftsky/views/FollowersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private struct FollowersRowView: View {
@State var user: ActorDefsProfileViewBasic
@State var usernamehover: Bool = false
@State var followingdisabled: Bool = false
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func follow() {
followingdisabled = true
Task {
Expand Down Expand Up @@ -50,7 +50,7 @@ private struct FollowersRowView: View {
Text("@\(user.handle)").foregroundColor(.secondary)
}
.onTapGesture {
path.append(user)
path.append(.profile(user.did))
}
if user.viewer?.followedBy != nil {
ZStack {
Expand Down Expand Up @@ -88,7 +88,7 @@ private struct FollowersRowView: View {
struct FollowersView: View {
let handle: String
@State var followers: graphGetFollowersOutput? = nil
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func getFollowers() async {
do {
self.followers = try await graphGetFollowers(actor: handle)
Expand Down
6 changes: 3 additions & 3 deletions swiftsky/views/FollowsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private struct FollowsRowView: View {
@State var user: ActorDefsProfileViewBasic
@State var usernamehover: Bool = false
@State var followingdisabled: Bool = false
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func follow() {
followingdisabled = true
Task {
Expand Down Expand Up @@ -50,7 +50,7 @@ private struct FollowsRowView: View {
Text("@\(user.handle)").foregroundColor(.secondary)
}
.onTapGesture {
path.append(user)
path.append(.profile(user.did))
}
if user.viewer?.followedBy != nil {
ZStack {
Expand Down Expand Up @@ -88,7 +88,7 @@ private struct FollowsRowView: View {
struct FollowsView: View {
let handle: String
@State var follows: graphGetFollowsOutput? = nil
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func getFollows() async {
do {
self.follows = try await graphGetFollows(actor: handle)
Expand Down
4 changes: 2 additions & 2 deletions swiftsky/views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import SwiftUI

struct HomeView: View {
@State var timeline: FeedGetTimelineOutput = FeedGetTimelineOutput()
@Binding var path: NavigationPath
@State var loading = false
@Binding var path: [Navigation]
func loadContent() async {
loading = true
do {
Expand Down Expand Up @@ -38,7 +38,7 @@ struct HomeView: View {
.padding([.top, .horizontal])
.contentShape(Rectangle())
.onTapGesture {
path.append(post)
path.append(.thread(post.post.uri))
}
.task {
if post == filteredfeed.last {
Expand Down
44 changes: 28 additions & 16 deletions swiftsky/views/NotificationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SwiftUI
private struct NotificationsViewFollow: View {
@State var notification: NotificationListNotificationsNotification
@State var underline = false
@Binding var path: [Navigation]
var body: some View {
Group {
if let author = notification.author {
Expand All @@ -21,12 +22,16 @@ private struct NotificationsViewFollow: View {
.foregroundColor(.accentColor)
AvatarView(url: author.avatar, size: 40)
HStack(spacing: 3) {
Text("@\(author.handle)")
.foregroundColor(.primary)
.underline(underline)
.hoverHand {
underline = $0
}
Button {
path.append(.profile(author.did))
} label: {
Text("@\(author.handle)")
.foregroundColor(.primary)
.underline(underline)
.hoverHand {
underline = $0
}
}.buttonStyle(.plain)
Text("followed you")
.opacity(0.8)

Expand All @@ -46,6 +51,7 @@ private struct NotificationsViewFollow: View {
private struct NotificationsViewLike: View {
@State var notification: NotificationListNotificationsNotification
@State var underline = false
@Binding var path: [Navigation]
var body: some View {
Group {
if let author = notification.author {
Expand All @@ -60,12 +66,17 @@ private struct NotificationsViewLike: View {
.foregroundColor(.pink)
AvatarView(url: author.avatar, size: 40)
HStack(spacing: 3) {
Text("@\(author.handle)")
.foregroundColor(.primary)
.underline(underline)
.hoverHand {
underline = $0
}
Button {
path.append(.profile(author.did))
} label: {
Text("@\(author.handle)")
.foregroundColor(.primary)
.underline(underline)
.hoverHand {
underline = $0
}
}.buttonStyle(.plain)

Text("liked your post")
.opacity(0.8)

Expand All @@ -83,6 +94,7 @@ private struct NotificationsViewLike: View {
}
struct NotificationsView: View {
@State var notifications: NotificationListNotificationsOutput?
@Binding var path: [Navigation]
func getNotifications(cursor: String? = nil) async {
do {
let notifications = try await NotificationListNotifications(cursor: cursor)
Expand Down Expand Up @@ -119,20 +131,20 @@ struct NotificationsView: View {
ForEach(notifications.notifications) { notification in
Group {
if notification.reason == "follow" {
NotificationsViewFollow(notification: notification)
NotificationsViewFollow(notification: notification, path: $path)
.padding(.bottom, 5)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
else if notification.reason == "like" {
NotificationsViewLike(notification: notification)
NotificationsViewLike(notification: notification, path: $path)
.padding(.bottom, 5)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
if let post = notification.post {
PostView(post: post, path: .constant(NavigationPath()))
PostView(post: post, path: $path)
.padding(.horizontal)
.padding(.top, notification.cid == notifications.notifications.first?.cid ? 5 : 0)
PostFooterView(post: post, path: .constant(NavigationPath()))
PostFooterView(post: post, path: $path)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
}
Expand Down
4 changes: 2 additions & 2 deletions swiftsky/views/PopularView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import SwiftUI
struct PopularView: View {
@AppStorage("disablelanguageFilter") private var disablelanguageFilter = false
@State var timeline: UnspeccedGetPopularOutput = UnspeccedGetPopularOutput()
@Binding var path: NavigationPath
@State var loading = false
@Binding var path: [Navigation]
func loadContent() async {
loading = true
do {
Expand Down Expand Up @@ -41,7 +41,7 @@ struct PopularView: View {
.padding([.top, .horizontal])
.contentShape(Rectangle())
.onTapGesture {
path.append(post)
path.append(.thread(post.post.uri))
}
.task {
if post == filteredfeed.last {
Expand Down
9 changes: 4 additions & 5 deletions swiftsky/views/PostFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ struct PostLikesSubview: View {
let displayname: String
let handle: String
@State var usernamehover = false
@Binding var path: NavigationPath
var body: some View {
HStack(alignment: .top) {
AvatarView(url: avatar, size: 40)
Expand All @@ -32,10 +31,10 @@ struct PostLikesSubview: View {
struct PostLikesView: View {
@State var post: FeedDefsPostView
@State var likes = feedgetLikesOutput()
@Binding var path: NavigationPath
@State var loading = true
@State var error = ""
@State var listheight = 40.0
@Binding var path: [Navigation]
private func getLikes() {
Task {
self.loading = true
Expand Down Expand Up @@ -71,9 +70,9 @@ struct PostLikesView: View {
}
ForEach(likes.likes) { user in
Button {
path.append(user.actor)
path.append(.profile(user.actor.did))
} label: {
PostLikesSubview(avatar: user.actor.avatar, displayname: user.actor.displayName ?? user.actor.handle, handle: user.actor.handle, path: $path)
PostLikesSubview(avatar: user.actor.avatar, displayname: user.actor.displayName ?? user.actor.handle, handle: user.actor.handle)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}
Expand Down Expand Up @@ -118,7 +117,7 @@ struct PostFooterView: View {
@State var locklike: Bool = false
@State var likesunderline: Bool = false
@State var likespopover: Bool = false
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func like() {
post.viewer.like = ""
post.likeCount += 1
Expand Down
6 changes: 3 additions & 3 deletions swiftsky/views/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct PostView: View {
@State var deletepost = false
@State var translateavailable = false
@StateObject var translateviewmodel = TranslateViewModel()
@Binding var path: NavigationPath
@Binding var path: [Navigation]
func delete() {
Task {
do {
Expand Down Expand Up @@ -58,7 +58,7 @@ struct PostView: View {
let displayname = post.author.displayName ?? post.author.handle

Button {
path.append(post.author)
path.append(.profile(post.author.did))
} label: {
Text("\(displayname) \(Text(post.author.handle).foregroundColor(.secondary))")
.fontWeight(.semibold)
Expand Down Expand Up @@ -142,7 +142,7 @@ struct PostView: View {
}
if let record: EmbedRecordViewRecord = embed.record {
Button {
path.append(record)
path.append(.thread(record.uri))
} label: {
EmbedPostView(embedrecord: record, path: $path)
}
Expand Down
12 changes: 4 additions & 8 deletions swiftsky/views/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import QuickLook
import SwiftUI

enum ProfileRouter: Hashable {
case followers(String)
case following(String)
}
private struct ProfileViewTabs: View {
@Namespace var namespace
@Binding var selectedtab: Int
Expand Down Expand Up @@ -48,7 +44,7 @@ struct ProfileView: View {
@State private var disablefollowbutton = false
@State private var disableblockbutton = false
@State private var blocksheetpresented = false
@Binding var path: NavigationPath
@Binding var path: [Navigation]
let tablist: [String] = ["Posts", "Posts & Replies", "Likes"]
private func getProfile() async {
do {
Expand Down Expand Up @@ -332,13 +328,13 @@ struct ProfileView: View {
else {
HStack {
Button {
path.append(ProfileRouter.followers(profile!.handle))
path.append(.followers(profile!.handle))
} label: {
Text("\(profile!.followersCount) \(Text("followers").foregroundColor(.secondary))")
}
.buttonStyle(.plain)
Button {
path.append(ProfileRouter.following(profile!.handle))
path.append(.following(profile!.handle))
} label: {
Text("\(profile!.followsCount) \(Text("following").foregroundColor(.secondary))")
}
Expand Down Expand Up @@ -367,7 +363,7 @@ struct ProfileView: View {
.padding(.top)
.contentShape(Rectangle())
.onTapGesture {
path.append(post)
path.append(.thread(post.post.uri))
}
.task {
if post == feed.last {
Expand Down
Loading

0 comments on commit 0efdd24

Please sign in to comment.