From ce10c7d6e28c43bdf40674a5efa77e112dc7f093 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 21 Aug 2024 16:16:34 -0400 Subject: [PATCH] Implement adding list using new sidebar --- .../Main/MainSidebarViewController.swift | 5 ++-- .../Main/NewMainTabBarViewController.swift | 26 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 6b0908bc..d35363f5 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -269,8 +269,9 @@ class MainSidebarViewController: UIViewController { } private func showAddList() { - let service = CreateListService(mastodonController: mastodonController, present: { self.present($0, animated: true - ) }) { list in + let service = CreateListService(mastodonController: mastodonController, present: { + self.present($0, animated: true) + }) { list in let oldItem = self.selectedItem self.select(item: .list(list), animated: false) let list = ListTimelineViewController(for: list, mastodonController: self.mastodonController) diff --git a/Tusker/Screens/Main/NewMainTabBarViewController.swift b/Tusker/Screens/Main/NewMainTabBarViewController.swift index 4b48d0cd..ebfbc6bd 100644 --- a/Tusker/Screens/Main/NewMainTabBarViewController.swift +++ b/Tusker/Screens/Main/NewMainTabBarViewController.swift @@ -12,7 +12,7 @@ import Pachyderm import TuskerPreferences @available(iOS 18.0, *) -class NewMainTabBarViewController: BaseMainTabBarViewController { +final class NewMainTabBarViewController: BaseMainTabBarViewController { private let composePlaceholder = UIViewController() @@ -61,8 +61,8 @@ class NewMainTabBarViewController: BaseMainTabBarViewController { } listsGroup.preferredPlacement = .sidebarOnly listsGroup.sidebarActions = [ - UIAction(title: "New List…", image: UIImage(systemName: "plus"), handler: { _ in - fatalError("TODO") + UIAction(title: "New List…", image: UIImage(systemName: "plus"), handler: { [unowned self] _ in + self.showAddList() }) ] reloadLists(mastodonController.lists) @@ -129,7 +129,7 @@ class NewMainTabBarViewController: BaseMainTabBarViewController { if nav.viewControllers.count > 1 { switch nav.viewControllers[1] { case let listVC as ListTimelineViewController: - if let tab = listsGroup.tab(forIdentifier: "list:\(listVC.list.id)") { + if let tab = listsGroup.tab(forIdentifier: Self.listTabIdentifier(listVC.list)) { newTab = (tab, Array(nav.viewControllers[1...])) nav.viewControllers = [ nav.viewControllers[0], // leave the ExploreVC in place @@ -218,12 +218,16 @@ class NewMainTabBarViewController: BaseMainTabBarViewController { private func reloadLists(_ lists: [List]) { listsGroup.children = lists.map { list in - UITab(title: list.title, image: UIImage(systemName: "list.bullet"), identifier: "list:\(list.id)") { [unowned self] _ in + UITab(title: list.title, image: UIImage(systemName: "list.bullet"), identifier: Self.listTabIdentifier(list)) { [unowned self] _ in return ListTimelineViewController(for: list, mastodonController: self.mastodonController) } } } + private static func listTabIdentifier(_ list: List) -> String { + "list:\(list.id)" + } + @objc func handleComposeKeyCommand() { compose(editing: nil) } @@ -232,6 +236,18 @@ class NewMainTabBarViewController: BaseMainTabBarViewController { fastAccountSwitcher?.hide() } + private func showAddList() { + let service = CreateListService(mastodonController: mastodonController, present: { + self.present($0, animated: true) + }) { list in + let tab = self.listsGroup.tab(forIdentifier: Self.listTabIdentifier(list))! + let listVC = tab.viewController as! ListTimelineViewController + listVC.presentEditOnAppear = true + self.selectedTab = tab + } + service.run() + } + fileprivate func updateViewControllerSafeAreaInsets(_ vc: UIViewController) { guard vc is MultiColumnNavigationController || (vc as? AdaptableNavigationController)?.current is MultiColumnNavigationController else { return