From 7465abe0a9f4b56ec87ce35b84a46b8d5bbff7da Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 26 Apr 2022 22:11:19 -0400 Subject: [PATCH] Fix crash when loading account --- .../Profile/ProfileViewController.swift | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileViewController.swift b/Tusker/Screens/Profile/ProfileViewController.swift index 11ecd62e..3e1675f3 100644 --- a/Tusker/Screens/Profile/ProfileViewController.swift +++ b/Tusker/Screens/Profile/ProfileViewController.swift @@ -120,10 +120,21 @@ class ProfileViewController: UIPageViewController { let req = Client.getAccount(id: accountID) mastodonController.run(req) { [weak self] (response) in guard let self = self else { return } - guard case let .success(account, _) = response else { fatalError() } - self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in + switch response { + case .success(let account, _): + self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in + DispatchQueue.main.async { + self.updateAccountUI() + } + } + + case .failure(let error): DispatchQueue.main.async { - self.updateAccountUI() + let config = ToastConfiguration(from: error, with: "Loading", in: self) { [unowned self] (toast) in + toast.dismissToast(animated: true) + self.loadAccount() + } + self.showToast(configuration: config, animated: true) } } } @@ -271,3 +282,6 @@ extension ProfileViewController: TabbedPageViewController { selectPage(at: currentIndex - 1, animated: true) } } + +extension ProfileViewController: ToastableViewController { +}