mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-26 18:04:44 +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()
|
Divider()
|
||||||
}
|
}
|
||||||
} else if conversations.isEmpty, !viewModel.isLoadingFirstPage, !viewModel.isError {
|
} else if conversations.isEmpty, !viewModel.isLoadingFirstPage, !viewModel.isError {
|
||||||
EmptyView(iconName: "tray",
|
PlaceholderView(iconName: "tray",
|
||||||
title: "conversations.empty.title",
|
title: "conversations.empty.title",
|
||||||
message: "conversations.empty.message")
|
message: "conversations.empty.message")
|
||||||
} else if viewModel.isError {
|
} 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 init() {}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
HStack { SwiftUI.EmptyView() }
|
HStack { EmptyView() }
|
||||||
.listRowBackground(Color.clear)
|
.listRowBackground(Color.clear)
|
||||||
.listRowSeparator(.hidden)
|
.listRowSeparator(.hidden)
|
||||||
.listRowInsets(.init())
|
.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 {
|
} else if !viewModel.searchQuery.isEmpty {
|
||||||
if let results = viewModel.results[viewModel.searchQuery] {
|
if let results = viewModel.results[viewModel.searchQuery] {
|
||||||
if results.isEmpty, !viewModel.isSearching {
|
if results.isEmpty, !viewModel.isSearching {
|
||||||
EmptyView(iconName: "magnifyingglass",
|
PlaceholderView(iconName: "magnifyingglass",
|
||||||
title: "explore.search.empty.title",
|
title: "explore.search.empty.title",
|
||||||
message: "explore.search.empty.message")
|
message: "explore.search.empty.message")
|
||||||
.listRowBackground(theme.secondaryBackgroundColor)
|
.listRowBackground(theme.secondaryBackgroundColor)
|
||||||
|
@ -53,7 +53,7 @@ public struct ExploreView: View {
|
||||||
.id(UUID())
|
.id(UUID())
|
||||||
}
|
}
|
||||||
} else if viewModel.allSectionsEmpty {
|
} else if viewModel.allSectionsEmpty {
|
||||||
EmptyView(iconName: "magnifyingglass",
|
PlaceholderView(iconName: "magnifyingglass",
|
||||||
title: "explore.search.title",
|
title: "explore.search.title",
|
||||||
message: "explore.search.message-\(client.server)")
|
message: "explore.search.message-\(client.server)")
|
||||||
#if !os(visionOS)
|
#if !os(visionOS)
|
||||||
|
|
|
@ -153,7 +153,7 @@ public struct NotificationsListView: View {
|
||||||
|
|
||||||
case let .display(notifications, nextPageState):
|
case let .display(notifications, nextPageState):
|
||||||
if notifications.isEmpty {
|
if notifications.isEmpty {
|
||||||
EmptyView(iconName: "bell.slash",
|
PlaceholderView(iconName: "bell.slash",
|
||||||
title: "notifications.empty.title",
|
title: "notifications.empty.title",
|
||||||
message: "notifications.empty.message")
|
message: "notifications.empty.message")
|
||||||
#if !os(visionOS)
|
#if !os(visionOS)
|
||||||
|
|
|
@ -350,13 +350,8 @@ public struct StatusRowView: View {
|
||||||
client: .init(server: ""),
|
client: .init(server: ""),
|
||||||
routerPath: RouterPath()),
|
routerPath: RouterPath()),
|
||||||
context: .timeline)
|
context: .timeline)
|
||||||
}.listStyle(.plain)
|
}
|
||||||
.environment(RouterPath())
|
.listStyle(.plain)
|
||||||
.environment(Client(server: ""))
|
.withPreviewsEnv()
|
||||||
.environment(CurrentAccount.shared)
|
.environment(Theme.shared)
|
||||||
.environment(UserPreferences.shared)
|
|
||||||
.environment(CurrentInstance.shared)
|
|
||||||
.environment(Theme.shared)
|
|
||||||
.environment(PushNotificationsService.shared)
|
|
||||||
.environment(QuickLook.shared)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue