-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement Jetpack Activity Logs screen (list) #24596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(cat:*)", | ||
| "Bash(ls:*)", | ||
| "Bash(rg:*)", | ||
| "Bash(find:*)", | ||
| "Bash(grep:*)", | ||
| "Bash(head:*)", | ||
| "Bash(tail:*)", | ||
| "Bash(wc:*)", | ||
| "Bash(tree:*)", | ||
| "Bash(git:log,status,diff,branch)", | ||
| ], | ||
| "deny": [] | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import SwiftUI | ||
|
|
||
| /// A generic search view that works with DataViewPaginatedResponse. | ||
| /// Provides search functionality with debouncing, loading states, and error handling. | ||
| public struct DataViewSearchView<Response: DataViewPaginatedResponseProtocol, Content: View>: View { | ||
| /// The search text to monitor for changes | ||
| let searchText: String | ||
|
|
||
| /// The async function to perform the search | ||
| let search: () async throws -> Response | ||
|
|
||
| /// Content builder for the paginated list | ||
| let content: (Response) -> Content | ||
|
|
||
| /// Delay in milliseconds before executing search (default: 500ms) | ||
| let debounceDelay: UInt64 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I switched to the |
||
|
|
||
| @State private var response: Response? | ||
| @State private var error: Error? | ||
|
|
||
| public init( | ||
| searchText: String, | ||
| debounceDelay: UInt64 = 500, | ||
| search: @escaping () async throws -> Response, | ||
| @ViewBuilder content: @escaping (Response) -> Content | ||
| ) { | ||
| self.searchText = searchText | ||
| self.debounceDelay = debounceDelay | ||
| self.search = search | ||
| self.content = content | ||
| } | ||
|
|
||
| public var body: some View { | ||
| List { | ||
| if let response { | ||
| content(response) | ||
| } else if error == nil { | ||
| DataViewPagingFooterView(.loading) | ||
| } | ||
| } | ||
| .listStyle(.plain) | ||
| .overlay { | ||
| if let response, response.items.isEmpty { | ||
| EmptyStateView.search() | ||
| } else if let error { | ||
| EmptyStateView.failure(error: error) | ||
| } | ||
| } | ||
| .task(id: searchText) { | ||
| error = nil | ||
| do { | ||
| try await Task.sleep(for: .milliseconds(debounceDelay)) | ||
| let response = try await search() | ||
| guard !Task.isCancelled else { return } | ||
| self.response = response | ||
| } catch { | ||
| guard !Task.isCancelled else { return } | ||
| self.response = nil | ||
| self.error = error | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import SwiftUI | ||
| import WordPressUI | ||
|
|
||
| struct ActivityLogRowView: View { | ||
| let viewModel: ActivityLogRowViewModel | ||
|
|
||
| var body: some View { | ||
| HStack(alignment: .center, spacing: 12) { | ||
| icon | ||
|
|
||
| VStack(alignment: .leading, spacing: 4) { | ||
| HStack { | ||
| Text(viewModel.subtitle) | ||
| .font(.caption) | ||
| .fontWeight(.medium) | ||
| .foregroundStyle(.secondary) | ||
| Spacer() | ||
| Text(viewModel.time) | ||
| .font(.caption2) | ||
| .foregroundColor(.secondary) | ||
| } | ||
|
|
||
| Text(viewModel.title) | ||
| .font(.subheadline) | ||
| .lineLimit(2) | ||
|
|
||
| if let actor = viewModel.actor { | ||
| HStack(spacing: 6) { | ||
| avatar | ||
| HStack(spacing: 4) { | ||
| Text(actor) | ||
| .font(.footnote) | ||
| .foregroundColor(.secondary) | ||
| if let role = viewModel.actorRole { | ||
| Text("·") | ||
| .font(.footnote) | ||
| .foregroundColor(.secondary) | ||
| Text(role) | ||
| .font(.footnote) | ||
| .foregroundColor(.secondary) | ||
| } | ||
| } | ||
| } | ||
| .padding(.top, 4) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private var avatar: some View { | ||
| Group { | ||
| if let avatarURL = viewModel.actorAvatarURL { | ||
| AvatarView(style: .single(avatarURL), diameter: 16) | ||
| } else if viewModel.actor?.lowercased() == "jetpack" { | ||
| Image("icon-jetpack") | ||
| .resizable() | ||
| } else { | ||
| Circle() | ||
| .fill(Color(.secondarySystemBackground)) | ||
| .overlay( | ||
| Text((viewModel.actor ?? "").prefix(1).uppercased()) | ||
| .font(.system(size: 9, weight: .medium)) | ||
| .foregroundColor(.secondary) | ||
| ) | ||
| } | ||
| } | ||
| .frame(width: 16, height: 16) | ||
| } | ||
|
|
||
| private var icon: some View { | ||
| ZStack { | ||
| RoundedRectangle(cornerRadius: 10) | ||
| .fill(viewModel.tintColor.opacity(0.15)) | ||
| .frame(width: 36, height: 36) | ||
|
|
||
| if let iconImage = viewModel.icon { | ||
| Image(uiImage: iconImage) | ||
| .renderingMode(.template) | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fit) | ||
| .frame(width: 20, height: 20) | ||
| .foregroundColor(viewModel.tintColor) | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import Foundation | ||
| import SwiftUI | ||
| import UIKit | ||
| import WordPressKit | ||
| import WordPressUI | ||
| import FormattableContentKit | ||
|
|
||
| struct ActivityLogRowViewModel: Identifiable { | ||
| let id: String | ||
| let actorAvatarURL: URL? | ||
| var actor: String? | ||
| var actorRole: String? | ||
| let title: String | ||
| let subtitle: String | ||
| let date: Date | ||
| let time: String | ||
| let icon: UIImage? | ||
| let tintColor: Color | ||
| let activity: Activity | ||
|
|
||
| init(activity: Activity) { | ||
| self.activity = activity | ||
| self.id = activity.activityID | ||
| self.actorAvatarURL = activity.actor.flatMap { URL(string: $0.avatarURL) } | ||
| if let actor = activity.actor { | ||
| self.actor = actor.displayName | ||
| if !actor.role.isEmpty { | ||
| self.actorRole = actor.role.localizedCapitalized | ||
| } | ||
| } | ||
| self.date = activity.published | ||
| self.time = activity.published.formatted(date: .omitted, time: .shortened) | ||
| self.title = activity.text | ||
| self.subtitle = activity.summary.localizedCapitalized | ||
|
|
||
| self.icon = WPStyleGuide.ActivityStyleGuide.getIconForActivity(activity) | ||
| self.tintColor = Color(WPStyleGuide.ActivityStyleGuide.getColorByActivityStatus(activity)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted from
SubscribersView.