From e69fcee9fb1beb4e4ebfb215019ba6fdd634954c Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 12 Jan 2023 19:12:23 +0100 Subject: [PATCH] Various small UI fixes --- .../Sources/Explore/ExploreViewModel.swift | 5 ++- .../NotificationsViewModel.swift | 11 ++++-- .../Status/Row/StatusActionsView.swift | 37 ++++++++----------- .../Sources/Timeline/TimelineViewModel.swift | 4 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Packages/Explore/Sources/Explore/ExploreViewModel.swift b/Packages/Explore/Sources/Explore/ExploreViewModel.swift index cd992f81..62c7b704 100644 --- a/Packages/Explore/Sources/Explore/ExploreViewModel.swift +++ b/Packages/Explore/Sources/Explore/ExploreViewModel.swift @@ -72,8 +72,9 @@ class ExploreViewModel: ObservableObject { self.trendingLinks = data.trendingLinks self.suggestedAccountsRelationShips = try await client.get(endpoint: Accounts.relationships(ids: self.suggestedAccounts.map{ $0.id })) - - isLoaded = true + withAnimation { + isLoaded = true + } } catch { isLoaded = true } diff --git a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift index c5dd2d4a..07ac1117 100644 --- a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift +++ b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift @@ -52,15 +52,20 @@ class NotificationsViewModel: ObservableObject { types: queryTypes)) nextPageState = notifications.count < 15 ? .none : .hasNextPage } else if let first = notifications.first { - let newNotifications: [Models.Notification] = + var newNotifications: [Models.Notification] = try await client.get(endpoint: Notifications.notifications(sinceId: first.id, maxId: nil, types: queryTypes)) nextPageState = notifications.count < 15 ? .none : .hasNextPage + newNotifications = newNotifications.filter({ notification in + !notifications.contains(where: { $0.id == notification.id }) + }) notifications.insert(contentsOf: newNotifications, at: 0) } - state = .display(notifications: notifications, - nextPageState: notifications.isEmpty ? .none : nextPageState) + withAnimation { + state = .display(notifications: notifications, + nextPageState: notifications.isEmpty ? .none : nextPageState) + } } catch { state = .error(error: error) } diff --git a/Packages/Status/Sources/Status/Row/StatusActionsView.swift b/Packages/Status/Sources/Status/Row/StatusActionsView.swift index a539b01e..2ea02a2e 100644 --- a/Packages/Status/Sources/Status/Row/StatusActionsView.swift +++ b/Packages/Status/Sources/Status/Row/StatusActionsView.swift @@ -98,10 +98,12 @@ struct StatusActionsView: View { @ViewBuilder private var summaryView: some View { + Divider() HStack { - Text(viewModel.status.createdAt.asDate, style: .date) - Text(viewModel.status.createdAt.asDate, style: .time) - Text("·") + Text(viewModel.status.createdAt.asDate, style: .date) + + Text(" at ") + + Text(viewModel.status.createdAt.asDate, style: .time) + + Text(" ·") Image(systemName: viewModel.status.visibility.iconName) Spacer() Text(viewModel.status.application?.name ?? "") @@ -114,30 +116,23 @@ struct StatusActionsView: View { } .font(.caption) .foregroundColor(.gray) + if viewModel.favouritesCount > 0 { Divider() - Button { - routeurPath.navigate(to: .favouritedBy(id: viewModel.status.id)) - } label: { - HStack { - Text("\(viewModel.favouritesCount) favorites") - Spacer() - Image(systemName: "chevron.right") - } - .font(.callout) + NavigationLink(value: RouteurDestinations.favouritedBy(id: viewModel.status.id)) { + Text("\(viewModel.favouritesCount) favorites") + .font(.callout) + Spacer() + Image(systemName: "chevron.right") } } if viewModel.reblogsCount > 0 { Divider() - Button { - routeurPath.navigate(to: .rebloggedBy(id: viewModel.status.id)) - } label: { - HStack { - Text("\(viewModel.reblogsCount) boosts") - Spacer() - Image(systemName: "chevron.right") - } - .font(.callout) + NavigationLink(value: RouteurDestinations.rebloggedBy(id: viewModel.status.id)) { + Text("\(viewModel.reblogsCount) boosts") + .font(.callout) + Spacer() + Image(systemName: "chevron.right") } } } diff --git a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift index c4b49237..f834b228 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift @@ -74,7 +74,9 @@ class TimelineViewModel: ObservableObject, StatusesFetcher { maxId: nil, minId: nil, offset: statuses.count)) - statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage) + withAnimation { + statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage) + } } else if let first = pendingStatuses.first ?? statuses.first { var newStatuses: [Status] = await fetchNewPages(minId: first.id, maxPages: 20) if userIntent || !pendingStatusesEnabled {