diff --git a/Shared/Account/AccountLogoutView.swift b/Shared/Account/AccountLogoutView.swift index 9f69a50..0ff1c77 100644 --- a/Shared/Account/AccountLogoutView.swift +++ b/Shared/Account/AccountLogoutView.swift @@ -43,22 +43,13 @@ struct AccountLogoutView: View { Text("Log Out") }) } - .sheet(isPresented: $isPresentingLogoutConfirmation) { - VStack { - Text("Log Out?") - .font(.title) - Text("\(editedPostsWarningString)You won't lose any local posts. Are you sure?") - HStack { - Button(action: model.logout, label: { - Text("Log Out") - }) - Button(action: { - self.isPresentingLogoutConfirmation = false - }, label: { - Text("Cancel") - }).keyboardShortcut(.cancelAction) - } - } + .alert(isPresented: $isPresentingLogoutConfirmation) { + Alert( + title: Text("Log Out?"), + message: Text("\(editedPostsWarningString)You won't lose any local posts. Are you sure?"), + primaryButton: .cancel(Text("Cancel"), action: { self.isPresentingLogoutConfirmation = false }), + secondaryButton: .destructive(Text("Log Out"), action: model.logout ) + ) } #endif } diff --git a/Shared/Models/WriteFreelyModel.swift b/Shared/Models/WriteFreelyModel.swift index 525f4ee..b53da10 100644 --- a/Shared/Models/WriteFreelyModel.swift +++ b/Shared/Models/WriteFreelyModel.swift @@ -14,6 +14,8 @@ class WriteFreelyModel: ObservableObject { @Published var isProcessingRequest: Bool = false @Published var hasNetworkConnection: Bool = true @Published var selectedPost: WFAPost? + @Published var selectedCollection: WFACollection? + @Published var showAllPosts: Bool = true @Published var isPresentingDeleteAlert: Bool = false @Published var isPresentingLoginErrorAlert: Bool = false @Published var isPresentingNetworkErrorAlert: Bool = false diff --git a/Shared/PostList/PostListFilteredView.swift b/Shared/PostList/PostListFilteredView.swift index cc65779..3460033 100644 --- a/Shared/PostList/PostListFilteredView.swift +++ b/Shared/PostList/PostListFilteredView.swift @@ -5,21 +5,33 @@ struct PostListFilteredView: View { @Binding var postCount: Int @FetchRequest(entity: WFACollection.entity(), sortDescriptors: []) var collections: FetchedResults var fetchRequest: FetchRequest - var showAllPosts: Bool - init(filter: String?, showAllPosts: Bool, postCount: Binding) { + var showAllPosts: Bool { + didSet { + model.showAllPosts = showAllPosts + } + } + + var selectedCollection: WFACollection? { + didSet { + model.selectedCollection = selectedCollection + } + } + + init(collection: WFACollection?, showAllPosts: Bool, postCount: Binding) { self.showAllPosts = showAllPosts + self.selectedCollection = collection if showAllPosts { fetchRequest = FetchRequest( entity: WFAPost.entity(), sortDescriptors: [NSSortDescriptor(key: "createdDate", ascending: false)] ) } else { - if let filter = filter { + if let collectionAlias = collection?.alias { fetchRequest = FetchRequest( entity: WFAPost.entity(), sortDescriptors: [NSSortDescriptor(key: "createdDate", ascending: false)], - predicate: NSPredicate(format: "collectionAlias == %@", filter) + predicate: NSPredicate(format: "collectionAlias == %@", collectionAlias) ) } else { fetchRequest = FetchRequest( @@ -75,7 +87,16 @@ struct PostListFilteredView: View { tag: post, selection: $model.selectedPost ) { - PostCellView(post: post) + if showAllPosts { + if let collection = collections.filter { $0.alias == post.collectionAlias }.first { + PostCellView(post: post, collectionName: collection.title) + } else { + let collectionName = model.account.server == "https://write.as" ? "Anonymous" : "Drafts" + PostCellView(post: post, collectionName: collectionName) + } + } else { + PostCellView(post: post) + } } .deleteDisabled(post.status != PostStatus.local.rawValue) } @@ -105,12 +126,6 @@ struct PostListFilteredView: View { }) ) } - .onAppear(perform: { - self.postCount = fetchRequest.wrappedValue.count - }) - .onChange(of: fetchRequest.wrappedValue.count, perform: { value in - self.postCount = value - }) .onDeleteCommand(perform: { guard let selectedPost = model.selectedPost else { return } if selectedPost.status == PostStatus.local.rawValue { @@ -134,6 +149,6 @@ struct PostListFilteredView: View { struct PostListFilteredView_Previews: PreviewProvider { static var previews: some View { - return PostListFilteredView(filter: nil, showAllPosts: false, postCount: .constant(999)) + return PostListFilteredView(collection: nil, showAllPosts: false, postCount: .constant(999)) } } diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift index ffc545b..8199e17 100644 --- a/Shared/PostList/PostListView.swift +++ b/Shared/PostList/PostListView.swift @@ -12,7 +12,7 @@ struct PostListView: View { var body: some View { #if os(iOS) GeometryReader { geometry in - PostListFilteredView(filter: selectedCollection?.alias, showAllPosts: showAllPosts, postCount: $postCount) + PostListFilteredView(collection: selectedCollection, showAllPosts: showAllPosts, postCount: $postCount) .navigationTitle( showAllPosts ? "All Posts" : selectedCollection?.title ?? ( model.account.server == "https://write.as" ? "Anonymous" : "Drafts" @@ -79,13 +79,41 @@ struct PostListView: View { } } #else //if os(macOS) - PostListFilteredView(filter: selectedCollection?.alias, showAllPosts: showAllPosts, postCount: $postCount) - .navigationTitle( - showAllPosts ? "All Posts" : selectedCollection?.title ?? ( - model.account.server == "https://write.as" ? "Anonymous" : "Drafts" - ) + PostListFilteredView( + collection: selectedCollection, + showAllPosts: showAllPosts, + postCount: $postCount + ) + .toolbar { + ToolbarItemGroup(placement: .primaryAction) { + if let selectedPost = model.selectedPost { + ActivePostToolbarView(activePost: selectedPost) + .alert(isPresented: $model.isPresentingNetworkErrorAlert, content: { + Alert( + title: Text("Connection Error"), + message: Text(""" + There is no internet connection at the moment. Please reconnect or try again later. + """), + dismissButton: .default(Text("OK"), action: { + model.isPresentingNetworkErrorAlert = false + }) + ) + }) + } + } + } + .onDisappear { + DispatchQueue.main.async { + self.model.selectedCollection = nil + self.model.showAllPosts = true + self.model.selectedPost = nil + } + } + .navigationTitle( + showAllPosts ? "All Posts" : selectedCollection?.title ?? ( + model.account.server == "https://write.as" ? "Anonymous" : "Drafts" ) - .navigationSubtitle(postCount == 1 ? "\(postCount) post" : "\(postCount) posts") + ) #endif } } diff --git a/Shared/WriteFreely_MultiPlatformApp.swift b/Shared/WriteFreely_MultiPlatformApp.swift index 29d33cc..4bc9109 100644 --- a/Shared/WriteFreely_MultiPlatformApp.swift +++ b/Shared/WriteFreely_MultiPlatformApp.swift @@ -54,9 +54,16 @@ struct WriteFreely_MultiPlatformApp: App { .disabled(!model.account.isLoggedIn) .keyboardShortcut("r", modifiers: [.command]) } - #if os(macOS) SidebarCommands() - #endif + CommandGroup(after: .help) { + Button("Visit Support Forum") { + #if os(macOS) + NSWorkspace().open(model.helpURL) + #else + UIApplication.shared.open(model.helpURL) + #endif + } + } } #if os(macOS) diff --git a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist index 6cd8075..2723ebe 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_ orderHint - 1 + 0 WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_ orderHint - 0 + 1