|
|
@@ -0,0 +1,310 @@
|
|
|
+//
|
|
|
+// ProfilesListPageView.swift
|
|
|
+// App for Indeed
|
|
|
+//
|
|
|
+
|
|
|
+import Cocoa
|
|
|
+
|
|
|
+private enum ProfilesListPalette {
|
|
|
+ static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
+ static let brandBlueHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
|
|
|
+ static let pageBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
|
|
|
+ static let cardBackground = NSColor(srgbRed: 252 / 255, green: 252 / 255, blue: 252 / 255, alpha: 1)
|
|
|
+ static let primaryText = NSColor(srgbRed: 45 / 255, green: 45 / 255, blue: 45 / 255, alpha: 1)
|
|
|
+ static let secondaryText = NSColor(srgbRed: 118 / 255, green: 118 / 255, blue: 118 / 255, alpha: 1)
|
|
|
+ static let border = NSColor(srgbRed: 212 / 255, green: 210 / 255, blue: 208 / 255, alpha: 1)
|
|
|
+ static let destructive = NSColor(srgbRed: 220 / 255, green: 38 / 255, blue: 38 / 255, alpha: 1)
|
|
|
+}
|
|
|
+
|
|
|
+/// Hub for saved job profiles: list, add, edit (opens editor elsewhere), delete.
|
|
|
+final class ProfilesListPageView: NSView {
|
|
|
+ var onAddProfile: (() -> Void)?
|
|
|
+ var onEditProfile: ((UUID) -> Void)?
|
|
|
+ var onDeleteProfile: ((UUID) -> Void)?
|
|
|
+
|
|
|
+ private let scrollView = NSScrollView()
|
|
|
+ private let documentView = NSView()
|
|
|
+ private let contentStack = NSStackView()
|
|
|
+ private let emptyStateLabel = NSTextField(wrappingLabelWithString: "")
|
|
|
+ private let addButton = ProfilesPrimaryButton(title: "Add new profile →", target: nil, action: nil)
|
|
|
+
|
|
|
+ override var userInterfaceLayoutDirection: NSUserInterfaceLayoutDirection {
|
|
|
+ get { .leftToRight }
|
|
|
+ set { super.userInterfaceLayoutDirection = .leftToRight }
|
|
|
+ }
|
|
|
+
|
|
|
+ override init(frame frameRect: NSRect) {
|
|
|
+ super.init(frame: frameRect)
|
|
|
+ setup()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ super.init(coder: coder)
|
|
|
+ setup()
|
|
|
+ }
|
|
|
+
|
|
|
+ func reloadFromStore() {
|
|
|
+ for row in contentStack.arrangedSubviews {
|
|
|
+ contentStack.removeArrangedSubview(row)
|
|
|
+ row.removeFromSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let profiles = SavedProfilesStore.loadAll()
|
|
|
+ emptyStateLabel.isHidden = !profiles.isEmpty
|
|
|
+
|
|
|
+ for profile in profiles {
|
|
|
+ let row = ProfileListRowView(profile: profile)
|
|
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ row.onEdit = { [weak self] id in self?.onEditProfile?(id) }
|
|
|
+ row.onDelete = { [weak self] id in self?.onDeleteProfile?(id) }
|
|
|
+ contentStack.addArrangedSubview(row)
|
|
|
+ row.widthAnchor.constraint(equalTo: contentStack.widthAnchor).isActive = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setup() {
|
|
|
+ wantsLayer = true
|
|
|
+ layer?.backgroundColor = ProfilesListPalette.pageBackground.cgColor
|
|
|
+ userInterfaceLayoutDirection = .leftToRight
|
|
|
+
|
|
|
+ let title = NSTextField(labelWithString: "Profiles")
|
|
|
+ title.font = .systemFont(ofSize: 22, weight: .semibold)
|
|
|
+ title.textColor = ProfilesListPalette.primaryText
|
|
|
+
|
|
|
+ let subtitle = NSTextField(wrappingLabelWithString: "Create and manage CV profiles. Each profile stores your details on this Mac.")
|
|
|
+ subtitle.font = .systemFont(ofSize: 13, weight: .regular)
|
|
|
+ subtitle.textColor = ProfilesListPalette.secondaryText
|
|
|
+ subtitle.maximumNumberOfLines = 0
|
|
|
+
|
|
|
+ emptyStateLabel.stringValue = "No profiles yet. Tap “Add new profile” to create your first one."
|
|
|
+ emptyStateLabel.font = .systemFont(ofSize: 13, weight: .regular)
|
|
|
+ emptyStateLabel.textColor = ProfilesListPalette.secondaryText
|
|
|
+ emptyStateLabel.isHidden = true
|
|
|
+
|
|
|
+ addButton.target = self
|
|
|
+ addButton.action = #selector(didTapAdd)
|
|
|
+ addButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+
|
|
|
+ let headerStack = NSStackView(views: [title, subtitle, emptyStateLabel, addButton])
|
|
|
+ headerStack.orientation = .vertical
|
|
|
+ headerStack.alignment = .leading
|
|
|
+ headerStack.spacing = 10
|
|
|
+ headerStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ headerStack.setCustomSpacing(16, after: subtitle)
|
|
|
+
|
|
|
+ contentStack.orientation = .vertical
|
|
|
+ contentStack.alignment = .leading
|
|
|
+ contentStack.spacing = 12
|
|
|
+ contentStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+
|
|
|
+ documentView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ documentView.addSubview(headerStack)
|
|
|
+ documentView.addSubview(contentStack)
|
|
|
+
|
|
|
+ scrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ scrollView.drawsBackground = false
|
|
|
+ scrollView.hasVerticalScroller = true
|
|
|
+ scrollView.hasHorizontalScroller = false
|
|
|
+ scrollView.autohidesScrollers = true
|
|
|
+ scrollView.borderType = .noBorder
|
|
|
+ scrollView.documentView = documentView
|
|
|
+
|
|
|
+ addSubview(scrollView)
|
|
|
+
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ scrollView.leftAnchor.constraint(equalTo: leftAnchor),
|
|
|
+ scrollView.rightAnchor.constraint(equalTo: rightAnchor),
|
|
|
+ scrollView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
+ scrollView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
+
|
|
|
+ documentView.leftAnchor.constraint(equalTo: scrollView.contentView.leftAnchor),
|
|
|
+ documentView.rightAnchor.constraint(equalTo: scrollView.contentView.rightAnchor),
|
|
|
+ documentView.topAnchor.constraint(equalTo: scrollView.contentView.topAnchor),
|
|
|
+ documentView.bottomAnchor.constraint(equalTo: contentStack.bottomAnchor, constant: 32),
|
|
|
+
|
|
|
+ headerStack.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: 32),
|
|
|
+ headerStack.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -32),
|
|
|
+ headerStack.topAnchor.constraint(equalTo: documentView.topAnchor, constant: 24),
|
|
|
+
|
|
|
+ contentStack.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: 32),
|
|
|
+ contentStack.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -32),
|
|
|
+ contentStack.topAnchor.constraint(equalTo: headerStack.bottomAnchor, constant: 24),
|
|
|
+
|
|
|
+ headerStack.widthAnchor.constraint(equalTo: documentView.widthAnchor, constant: -64),
|
|
|
+ contentStack.widthAnchor.constraint(equalTo: documentView.widthAnchor, constant: -64)
|
|
|
+ ])
|
|
|
+
|
|
|
+ reloadFromStore()
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func didTapAdd() {
|
|
|
+ onAddProfile?()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Row
|
|
|
+
|
|
|
+private final class ProfileListRowView: NSView {
|
|
|
+ var onEdit: ((UUID) -> Void)?
|
|
|
+ var onDelete: ((UUID) -> Void)?
|
|
|
+
|
|
|
+ private let profileID: UUID
|
|
|
+ private let editButton = NSButton(title: "Edit", target: nil, action: nil)
|
|
|
+ private let deleteButton = NSButton(title: "Delete", target: nil, action: nil)
|
|
|
+
|
|
|
+ init(profile: SavedProfile) {
|
|
|
+ self.profileID = profile.id
|
|
|
+ super.init(frame: .zero)
|
|
|
+ translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ wantsLayer = true
|
|
|
+ layer?.cornerRadius = 14
|
|
|
+ layer?.borderWidth = 1
|
|
|
+ layer?.borderColor = ProfilesListPalette.border.cgColor
|
|
|
+ layer?.backgroundColor = ProfilesListPalette.cardBackground.cgColor
|
|
|
+ if #available(macOS 11.0, *) {
|
|
|
+ layer?.cornerCurve = .continuous
|
|
|
+ }
|
|
|
+
|
|
|
+ let name = NSTextField(labelWithString: profile.profileDisplayName.isEmpty ? "Untitled profile" : profile.profileDisplayName)
|
|
|
+ name.font = .systemFont(ofSize: 15, weight: .semibold)
|
|
|
+ name.textColor = ProfilesListPalette.primaryText
|
|
|
+
|
|
|
+ let detailParts = [profile.personal.fullName, profile.personal.email].filter { !$0.isEmpty }
|
|
|
+ let detail = NSTextField(wrappingLabelWithString: detailParts.isEmpty ? "No contact details yet" : detailParts.joined(separator: " · "))
|
|
|
+ detail.font = .systemFont(ofSize: 12, weight: .regular)
|
|
|
+ detail.textColor = ProfilesListPalette.secondaryText
|
|
|
+ detail.maximumNumberOfLines = 2
|
|
|
+
|
|
|
+ let textStack = NSStackView(views: [name, detail])
|
|
|
+ textStack.orientation = .vertical
|
|
|
+ textStack.alignment = .leading
|
|
|
+ textStack.spacing = 4
|
|
|
+ textStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+
|
|
|
+ editButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ editButton.bezelStyle = .rounded
|
|
|
+ editButton.isBordered = true
|
|
|
+ editButton.font = .systemFont(ofSize: 12, weight: .medium)
|
|
|
+ editButton.target = self
|
|
|
+ editButton.action = #selector(didTapEdit)
|
|
|
+
|
|
|
+ deleteButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ deleteButton.bezelStyle = .rounded
|
|
|
+ deleteButton.isBordered = false
|
|
|
+ deleteButton.font = .systemFont(ofSize: 12, weight: .medium)
|
|
|
+ deleteButton.contentTintColor = ProfilesListPalette.destructive
|
|
|
+ deleteButton.target = self
|
|
|
+ deleteButton.action = #selector(didTapDelete)
|
|
|
+
|
|
|
+ let spacer = NSView()
|
|
|
+ spacer.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
|
+
|
|
|
+ let actions = NSStackView(views: [editButton, deleteButton])
|
|
|
+ actions.orientation = .horizontal
|
|
|
+ actions.spacing = 8
|
|
|
+ actions.alignment = .centerY
|
|
|
+ actions.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+
|
|
|
+ let row = NSStackView(views: [textStack, spacer, actions])
|
|
|
+ row.orientation = .horizontal
|
|
|
+ row.alignment = .top
|
|
|
+ row.spacing = 16
|
|
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+
|
|
|
+ addSubview(row)
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ row.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
|
|
|
+ row.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
|
|
|
+ row.topAnchor.constraint(equalTo: topAnchor, constant: 16),
|
|
|
+ row.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -16)
|
|
|
+ ])
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func didTapEdit() {
|
|
|
+ onEdit?(profileID)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func didTapDelete() {
|
|
|
+ onDelete?(profileID)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Primary CTA (matches profile page button)
|
|
|
+
|
|
|
+private final class ProfilesPrimaryButton: NSButton {
|
|
|
+ private var trackingArea: NSTrackingArea?
|
|
|
+ private var didPushCursor = false
|
|
|
+
|
|
|
+ override init(frame frameRect: NSRect) {
|
|
|
+ super.init(frame: frameRect)
|
|
|
+ commonInit()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ super.init(coder: coder)
|
|
|
+ commonInit()
|
|
|
+ }
|
|
|
+
|
|
|
+ convenience init(title: String, target: AnyObject?, action: Selector?) {
|
|
|
+ self.init(frame: .zero)
|
|
|
+ self.title = title
|
|
|
+ self.target = target
|
|
|
+ self.action = action
|
|
|
+ }
|
|
|
+
|
|
|
+ private func commonInit() {
|
|
|
+ bezelStyle = .rounded
|
|
|
+ isBordered = false
|
|
|
+ font = .systemFont(ofSize: 16, weight: .semibold)
|
|
|
+ contentTintColor = .white
|
|
|
+ wantsLayer = true
|
|
|
+ layer?.cornerRadius = 14
|
|
|
+ if #available(macOS 11.0, *) {
|
|
|
+ layer?.cornerCurve = .continuous
|
|
|
+ }
|
|
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlue.cgColor
|
|
|
+ }
|
|
|
+
|
|
|
+ override func updateTrackingAreas() {
|
|
|
+ super.updateTrackingAreas()
|
|
|
+ if let trackingArea { removeTrackingArea(trackingArea) }
|
|
|
+ let area = NSTrackingArea(
|
|
|
+ rect: bounds,
|
|
|
+ options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
|
|
|
+ owner: self,
|
|
|
+ userInfo: nil
|
|
|
+ )
|
|
|
+ addTrackingArea(area)
|
|
|
+ trackingArea = area
|
|
|
+ }
|
|
|
+
|
|
|
+ override func mouseEntered(with event: NSEvent) {
|
|
|
+ super.mouseEntered(with: event)
|
|
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlueHover.cgColor
|
|
|
+ if !didPushCursor {
|
|
|
+ NSCursor.pointingHand.push()
|
|
|
+ didPushCursor = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func mouseExited(with event: NSEvent) {
|
|
|
+ super.mouseExited(with: event)
|
|
|
+ layer?.backgroundColor = ProfilesListPalette.brandBlue.cgColor
|
|
|
+ if didPushCursor {
|
|
|
+ NSCursor.pop()
|
|
|
+ didPushCursor = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillMove(toWindow newWindow: NSWindow?) {
|
|
|
+ super.viewWillMove(toWindow: newWindow)
|
|
|
+ if newWindow == nil, didPushCursor {
|
|
|
+ NSCursor.pop()
|
|
|
+ didPushCursor = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|