|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+//
|
|
|
2
|
+// ProfilesListPageView.swift
|
|
|
3
|
+// App for Indeed
|
|
|
4
|
+//
|
|
|
5
|
+
|
|
|
6
|
+import Cocoa
|
|
|
7
|
+
|
|
|
8
|
+private enum ProfilesListPalette {
|
|
|
9
|
+ static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
10
|
+ static let brandBlueHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
|
|
|
11
|
+ static let pageBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
|
|
|
12
|
+ static let cardBackground = NSColor(srgbRed: 252 / 255, green: 252 / 255, blue: 252 / 255, alpha: 1)
|
|
|
13
|
+ static let primaryText = NSColor(srgbRed: 45 / 255, green: 45 / 255, blue: 45 / 255, alpha: 1)
|
|
|
14
|
+ static let secondaryText = NSColor(srgbRed: 118 / 255, green: 118 / 255, blue: 118 / 255, alpha: 1)
|
|
|
15
|
+ static let border = NSColor(srgbRed: 212 / 255, green: 210 / 255, blue: 208 / 255, alpha: 1)
|
|
|
16
|
+ static let destructive = NSColor(srgbRed: 220 / 255, green: 38 / 255, blue: 38 / 255, alpha: 1)
|
|
|
17
|
+}
|
|
|
18
|
+
|
|
|
19
|
+/// Hub for saved job profiles: list, add, edit (opens editor elsewhere), delete.
|
|
|
20
|
+final class ProfilesListPageView: NSView {
|
|
|
21
|
+ var onAddProfile: (() -> Void)?
|
|
|
22
|
+ var onEditProfile: ((UUID) -> Void)?
|
|
|
23
|
+ var onDeleteProfile: ((UUID) -> Void)?
|
|
|
24
|
+
|
|
|
25
|
+ private let scrollView = NSScrollView()
|
|
|
26
|
+ private let documentView = NSView()
|
|
|
27
|
+ private let contentStack = NSStackView()
|
|
|
28
|
+ private let emptyStateLabel = NSTextField(wrappingLabelWithString: "")
|
|
|
29
|
+ private let addButton = ProfilesPrimaryButton(title: "Add new profile →", target: nil, action: nil)
|
|
|
30
|
+
|
|
|
31
|
+ override var userInterfaceLayoutDirection: NSUserInterfaceLayoutDirection {
|
|
|
32
|
+ get { .leftToRight }
|
|
|
33
|
+ set { super.userInterfaceLayoutDirection = .leftToRight }
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ override init(frame frameRect: NSRect) {
|
|
|
37
|
+ super.init(frame: frameRect)
|
|
|
38
|
+ setup()
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ required init?(coder: NSCoder) {
|
|
|
42
|
+ super.init(coder: coder)
|
|
|
43
|
+ setup()
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ func reloadFromStore() {
|
|
|
47
|
+ for row in contentStack.arrangedSubviews {
|
|
|
48
|
+ contentStack.removeArrangedSubview(row)
|
|
|
49
|
+ row.removeFromSuperview()
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ let profiles = SavedProfilesStore.loadAll()
|
|
|
53
|
+ emptyStateLabel.isHidden = !profiles.isEmpty
|
|
|
54
|
+
|
|
|
55
|
+ for profile in profiles {
|
|
|
56
|
+ let row = ProfileListRowView(profile: profile)
|
|
|
57
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
58
|
+ row.onEdit = { [weak self] id in self?.onEditProfile?(id) }
|
|
|
59
|
+ row.onDelete = { [weak self] id in self?.onDeleteProfile?(id) }
|
|
|
60
|
+ contentStack.addArrangedSubview(row)
|
|
|
61
|
+ row.widthAnchor.constraint(equalTo: contentStack.widthAnchor).isActive = true
|
|
|
62
|
+ }
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+ private func setup() {
|
|
|
66
|
+ wantsLayer = true
|
|
|
67
|
+ layer?.backgroundColor = ProfilesListPalette.pageBackground.cgColor
|
|
|
68
|
+ userInterfaceLayoutDirection = .leftToRight
|
|
|
69
|
+
|
|
|
70
|
+ let title = NSTextField(labelWithString: "Profiles")
|
|
|
71
|
+ title.font = .systemFont(ofSize: 22, weight: .semibold)
|
|
|
72
|
+ title.textColor = ProfilesListPalette.primaryText
|
|
|
73
|
+
|
|
|
74
|
+ let subtitle = NSTextField(wrappingLabelWithString: "Create and manage CV profiles. Each profile stores your details on this Mac.")
|
|
|
75
|
+ subtitle.font = .systemFont(ofSize: 13, weight: .regular)
|
|
|
76
|
+ subtitle.textColor = ProfilesListPalette.secondaryText
|
|
|
77
|
+ subtitle.maximumNumberOfLines = 0
|
|
|
78
|
+
|
|
|
79
|
+ emptyStateLabel.stringValue = "No profiles yet. Tap “Add new profile” to create your first one."
|
|
|
80
|
+ emptyStateLabel.font = .systemFont(ofSize: 13, weight: .regular)
|
|
|
81
|
+ emptyStateLabel.textColor = ProfilesListPalette.secondaryText
|
|
|
82
|
+ emptyStateLabel.isHidden = true
|
|
|
83
|
+
|
|
|
84
|
+ addButton.target = self
|
|
|
85
|
+ addButton.action = #selector(didTapAdd)
|
|
|
86
|
+ addButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
87
|
+
|
|
|
88
|
+ let headerStack = NSStackView(views: [title, subtitle, emptyStateLabel, addButton])
|
|
|
89
|
+ headerStack.orientation = .vertical
|
|
|
90
|
+ headerStack.alignment = .leading
|
|
|
91
|
+ headerStack.spacing = 10
|
|
|
92
|
+ headerStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
93
|
+ headerStack.setCustomSpacing(16, after: subtitle)
|
|
|
94
|
+
|
|
|
95
|
+ contentStack.orientation = .vertical
|
|
|
96
|
+ contentStack.alignment = .leading
|
|
|
97
|
+ contentStack.spacing = 12
|
|
|
98
|
+ contentStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
99
|
+
|
|
|
100
|
+ documentView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
101
|
+ documentView.addSubview(headerStack)
|
|
|
102
|
+ documentView.addSubview(contentStack)
|
|
|
103
|
+
|
|
|
104
|
+ scrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
105
|
+ scrollView.drawsBackground = false
|
|
|
106
|
+ scrollView.hasVerticalScroller = true
|
|
|
107
|
+ scrollView.hasHorizontalScroller = false
|
|
|
108
|
+ scrollView.autohidesScrollers = true
|
|
|
109
|
+ scrollView.borderType = .noBorder
|
|
|
110
|
+ scrollView.documentView = documentView
|
|
|
111
|
+
|
|
|
112
|
+ addSubview(scrollView)
|
|
|
113
|
+
|
|
|
114
|
+ NSLayoutConstraint.activate([
|
|
|
115
|
+ scrollView.leftAnchor.constraint(equalTo: leftAnchor),
|
|
|
116
|
+ scrollView.rightAnchor.constraint(equalTo: rightAnchor),
|
|
|
117
|
+ scrollView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
118
|
+ scrollView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
119
|
+
|
|
|
120
|
+ documentView.leftAnchor.constraint(equalTo: scrollView.contentView.leftAnchor),
|
|
|
121
|
+ documentView.rightAnchor.constraint(equalTo: scrollView.contentView.rightAnchor),
|
|
|
122
|
+ documentView.topAnchor.constraint(equalTo: scrollView.contentView.topAnchor),
|
|
|
123
|
+ documentView.bottomAnchor.constraint(equalTo: contentStack.bottomAnchor, constant: 32),
|
|
|
124
|
+
|
|
|
125
|
+ headerStack.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: 32),
|
|
|
126
|
+ headerStack.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -32),
|
|
|
127
|
+ headerStack.topAnchor.constraint(equalTo: documentView.topAnchor, constant: 24),
|
|
|
128
|
+
|
|
|
129
|
+ contentStack.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: 32),
|
|
|
130
|
+ contentStack.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -32),
|
|
|
131
|
+ contentStack.topAnchor.constraint(equalTo: headerStack.bottomAnchor, constant: 24),
|
|
|
132
|
+
|
|
|
133
|
+ headerStack.widthAnchor.constraint(equalTo: documentView.widthAnchor, constant: -64),
|
|
|
134
|
+ contentStack.widthAnchor.constraint(equalTo: documentView.widthAnchor, constant: -64)
|
|
|
135
|
+ ])
|
|
|
136
|
+
|
|
|
137
|
+ reloadFromStore()
|
|
|
138
|
+ }
|
|
|
139
|
+
|
|
|
140
|
+ @objc private func didTapAdd() {
|
|
|
141
|
+ onAddProfile?()
|
|
|
142
|
+ }
|
|
|
143
|
+}
|
|
|
144
|
+
|
|
|
145
|
+// MARK: - Row
|
|
|
146
|
+
|
|
|
147
|
+private final class ProfileListRowView: NSView {
|
|
|
148
|
+ var onEdit: ((UUID) -> Void)?
|
|
|
149
|
+ var onDelete: ((UUID) -> Void)?
|
|
|
150
|
+
|
|
|
151
|
+ private let profileID: UUID
|
|
|
152
|
+ private let editButton = NSButton(title: "Edit", target: nil, action: nil)
|
|
|
153
|
+ private let deleteButton = NSButton(title: "Delete", target: nil, action: nil)
|
|
|
154
|
+
|
|
|
155
|
+ init(profile: SavedProfile) {
|
|
|
156
|
+ self.profileID = profile.id
|
|
|
157
|
+ super.init(frame: .zero)
|
|
|
158
|
+ translatesAutoresizingMaskIntoConstraints = false
|
|
|
159
|
+ wantsLayer = true
|
|
|
160
|
+ layer?.cornerRadius = 14
|
|
|
161
|
+ layer?.borderWidth = 1
|
|
|
162
|
+ layer?.borderColor = ProfilesListPalette.border.cgColor
|
|
|
163
|
+ layer?.backgroundColor = ProfilesListPalette.cardBackground.cgColor
|
|
|
164
|
+ if #available(macOS 11.0, *) {
|
|
|
165
|
+ layer?.cornerCurve = .continuous
|
|
|
166
|
+ }
|
|
|
167
|
+
|
|
|
168
|
+ let name = NSTextField(labelWithString: profile.profileDisplayName.isEmpty ? "Untitled profile" : profile.profileDisplayName)
|
|
|
169
|
+ name.font = .systemFont(ofSize: 15, weight: .semibold)
|
|
|
170
|
+ name.textColor = ProfilesListPalette.primaryText
|
|
|
171
|
+
|
|
|
172
|
+ let detailParts = [profile.personal.fullName, profile.personal.email].filter { !$0.isEmpty }
|
|
|
173
|
+ let detail = NSTextField(wrappingLabelWithString: detailParts.isEmpty ? "No contact details yet" : detailParts.joined(separator: " · "))
|
|
|
174
|
+ detail.font = .systemFont(ofSize: 12, weight: .regular)
|
|
|
175
|
+ detail.textColor = ProfilesListPalette.secondaryText
|
|
|
176
|
+ detail.maximumNumberOfLines = 2
|
|
|
177
|
+
|
|
|
178
|
+ let textStack = NSStackView(views: [name, detail])
|
|
|
179
|
+ textStack.orientation = .vertical
|
|
|
180
|
+ textStack.alignment = .leading
|
|
|
181
|
+ textStack.spacing = 4
|
|
|
182
|
+ textStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
183
|
+
|
|
|
184
|
+ editButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
185
|
+ editButton.bezelStyle = .rounded
|
|
|
186
|
+ editButton.isBordered = true
|
|
|
187
|
+ editButton.font = .systemFont(ofSize: 12, weight: .medium)
|
|
|
188
|
+ editButton.target = self
|
|
|
189
|
+ editButton.action = #selector(didTapEdit)
|
|
|
190
|
+
|
|
|
191
|
+ deleteButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
192
|
+ deleteButton.bezelStyle = .rounded
|
|
|
193
|
+ deleteButton.isBordered = false
|
|
|
194
|
+ deleteButton.font = .systemFont(ofSize: 12, weight: .medium)
|
|
|
195
|
+ deleteButton.contentTintColor = ProfilesListPalette.destructive
|
|
|
196
|
+ deleteButton.target = self
|
|
|
197
|
+ deleteButton.action = #selector(didTapDelete)
|
|
|
198
|
+
|
|
|
199
|
+ let spacer = NSView()
|
|
|
200
|
+ spacer.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
|
201
|
+
|
|
|
202
|
+ let actions = NSStackView(views: [editButton, deleteButton])
|
|
|
203
|
+ actions.orientation = .horizontal
|
|
|
204
|
+ actions.spacing = 8
|
|
|
205
|
+ actions.alignment = .centerY
|
|
|
206
|
+ actions.translatesAutoresizingMaskIntoConstraints = false
|
|
|
207
|
+
|
|
|
208
|
+ let row = NSStackView(views: [textStack, spacer, actions])
|
|
|
209
|
+ row.orientation = .horizontal
|
|
|
210
|
+ row.alignment = .top
|
|
|
211
|
+ row.spacing = 16
|
|
|
212
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
213
|
+
|
|
|
214
|
+ addSubview(row)
|
|
|
215
|
+ NSLayoutConstraint.activate([
|
|
|
216
|
+ row.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
|
|
|
217
|
+ row.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
|
|
|
218
|
+ row.topAnchor.constraint(equalTo: topAnchor, constant: 16),
|
|
|
219
|
+ row.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -16)
|
|
|
220
|
+ ])
|
|
|
221
|
+ }
|
|
|
222
|
+
|
|
|
223
|
+ required init?(coder: NSCoder) {
|
|
|
224
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ @objc private func didTapEdit() {
|
|
|
228
|
+ onEdit?(profileID)
|
|
|
229
|
+ }
|
|
|
230
|
+
|
|
|
231
|
+ @objc private func didTapDelete() {
|
|
|
232
|
+ onDelete?(profileID)
|
|
|
233
|
+ }
|
|
|
234
|
+}
|
|
|
235
|
+
|
|
|
236
|
+// MARK: - Primary CTA (matches profile page button)
|
|
|
237
|
+
|
|
|
238
|
+private final class ProfilesPrimaryButton: NSButton {
|
|
|
239
|
+ private var trackingArea: NSTrackingArea?
|
|
|
240
|
+ private var didPushCursor = false
|
|
|
241
|
+
|
|
|
242
|
+ override init(frame frameRect: NSRect) {
|
|
|
243
|
+ super.init(frame: frameRect)
|
|
|
244
|
+ commonInit()
|
|
|
245
|
+ }
|
|
|
246
|
+
|
|
|
247
|
+ required init?(coder: NSCoder) {
|
|
|
248
|
+ super.init(coder: coder)
|
|
|
249
|
+ commonInit()
|
|
|
250
|
+ }
|
|
|
251
|
+
|
|
|
252
|
+ convenience init(title: String, target: AnyObject?, action: Selector?) {
|
|
|
253
|
+ self.init(frame: .zero)
|
|
|
254
|
+ self.title = title
|
|
|
255
|
+ self.target = target
|
|
|
256
|
+ self.action = action
|
|
|
257
|
+ }
|
|
|
258
|
+
|
|
|
259
|
+ private func commonInit() {
|
|
|
260
|
+ bezelStyle = .rounded
|
|
|
261
|
+ isBordered = false
|
|
|
262
|
+ font = .systemFont(ofSize: 16, weight: .semibold)
|
|
|
263
|
+ contentTintColor = .white
|
|
|
264
|
+ wantsLayer = true
|
|
|
265
|
+ layer?.cornerRadius = 14
|
|
|
266
|
+ if #available(macOS 11.0, *) {
|
|
|
267
|
+ layer?.cornerCurve = .continuous
|
|
|
268
|
+ }
|
|
|
269
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlue.cgColor
|
|
|
270
|
+ }
|
|
|
271
|
+
|
|
|
272
|
+ override func updateTrackingAreas() {
|
|
|
273
|
+ super.updateTrackingAreas()
|
|
|
274
|
+ if let trackingArea { removeTrackingArea(trackingArea) }
|
|
|
275
|
+ let area = NSTrackingArea(
|
|
|
276
|
+ rect: bounds,
|
|
|
277
|
+ options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
|
|
|
278
|
+ owner: self,
|
|
|
279
|
+ userInfo: nil
|
|
|
280
|
+ )
|
|
|
281
|
+ addTrackingArea(area)
|
|
|
282
|
+ trackingArea = area
|
|
|
283
|
+ }
|
|
|
284
|
+
|
|
|
285
|
+ override func mouseEntered(with event: NSEvent) {
|
|
|
286
|
+ super.mouseEntered(with: event)
|
|
|
287
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlueHover.cgColor
|
|
|
288
|
+ if !didPushCursor {
|
|
|
289
|
+ NSCursor.pointingHand.push()
|
|
|
290
|
+ didPushCursor = true
|
|
|
291
|
+ }
|
|
|
292
|
+ }
|
|
|
293
|
+
|
|
|
294
|
+ override func mouseExited(with event: NSEvent) {
|
|
|
295
|
+ super.mouseExited(with: event)
|
|
|
296
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlue.cgColor
|
|
|
297
|
+ if didPushCursor {
|
|
|
298
|
+ NSCursor.pop()
|
|
|
299
|
+ didPushCursor = false
|
|
|
300
|
+ }
|
|
|
301
|
+ }
|
|
|
302
|
+
|
|
|
303
|
+ override func viewWillMove(toWindow newWindow: NSWindow?) {
|
|
|
304
|
+ super.viewWillMove(toWindow: newWindow)
|
|
|
305
|
+ if newWindow == nil, didPushCursor {
|
|
|
306
|
+ NSCursor.pop()
|
|
|
307
|
+ didPushCursor = false
|
|
|
308
|
+ }
|
|
|
309
|
+ }
|
|
|
310
|
+}
|