1+ import AsyncImageKit
12import Foundation
3+ import SafariServices
4+ import SwiftUI
25import WordPressData
36import WordPressReader
47import WordPressShared
@@ -466,7 +469,7 @@ class ReaderDetailCoordinator {
466469 WPAppAnalytics . track ( . readerSitePreviewed, withProperties: properties)
467470 }
468471
469- private func showTopic( _ topic: String ) {
472+ func showTopic( _ topic: String ) {
470473 let controller = ReaderStreamViewController . controllerWithTagSlug ( topic)
471474 controller. trackingContext. source = ScreenTrackingSource ( ScreenID . Reader. article, component: ElementID . Reader. tagChip)
472475 viewController? . navigationController? . pushViewController ( controller, animated: true )
@@ -691,28 +694,72 @@ class ReaderDetailCoordinator {
691694 }
692695}
693696
694- // MARK: - ReaderDetailHeaderViewDelegate
695- extension ReaderDetailCoordinator : ReaderDetailHeaderViewDelegate {
696- func didTapBlogName( ) {
697- previewSite ( )
697+ // MARK: - ReaderPostHeaderViewDelegate
698+ extension ReaderDetailCoordinator : ReaderPostHeaderViewDelegate {
699+ func readerPostHeaderView( _ view: ReaderPostHeaderView , didTap element: ReaderPostHeaderView . Element ) {
700+ switch element {
701+ case . siteName:
702+ previewSite ( )
703+ case . subscribe:
704+ if view. isSubscribed {
705+ showUnsubscribeConfirmation ( headerView: view)
706+ } else {
707+ view. isShowingSubscribeLoadingIndicator = true
708+ followSite { [ weak self] in
709+ view. isShowingSubscribeLoadingIndicator = false
710+ self ? . view? . updateHeader ( )
711+ }
712+ }
713+ case . author:
714+ showAuthorProfile ( )
715+ case . featuredImage:
716+ showFeaturedImage ( view. featuredImageView)
717+ }
698718 }
699719
700- func didTapTagButton( ) {
701- showTag ( )
720+ private func showFeaturedImage( _ sender: AsyncImageView ) {
721+ guard let post, let imageURL = post. featuredImage. flatMap ( URL . init) else {
722+ return
723+ }
724+ let lightboxVC = LightboxViewController ( sourceURL: imageURL, host: MediaHost ( post) )
725+ MainActor . assumeIsolated {
726+ lightboxVC. thumbnail = sender. image
727+ }
728+ lightboxVC. configureZoomTransition ( sourceView: sender)
729+ viewController? . present ( lightboxVC, animated: true )
702730 }
703731
704- func didTapHeaderAvatar( ) {
705- previewSite ( )
732+ private func showAuthorProfile( ) {
733+ guard let post else { return }
734+ let viewModel = ReaderUserProfileViewModel ( post: post)
735+ let profileVC = UIHostingController ( rootView: ReaderUserProfileView ( viewModel: viewModel) )
736+ let navigationVC = UINavigationController ( rootViewController: profileVC)
737+ profileVC. navigationItem. leftBarButtonItem = UIBarButtonItem ( systemItem: . close, primaryAction: . init { [ weak profileVC] _ in
738+ profileVC? . presentingViewController? . dismiss ( animated: true )
739+ } )
740+ navigationVC. sheetPresentationController? . detents = [ . medium( ) ]
741+ viewController? . present ( navigationVC, animated: true )
706742 }
707743
708- func didTapFollowButton( completion: @escaping ( ) -> Void ) {
709- followSite ( completion: completion)
710- }
744+ private func showUnsubscribeConfirmation( headerView: ReaderPostHeaderView ) {
745+ let alertController = UIAlertController (
746+ title: Strings . unsubscribeTitle,
747+ message: Strings . unsubscribeMessage,
748+ preferredStyle: . alert
749+ )
711750
712- func didSelectTopic( _ topic: String ) {
713- showTopic ( topic)
714- }
751+ alertController. addAction ( UIAlertAction ( title: SharedStrings . Button. cancel, style: . cancel) )
752+ alertController. addAction ( UIAlertAction ( title: Strings . unsubscribe, style: . destructive) { [ weak self, weak headerView] _ in
753+ guard let self, let headerView else { return }
754+ headerView. isShowingSubscribeLoadingIndicator = true
755+ self . followSite { [ weak headerView] in
756+ headerView? . isShowingSubscribeLoadingIndicator = false
757+ self . view? . updateHeader ( )
758+ }
759+ } )
715760
761+ viewController? . present ( alertController, animated: true )
762+ }
716763}
717764
718765extension ReaderDetailCoordinator : ReaderDetailLikesViewDelegate {
@@ -733,6 +780,17 @@ private extension ReaderDetailCoordinator {
733780 value: " You don't have permission to view this private blog. " ,
734781 comment: " Error message that informs reader detail from a private blog cannot be fetched. "
735782 )
783+ static let unsubscribeTitle = NSLocalizedString (
784+ " reader.detail.unsubscribe.title " ,
785+ value: " Unsubscribe? " ,
786+ comment: " Title of the confirmation dialog when unsubscribing from a site "
787+ )
788+ static let unsubscribeMessage = NSLocalizedString (
789+ " reader.detail.unsubscribe.message " ,
790+ value: " Are you sure you want to unsubscribe from this site? " ,
791+ comment: " Message in the confirmation dialog when unsubscribing from a site "
792+ )
793+ static let unsubscribe = SharedStrings . Reader. unsubscribe
736794 }
737795
738796}
0 commit comments