mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-25 09:41:02 +00:00
Add previews + refactor placeholder view
This commit is contained in:
parent
1f858414d8
commit
24ce872849
11 changed files with 78 additions and 46 deletions
|
@ -153,3 +153,13 @@ public struct AccountsListView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
List {
|
||||
AccountsListRow(viewModel: .init(account: .placeholder(),
|
||||
relationShip: .placeholder()))
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.withPreviewsEnv()
|
||||
.environment(Theme.shared)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -42,3 +42,11 @@ public struct ErrorView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ErrorView(title: "Error",
|
||||
message: "Error loading. Please try again",
|
||||
buttonTitle: "Retry") {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,3 +50,14 @@ public struct NextPageView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Preview {
|
||||
List {
|
||||
Text("Item 1")
|
||||
NextPageView {
|
||||
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
|
|
|
@ -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.")
|
||||
}
|
|
@ -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())
|
||||
|
|
15
Packages/Env/Sources/Env/PreviewEnv.swift
Normal file
15
Packages/Env/Sources/Env/PreviewEnv.swift
Normal 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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue