Add previews + refactor placeholder view

This commit is contained in:
Thomas Ricouard 2024-02-14 13:34:06 +01:00
parent 1f858414d8
commit 24ce872849
11 changed files with 78 additions and 46 deletions

View file

@ -153,3 +153,13 @@ public struct AccountsListView: View {
}
}
}
#Preview {
List {
AccountsListRow(viewModel: .init(account: .placeholder(),
relationShip: .placeholder()))
}
.listStyle(.plain)
.withPreviewsEnv()
.environment(Theme.shared)
}

View file

@ -48,7 +48,7 @@ public struct ConversationsListView: View {
Divider()
}
} else if conversations.isEmpty, !viewModel.isLoadingFirstPage, !viewModel.isError {
EmptyView(iconName: "tray",
PlaceholderView(iconName: "tray",
title: "conversations.empty.title",
message: "conversations.empty.message")
} else if viewModel.isError {

View file

@ -1,32 +0,0 @@
import SwiftUI
public struct EmptyView: View {
public let iconName: String
public let title: LocalizedStringKey
public let message: LocalizedStringKey
public init(iconName: String, title: LocalizedStringKey, message: LocalizedStringKey) {
self.iconName = iconName
self.title = title
self.message = message
}
public var body: some View {
VStack {
Image(systemName: iconName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxHeight: 50)
Text(title)
.font(.scaledTitle)
.padding(.top, 16)
Text(message)
.font(.scaledSubheadline)
.multilineTextAlignment(.center)
.foregroundStyle(.secondary)
}
.padding(.top, 100)
.padding(.layoutPadding)
.fixedSize(horizontal: false, vertical: true)
}
}

View file

@ -42,3 +42,11 @@ public struct ErrorView: View {
}
}
}
#Preview {
ErrorView(title: "Error",
message: "Error loading. Please try again",
buttonTitle: "Retry") {
}
}

View file

@ -50,3 +50,14 @@ public struct NextPageView: View {
}
}
}
#Preview {
List {
Text("Item 1")
NextPageView {
}
}
.listStyle(.plain)
}

View file

@ -0,0 +1,25 @@
import SwiftUI
public struct PlaceholderView: View {
public let iconName: String
public let title: LocalizedStringKey
public let message: LocalizedStringKey
public init(iconName: String, title: LocalizedStringKey, message: LocalizedStringKey) {
self.iconName = iconName
self.title = title
self.message = message
}
public var body: some View {
ContentUnavailableView(title,
systemImage: iconName,
description: Text(message))
}
}
#Preview {
PlaceholderView(iconName: "square.and.arrow.up.trianglebadge.exclamationmark",
title: "Nothing to see",
message: "This is a preview. Please try again.")
}

View file

@ -11,7 +11,7 @@ public struct ScrollToView: View {
public init() {}
public var body: some View {
HStack { SwiftUI.EmptyView() }
HStack { EmptyView() }
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.listRowInsets(.init())

View file

@ -0,0 +1,15 @@
import SwiftUI
import Network
@MainActor
public extension View {
func withPreviewsEnv() -> some View{
environment(RouterPath())
.environment(Client(server: ""))
.environment(CurrentAccount.shared)
.environment(UserPreferences.shared)
.environment(CurrentInstance.shared)
.environment(PushNotificationsService.shared)
.environment(QuickLook.shared)
}
}

View file

@ -32,7 +32,7 @@ public struct ExploreView: View {
} else if !viewModel.searchQuery.isEmpty {
if let results = viewModel.results[viewModel.searchQuery] {
if results.isEmpty, !viewModel.isSearching {
EmptyView(iconName: "magnifyingglass",
PlaceholderView(iconName: "magnifyingglass",
title: "explore.search.empty.title",
message: "explore.search.empty.message")
.listRowBackground(theme.secondaryBackgroundColor)
@ -53,7 +53,7 @@ public struct ExploreView: View {
.id(UUID())
}
} else if viewModel.allSectionsEmpty {
EmptyView(iconName: "magnifyingglass",
PlaceholderView(iconName: "magnifyingglass",
title: "explore.search.title",
message: "explore.search.message-\(client.server)")
#if !os(visionOS)

View file

@ -153,7 +153,7 @@ public struct NotificationsListView: View {
case let .display(notifications, nextPageState):
if notifications.isEmpty {
EmptyView(iconName: "bell.slash",
PlaceholderView(iconName: "bell.slash",
title: "notifications.empty.title",
message: "notifications.empty.message")
#if !os(visionOS)

View file

@ -350,13 +350,8 @@ public struct StatusRowView: View {
client: .init(server: ""),
routerPath: RouterPath()),
context: .timeline)
}.listStyle(.plain)
.environment(RouterPath())
.environment(Client(server: ""))
.environment(CurrentAccount.shared)
.environment(UserPreferences.shared)
.environment(CurrentInstance.shared)
.environment(Theme.shared)
.environment(PushNotificationsService.shared)
.environment(QuickLook.shared)
}
.listStyle(.plain)
.withPreviewsEnv()
.environment(Theme.shared)
}