Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit dbb5603

Browse files
rluftwBasThomas
authored andcommitted
Enable individual bookmark deletes (#2741)
* update bookmarks to SwipeSelectableCell * add ability to delete * undo return separation * remove using section * move protocol to bookmark vc * add markers
1 parent c3ac63c commit dbb5603

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

Classes/Bookmark/BookmarkCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
import SnapKit
1111
import StyledTextKit
1212

13-
final class BookmarkCell: SelectableCell {
13+
final class BookmarkCell: SwipeSelectableCell {
1414

1515
static let titleInset = UIEdgeInsets(
1616
top: Styles.Sizes.rowSpacing,

Classes/Bookmark/BookmarkIssueSectionController.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
import Foundation
1010
import IGListKit
1111
import GitHawkRoutes
12+
import SwipeCellKit
1213

13-
final class BookmarkIssueSectionController: ListSwiftSectionController<BookmarkIssueViewModel> {
14+
final class BookmarkIssueSectionController: ListSwiftSectionController<BookmarkIssueViewModel>, SwipeCollectionViewCellDelegate {
15+
16+
private weak var delegate: BookmarkSectionControllerDelegate?
17+
18+
init(delegate: BookmarkSectionControllerDelegate?) {
19+
self.delegate = delegate
20+
}
1421

1522
override func createBinders(from value: BookmarkIssueViewModel) -> [ListBinder] {
1623
return [
@@ -23,6 +30,7 @@ final class BookmarkIssueSectionController: ListSwiftSectionController<BookmarkI
2330
)
2431
}, configure: {
2532
$0.configure(with: $1.value)
33+
$0.delegate = self
2634
}, didSelect: { [weak self] context in
2735
self?.viewController?.route(IssueRoute(
2836
owner: context.value.repo.owner,
@@ -33,4 +41,15 @@ final class BookmarkIssueSectionController: ListSwiftSectionController<BookmarkI
3341
]
3442
}
3543

44+
// MARK: SwipeCollectionViewCellDelegate
45+
46+
func collectionView(_ collectionView: UICollectionView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
47+
guard orientation == .right else { return nil }
48+
49+
let action = DeleteSwipeAction { _, indexPath in
50+
self.delegate?.didSwipeToDelete(at: indexPath)
51+
}
52+
53+
return [action]
54+
}
3655
}

Classes/Bookmark/BookmarkRepoCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import SnapKit
1111

12-
final class BookmarkRepoCell: SelectableCell {
12+
final class BookmarkRepoCell: SwipeSelectableCell {
1313

1414
private let imageView = UIImageView(image: UIImage(named: "repo").withRenderingMode(.alwaysTemplate))
1515
private let label = UILabel()

Classes/Bookmark/BookmarkRepoSectionController.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
import Foundation
1010
import IGListKit
1111
import GitHawkRoutes
12+
import SwipeCellKit
1213

13-
final class BookmarkRepoSectionController: ListSwiftSectionController<RepositoryDetails> {
14+
final class BookmarkRepoSectionController: ListSwiftSectionController<RepositoryDetails>, SwipeCollectionViewCellDelegate {
15+
16+
private weak var delegate: BookmarkSectionControllerDelegate?
17+
18+
init(delegate: BookmarkSectionControllerDelegate?) {
19+
self.delegate = delegate
20+
}
1421

1522
override func createBinders(from value: RepositoryDetails) -> [ListBinder] {
1623
return [
@@ -21,6 +28,7 @@ final class BookmarkRepoSectionController: ListSwiftSectionController<Repository
2128
return $0.collection.cellSize(with: Styles.Sizes.tableCellHeightLarge)
2229
}, configure: {
2330
$0.configure(owner: $1.value.owner, name: $1.value.name)
31+
$0.delegate = self
2432
}, didSelect: { [weak self] context in
2533
self?.viewController?.route(RepoRoute(
2634
owner: context.value.owner,
@@ -31,4 +39,15 @@ final class BookmarkRepoSectionController: ListSwiftSectionController<Repository
3139
]
3240
}
3341

42+
// MARK: SwipeCollectionViewCellDelegate
43+
44+
func collectionView(_ collectionView: UICollectionView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
45+
guard orientation == .right else { return nil }
46+
47+
let action = DeleteSwipeAction { _, _ in
48+
self.delegate?.didSwipeToDelete(at: indexPath)
49+
}
50+
51+
return [action]
52+
}
3453
}

Classes/Bookmark/BookmarkViewController.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import Foundation
1010
import IGListKit
1111
import Squawk
1212

13+
protocol BookmarkSectionControllerDelegate: AnyObject {
14+
func didSwipeToDelete(at indexPath: IndexPath)
15+
}
16+
1317
protocol BookmarkViewControllerClient {
1418
func fetch(graphQLIDs: [String], completion: @escaping (Result<[BookmarkModelType]>) -> Void)
1519
}
@@ -23,7 +27,8 @@ final class BookmarkViewController: BaseListViewController<String>,
2327
BaseListViewControllerDataSource,
2428
BaseListViewControllerEmptyDataSource,
2529
BookmarkIDCloudStoreListener,
26-
BookmarkHeaderSectionControllerDelegate {
30+
BookmarkHeaderSectionControllerDelegate,
31+
BookmarkSectionControllerDelegate {
2732

2833
typealias Client = BookmarkViewControllerClient & BookmarkCloudMigratorClient
2934

@@ -150,11 +155,11 @@ BookmarkHeaderSectionControllerDelegate {
150155
switch $0 {
151156
case .issue(let model):
152157
return ListSwiftPair.pair(model, {
153-
BookmarkIssueSectionController()
158+
BookmarkIssueSectionController(delegate: self)
154159
})
155160
case .repo(let model):
156161
return ListSwiftPair.pair(model, {
157-
BookmarkRepoSectionController()
162+
BookmarkRepoSectionController(delegate: self)
158163
})
159164
}
160165
}
@@ -194,4 +199,10 @@ BookmarkHeaderSectionControllerDelegate {
194199
cloudStore.clear()
195200
}
196201

202+
// MARK: BookmarkSectionControllerDelegate
203+
204+
func didSwipeToDelete(at indexPath: IndexPath) {
205+
let graphQLID = cloudStore.ids[indexPath.section-1]
206+
cloudStore.remove(graphQLID: graphQLID)
207+
}
197208
}

0 commit comments

Comments
 (0)