diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 3d60094ff..fc530d3f1 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -15,7 +15,7 @@ struct FeedCardNavigationLink: View { var body: some View { NavigationLink( - destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)), + destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, homeFeedViewModel: viewModel)), tag: item, selection: $selectedLinkItem ) { @@ -48,7 +48,7 @@ struct GridCardNavigationLink: View { var body: some View { ZStack { NavigationLink( - destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)), + destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, homeFeedViewModel: viewModel)), isActive: $isActive ) { EmptyView() diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 521c82c5d..3f0d9cead 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -10,18 +10,23 @@ enum PDFProvider { } final class LinkItemDetailViewModel: ObservableObject { + let homeFeedViewModel: HomeFeedViewModel @Published var item: FeedItem @Published var webAppWrapperViewModel: WebAppWrapperViewModel? - enum Action { - case load - case updateReadStatus(markAsRead: Bool) - } - var subscriptions = Set() - init(item: FeedItem) { + init(item: FeedItem, homeFeedViewModel: HomeFeedViewModel) { self.item = item + self.homeFeedViewModel = homeFeedViewModel + } + + func handleArchiveAction(dataService: DataService) { + homeFeedViewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: !item.isArchived) + } + + func handleDeleteAction(dataService: DataService) { + homeFeedViewModel.removeLink(dataService: dataService, linkId: item.id) } func updateItemReadStatus(dataService: DataService) { @@ -103,6 +108,7 @@ struct LinkItemDetailView: View { @ObservedObject private var viewModel: LinkItemDetailViewModel @State private var showFontSizePopover = false @State private var navBarVisibilityRatio = 1.0 + @State private var showDeleteConfirmation = false init(viewModel: LinkItemDetailViewModel) { self.viewModel = viewModel @@ -147,6 +153,38 @@ struct LinkItemDetailView: View { #endif } + var navBariOS14: some View { + HStack(alignment: .center) { + Button( + action: { self.presentationMode.wrappedValue.dismiss() }, + label: { + Image(systemName: "chevron.backward") + .font(.appTitleTwo) + .foregroundColor(.appGrayTextContrast) + .padding(.horizontal) + } + ) + .scaleEffect(navBarVisibilityRatio) + Spacer() + Button( + action: { showFontSizePopover.toggle() }, + label: { + Image(systemName: "textformat.size") + .font(.appTitleTwo) + } + ) + .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) + } + .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) + .opacity(navBarVisibilityRatio) + .background(Color.systemBackground) + .onTapGesture { + showFontSizePopover = false + } + } + + @available(iOS 15.0, *) var navBar: some View { HStack(alignment: .center) { Button( @@ -173,11 +211,16 @@ struct LinkItemDetailView: View { content: { Group { Button( - action: {}, - label: { Label("Archive", systemImage: "archivebox") } + action: { viewModel.handleArchiveAction(dataService: dataService) }, + label: { + Label( + viewModel.item.isArchived ? "Unarchive" : "Archive", + systemImage: viewModel.item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" + ) + } ) Button( - action: {}, + action: { showDeleteConfirmation = true }, label: { Label("Delete", systemImage: "trash") } ) } @@ -195,6 +238,12 @@ struct LinkItemDetailView: View { .onTapGesture { showFontSizePopover = false } + .alert("Are you sure?", isPresented: $showDeleteConfirmation) { + Button("Remove Link", role: .destructive) { + viewModel.handleDeleteAction(dataService: dataService) + } + Button("Cancel", role: .cancel, action: {}) + } } #if os(iOS) @@ -232,24 +281,47 @@ struct LinkItemDetailView: View { } ) } + if #available(iOS 15.0, *) { + VStack(spacing: 0) { + navBar + Spacer() + } + .navigationBarHidden(true) + } else { + VStack(spacing: 0) { + navBariOS14 + Spacer() + } + .navigationBarHidden(true) + } + } + + } else { + if #available(iOS 15.0, *) { VStack(spacing: 0) { navBar Spacer() } + .onAppear { + viewModel.loadWebAppWrapper( + dataService: dataService, + rawAuthCookie: authenticator.omnivoreAuthCookieString + ) + } + .navigationBarHidden(true) + } else { + VStack(spacing: 0) { + navBariOS14 + Spacer() + } + .onAppear { + viewModel.loadWebAppWrapper( + dataService: dataService, + rawAuthCookie: authenticator.omnivoreAuthCookieString + ) + } + .navigationBarHidden(true) } - .navigationBarHidden(true) - } else { - VStack(spacing: 0) { - navBar - Spacer() - } - .onAppear { - viewModel.loadWebAppWrapper( - dataService: dataService, - rawAuthCookie: authenticator.omnivoreAuthCookieString - ) - } - .navigationBarHidden(true) } } #endif