From 714e7bb18418f2bd218e49e6f28e2a0b86f7ad5e Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 28 Feb 2022 10:05:46 -0800 Subject: [PATCH] use home feed child components in ios views --- .../Views/Home/HomeFeedViewComponents.swift | 13 +-- .../App/Views/Home/HomeFeedViewIOS.swift | 83 ++++++------------- .../App/Views/Home/HomeFeedViewMac.swift | 1 - .../Sources/Utils/FeatureFlags.swift | 1 + 4 files changed, 35 insertions(+), 63 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewComponents.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewComponents.swift index 3468b9968..62b756050 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewComponents.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewComponents.swift @@ -1,6 +1,7 @@ import Models import Services import SwiftUI +import Utils import Views struct FeedItemContextMenuView: View { @@ -31,11 +32,13 @@ struct FeedItemContextMenuView: View { } }, label: { Label("Unarchive", systemImage: "tray.and.arrow.down.fill") }) } - Button { - itemToSnooze = item - snoozePresented = true - } label: { - Label { Text("Snooze") } icon: { Image.moon } + if FeatureFlag.enableSnooze { + Button { + itemToSnooze = item + snoozePresented = true + } label: { + Label { Text("Snooze") } icon: { Image.moon } + } } } } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index db7dee27b..69d3f436f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -86,51 +86,25 @@ import Views @ObservedObject var viewModel: HomeFeedViewModel - let columns: [GridItem] = { - [GridItem(.adaptive(minimum: 300))] - }() - var body: some View { - ScrollView { - LazyVGrid(columns: columns, spacing: 20) { + List { + Section { ForEach(viewModel.items) { item in let link = ZStack { - NavigationLink( - destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)), - tag: item, - selection: $selectedLinkItem - ) { - EmptyView() - } - .opacity(0) - .buttonStyle(PlainButtonStyle()) - .onAppear { - viewModel.itemAppeared(item: item, searchQuery: searchQuery, dataService: dataService) - } - FeedCard(item: item) + FeedCardNavigationLink( + item: item, + searchQuery: searchQuery, + selectedLinkItem: $selectedLinkItem, + viewModel: viewModel + ) }.contextMenu { - if !item.isArchived { - Button(action: { - withAnimation(.linear(duration: 0.4)) { - viewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: true) - if item == selectedLinkItem { - selectedLinkItem = nil - } - } - }, label: { Label("Archive", systemImage: "archivebox") }) - } else { - Button(action: { - withAnimation(.linear(duration: 0.4)) { - viewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: false) - } - }, label: { Label("Unarchive", systemImage: "tray.and.arrow.down.fill") }) - } - Button { - itemToSnooze = item - snoozePresented = true - } label: { - Label { Text("Snooze") } icon: { Image.moon } - } + FeedItemContextMenuView( + item: item, + selectedLinkItem: $selectedLinkItem, + snoozePresented: $snoozePresented, + itemToSnooze: $itemToSnooze, + viewModel: viewModel + ) } if #available(iOS 15.0, *) { link @@ -175,14 +149,16 @@ import Views } Button("Cancel", role: .cancel) { self.itemToRemove = nil } } - // .swipeActions(edge: .leading, allowsFullSwipe: true) { - // Button { - // itemToSnooze = item - // snoozePresented = true - // } label: { - // Label { Text("Snooze") } icon: { Image.moon } - // }.tint(.appYellow48) - // } + .swipeActions(edge: .leading, allowsFullSwipe: true) { + if FeatureFlag.enableSnooze { + Button { + itemToSnooze = item + snoozePresented = true + } label: { + Label { Text("Snooze") } icon: { Image.moon } + }.tint(.appYellow48) + } + } } else { link } @@ -190,14 +166,7 @@ import Views } if viewModel.isLoading { - Section { - HStack(alignment: .center) { - Spacer() - Text("Loading...") - Spacer() - } - .frame(maxWidth: .infinity) - } + LoadingSection() } } .listStyle(PlainListStyle()) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift index 3190812b3..56aa8dee5 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift @@ -65,5 +65,4 @@ import Views } } -// TODO: handle $snoozePresented == true #endif diff --git a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift index 3dfabc24c..43385fcc4 100644 --- a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift +++ b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift @@ -13,4 +13,5 @@ public enum FeatureFlag { public static let enableRemindersFromShareExtension = false public static let enablePushNotifications = false public static let enableShareButton = false + public static let enableSnooze = false }