Skip to content

Commit

Permalink
Add BookmarksDialogViewFactory documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Feb 26, 2024
1 parent 2db48dd commit 8b60abf
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions DuckDuckGo/Bookmarks/View/Dialog/BookmarksDialogViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,43 @@ import SwiftUI
@MainActor
enum BookmarksDialogViewFactory {

static func makeAddBookmarkFolderView(parentFolder: BookmarkFolder?, bookmarkManager: LocalBookmarkManager = .shared) -> some ModalView {
/// Creates an instance of AddEditBookmarkFolderDialogView for adding a Bookmark Folder.
/// - Parameters:
/// - parentFolder: An optional `BookmarkFolder`. When adding a folder to the root bookmark folder pass `nil`. For any other folder pass the `BookmarkFolder` the new folder should be within.
/// - bookmarkManager: An instance of `BookmarkManager`. This should be used for `#previews` only.
/// - Returns: An instance of AddEditBookmarkFolderDialogView
static func makeAddBookmarkFolderView(parentFolder: BookmarkFolder?, bookmarkManager: LocalBookmarkManager = .shared) -> AddEditBookmarkFolderDialogView {
let viewModel = AddEditBookmarkFolderDialogViewModel(mode: .add(parentFolder: parentFolder), bookmarkManager: bookmarkManager)
return AddEditBookmarkFolderDialogView(viewModel: viewModel)
}

static func makeEditBookmarkFolderView(folder: BookmarkFolder, parentFolder: BookmarkFolder?, bookmarkManager: LocalBookmarkManager = .shared) -> some ModalView {
/// Creates an instance of AddEditBookmarkFolderDialogView for editing a Bookmark Folder.
/// - Parameters:
/// - folder: The `BookmarkFolder` to edit.
/// - parentFolder: An optional `BookmarkFolder`. When editing a folder within the root bookmark folder pass `nil`. For any other folder pass the `BookmarkFolder` the folder belongs to.
/// - bookmarkManager: An instance of `BookmarkManager`. This should be used for `#previews` only.
/// - Returns: An instance of AddEditBookmarkFolderDialogView
static func makeEditBookmarkFolderView(folder: BookmarkFolder, parentFolder: BookmarkFolder?, bookmarkManager: LocalBookmarkManager = .shared) -> AddEditBookmarkFolderDialogView {
let viewModel = AddEditBookmarkFolderDialogViewModel(mode: .edit(folder: folder, parentFolder: parentFolder), bookmarkManager: bookmarkManager)
return AddEditBookmarkFolderDialogView(viewModel: viewModel)
}

static func makeAddBookmarkView(bookmarkManager: LocalBookmarkManager = .shared) -> some ModalView {
let viewModel = AddEditBookmarkDialogViewModel(mode: .add(), bookmarkManager: bookmarkManager)
/// Creates an instance of AddEditBookmarkDialogView for adding a Bookmark.
/// - Parameters:
/// - currentTab: An optional `WebsiteInfo`. When adding a bookmark from the bookmark shortcut panel, if the `Tab` has loaded a web page pass the information via the `currentTab`. If the `Tab` has not loaded a tab pass `nil`. If adding a `Bookmark` from the `Manage Bookmark` settings page, pass `nil`.
/// - bookmarkManager: An instance of `BookmarkManager`. This should be used for `#previews` only.
/// - Returns: An instance of AddEditBookmarkDialogView
static func makeAddBookmarkView(currentTab: WebsiteInfo?, bookmarkManager: LocalBookmarkManager = .shared) -> AddEditBookmarkDialogView {
let viewModel = AddEditBookmarkDialogViewModel(mode: .add(tabWebsite: currentTab), bookmarkManager: bookmarkManager)
return makeAddEditBookmarkDialogView(viewModel: viewModel, bookmarkManager: bookmarkManager)
}

static func makeEditBookmarkView(bookmark: Bookmark, bookmarkManager: LocalBookmarkManager = .shared) -> some ModalView {
/// Creates an instance of AddEditBookmarkDialogView for editing a Bookmark.
/// - Parameters:
/// - bookmark: The `Bookmark` to edit.
/// - bookmarkManager: An instance of `BookmarkManager`. This should be used for `#previews` only.
/// - Returns: An instance of AddEditBookmarkDialogView
static func makeEditBookmarkView(bookmark: Bookmark, bookmarkManager: LocalBookmarkManager = .shared) -> AddEditBookmarkDialogView {
let viewModel = AddEditBookmarkDialogViewModel(mode: .edit(bookmark: bookmark), bookmarkManager: bookmarkManager)
return makeAddEditBookmarkDialogView(viewModel: viewModel, bookmarkManager: bookmarkManager)
}
Expand All @@ -45,7 +66,7 @@ enum BookmarksDialogViewFactory {

private extension BookmarksDialogViewFactory {

private static func makeAddEditBookmarkDialogView(viewModel: AddEditBookmarkDialogViewModel, bookmarkManager: BookmarkManager) -> some ModalView {
private static func makeAddEditBookmarkDialogView(viewModel: AddEditBookmarkDialogViewModel, bookmarkManager: BookmarkManager) -> AddEditBookmarkDialogView {
let addFolderViewModel = AddEditBookmarkFolderDialogViewModel(mode: .add(parentFolder: nil), bookmarkManager: bookmarkManager)
let viewModel = AddEditBookmarkDialogCoordinatorViewModel(bookmarkModel: viewModel, folderModel: addFolderViewModel)
return AddEditBookmarkDialogView(viewModel: viewModel)
Expand Down

0 comments on commit 8b60abf

Please sign in to comment.