-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathReaderSubscriptionCell.swift
More file actions
82 lines (69 loc) · 2.89 KB
/
Copy pathReaderSubscriptionCell.swift
File metadata and controls
82 lines (69 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import SwiftUI
import WordPressData
import WordPressUI
struct ReaderSubscriptionCell: View {
let site: ReaderSiteTopic
@State private var isShowingSettings = false
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
var onDelete: (ReaderSiteTopic) -> Void
private var details: String {
let components = [
horizontalSizeClass == .compact ? nil : URL(string: site.siteURL)?.host,
Strings.numberOfSubscriptions(with: site.subscriberCount.intValue)
]
return components.compactMap { $0 }.joined(separator: " · ")
}
var body: some View {
HStack(spacing: 0) {
HStack(spacing: 16) {
ReaderSiteIconView(site: site, size: .regular)
.padding(.leading, horizontalSizeClass == .compact ? 0 : 4)
VStack(alignment: .leading, spacing: 3) {
HStack(alignment: .firstTextBaseline, spacing: 8) {
Text(site.title)
.font(.body.weight(.medium))
}
Text(details)
.font(.caption)
.foregroundStyle(.secondary)
}
.lineLimit(1)
}
Spacer()
HStack(spacing: 0) {
if site.canManageNotifications {
ReaderSubscriptionNotificationSettingsButton(site: site)
}
buttonMore
}
.padding(.trailing, -16)
}
.contextMenu(menuItems: {
ReaderSubscriptionContextMenu(site: site, isShowingSettings: $isShowingSettings)
}, preview: {
ReaderTopicPreviewView(topic: site)
})
}
private var buttonMore: some View {
Menu {
ReaderSubscriptionContextMenu(site: site, isShowingSettings: $isShowingSettings)
} label: {
Image(systemName: "ellipsis")
.foregroundStyle(.secondary)
.frame(width: 40, height: 40)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}
}
private enum Strings {
static let settings = NSLocalizedString("reader.subscriptions.settings", value: "Settings", comment: "Button title for managing subscription settings")
static func numberOfSubscriptions(with count: Int) -> String {
let singular = NSLocalizedString("reader.subscriptions.subscriptionsSingular", value: "%@ subscriber", comment: "Number of subscriptions on a site (singular)")
let plural = NSLocalizedString("reader.subscriptions.subscriptionsPlural", value: "%@ subscribers", comment: "Number of subscriptions on a site (plural)")
return String(format: count == 1 ? singular : plural, kFormatted(count))
}
private static func kFormatted(_ count: Int) -> String {
count.formatted(.number.notation(.compactName))
}
}