Без опису

DashboardView.swift 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. //
  2. // DashboardView.swift
  3. // App for Indeed
  4. //
  5. import Cocoa
  6. import QuartzCore
  7. final class DashboardView: NSView, NSTextFieldDelegate {
  8. /// Indeed.com-inspired neutrals and brand blue (white surfaces, `#2557a7` accent, `#2d2d2d` / `#767676` text, `#d4d2d0` borders).
  9. private enum Theme {
  10. static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  11. static let pageBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  12. static let chromeBackground = NSColor(srgbRed: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1)
  13. static let sidebarBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  14. static let mainHostBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  15. /// Subtitle on the welcome hero: readable blue-gray aligned with brand.
  16. static let welcomeSubtitleText = NSColor(srgbRed: 52 / 255, green: 92 / 255, blue: 142 / 255, alpha: 1)
  17. static let selectionFill = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.12)
  18. static let cardBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  19. static let toggleBackground = NSColor(srgbRed: 232 / 255, green: 232 / 255, blue: 232 / 255, alpha: 1)
  20. static let primaryText = NSColor(srgbRed: 45 / 255, green: 45 / 255, blue: 45 / 255, alpha: 1)
  21. static let secondaryText = NSColor(srgbRed: 118 / 255, green: 118 / 255, blue: 118 / 255, alpha: 1)
  22. static let tertiaryText = NSColor(srgbRed: 118 / 255, green: 118 / 255, blue: 118 / 255, alpha: 1)
  23. static let border = NSColor(srgbRed: 212 / 255, green: 210 / 255, blue: 208 / 255, alpha: 1)
  24. /// Job search bar outer stroke (charcoal).
  25. static let searchBarBorder = NSColor(srgbRed: 58 / 255, green: 58 / 255, blue: 58 / 255, alpha: 1)
  26. static let proCardFill = NSColor(srgbRed: 239 / 255, green: 244 / 255, blue: 252 / 255, alpha: 1)
  27. static let proCardBorder = NSColor(srgbRed: 212 / 255, green: 210 / 255, blue: 208 / 255, alpha: 1)
  28. static let proAccent = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  29. static let proCTABackground = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  30. static let proCTAText = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  31. /// Slightly lighter blue for the top of the search-bar “Find jobs” pill (reads less flat than a solid fill).
  32. static let findJobsCTAHighlight = NSColor(srgbRed: 54 / 255, green: 110 / 255, blue: 198 / 255, alpha: 1)
  33. }
  34. private let contentStack = NSStackView()
  35. private let chromeContainer = NSView()
  36. private let sidebar = NSStackView()
  37. private let mainHost = NSView()
  38. private let mainOverlay = NSStackView()
  39. private let greetingLabel = NSTextField(labelWithString: "")
  40. private let subtitleLabel = NSTextField(labelWithString: "")
  41. private let searchBarShadowHost = NSView()
  42. private let searchCard = NSView()
  43. private let jobSearchIcon = NSImageView()
  44. private let jobKeywordsField = NSTextField()
  45. private let findJobsButton = NSButton()
  46. private let findJobsCTAHost = NSView()
  47. private let findJobsCTAChrome = NSView()
  48. private var findJobsCTAGradientLayer: CAGradientLayer?
  49. private let jobListingsScrollView = NSScrollView()
  50. /// Flipped so short result lists stay visually under the search bar instead of leaving a gap above the cards.
  51. private let jobListingsContainer = JobListingsDocumentView()
  52. private let jobListingsStack = NSStackView()
  53. /// Shown when a sidebar item other than Home is selected.
  54. private let nonHomeHost = NSView()
  55. private let nonHomeTitleLabel = NSTextField(labelWithString: "")
  56. private let nonHomeSubtitleLabel = NSTextField(wrappingLabelWithString: "")
  57. private var currentSidebarItems: [SidebarItem] = []
  58. private var selectedSidebarIndex: Int = 0
  59. /// Full list from `DashboardData`; results are shown after the user runs a search.
  60. private var catalogJobListings: [JobListing] = []
  61. /// Last successful search result set (used when removing a card with the dismiss control).
  62. private var lastSearchResults: [JobListing] = []
  63. private var lastNoResultsQuery: String?
  64. private var savedJobs: Set<JobListing> = []
  65. override init(frame frameRect: NSRect) {
  66. super.init(frame: frameRect)
  67. setupLayout()
  68. }
  69. required init?(coder: NSCoder) {
  70. super.init(coder: coder)
  71. setupLayout()
  72. }
  73. override func layout() {
  74. super.layout()
  75. updateSearchBarShadowPath()
  76. findJobsCTAGradientLayer?.frame = findJobsCTAChrome.bounds
  77. updateFindJobsCTAShadowPath()
  78. updateJobListingDescriptionWidths()
  79. }
  80. func render(_ data: DashboardData) {
  81. greetingLabel.stringValue = "Welcome"
  82. subtitleLabel.stringValue = data.subtitle
  83. currentSidebarItems = data.sidebarItems
  84. if selectedSidebarIndex >= currentSidebarItems.count {
  85. selectedSidebarIndex = max(0, currentSidebarItems.count - 1)
  86. }
  87. configureSidebar()
  88. catalogJobListings = data.jobListings
  89. savedJobs = []
  90. configureJobListings([], noResultsForQuery: nil)
  91. updateMainContentVisibility()
  92. }
  93. private func setupLayout() {
  94. wantsLayer = true
  95. layer?.backgroundColor = Theme.pageBackground.cgColor
  96. contentStack.orientation = .horizontal
  97. contentStack.spacing = 20
  98. contentStack.distribution = .fill
  99. contentStack.translatesAutoresizingMaskIntoConstraints = false
  100. contentStack.alignment = .height
  101. contentStack.edgeInsets = NSEdgeInsets(top: 24, left: 24, bottom: 24, right: 24)
  102. chromeContainer.translatesAutoresizingMaskIntoConstraints = false
  103. chromeContainer.wantsLayer = true
  104. chromeContainer.layer?.backgroundColor = Theme.chromeBackground.cgColor
  105. chromeContainer.layer?.cornerRadius = 0
  106. addSubview(chromeContainer)
  107. chromeContainer.addSubview(contentStack)
  108. sidebar.orientation = .vertical
  109. sidebar.spacing = 10
  110. sidebar.distribution = .fill
  111. sidebar.alignment = .leading
  112. sidebar.wantsLayer = true
  113. sidebar.layer?.backgroundColor = Theme.sidebarBackground.cgColor
  114. sidebar.layer?.cornerRadius = 16
  115. sidebar.edgeInsets = NSEdgeInsets(top: 18, left: 14, bottom: 18, right: 14)
  116. sidebar.translatesAutoresizingMaskIntoConstraints = false
  117. mainHost.translatesAutoresizingMaskIntoConstraints = false
  118. mainHost.wantsLayer = true
  119. mainHost.layer?.backgroundColor = Theme.mainHostBackground.cgColor
  120. mainHost.layer?.cornerRadius = 16
  121. mainHost.layer?.masksToBounds = true
  122. sidebar.setContentHuggingPriority(.required, for: .horizontal)
  123. mainHost.setContentHuggingPriority(.defaultLow, for: .horizontal)
  124. mainHost.addSubview(mainOverlay)
  125. configureNonHomePlaceholder()
  126. mainHost.addSubview(nonHomeHost)
  127. mainOverlay.orientation = .vertical
  128. mainOverlay.spacing = 0
  129. mainOverlay.alignment = .centerX
  130. mainOverlay.distribution = .fill
  131. mainOverlay.translatesAutoresizingMaskIntoConstraints = false
  132. mainOverlay.setContentHuggingPriority(.defaultLow, for: .vertical)
  133. greetingLabel.font = .systemFont(ofSize: 32, weight: .bold)
  134. greetingLabel.textColor = Theme.brandBlue
  135. greetingLabel.alignment = .center
  136. greetingLabel.maximumNumberOfLines = 1
  137. subtitleLabel.font = .systemFont(ofSize: 15, weight: .regular)
  138. subtitleLabel.textColor = Theme.welcomeSubtitleText
  139. subtitleLabel.alignment = .center
  140. subtitleLabel.maximumNumberOfLines = 2
  141. let topInset = NSView()
  142. topInset.translatesAutoresizingMaskIntoConstraints = false
  143. topInset.heightAnchor.constraint(equalToConstant: 32).isActive = true
  144. configureSearchBar()
  145. let titleBlock = NSStackView(views: [greetingLabel, subtitleLabel])
  146. titleBlock.orientation = .vertical
  147. titleBlock.spacing = 10
  148. titleBlock.alignment = .centerX
  149. let midSpacer = NSView()
  150. midSpacer.translatesAutoresizingMaskIntoConstraints = false
  151. midSpacer.heightAnchor.constraint(equalToConstant: 20).isActive = true
  152. let listingsTopSpacer = NSView()
  153. listingsTopSpacer.translatesAutoresizingMaskIntoConstraints = false
  154. listingsTopSpacer.heightAnchor.constraint(equalToConstant: 12).isActive = true
  155. jobListingsContainer.translatesAutoresizingMaskIntoConstraints = false
  156. jobListingsStack.orientation = .vertical
  157. jobListingsStack.spacing = 14
  158. // `.leading` keeps cards left-anchored; explicit width constraints below stretch each card across the full row.
  159. jobListingsStack.alignment = .leading
  160. jobListingsStack.distribution = .fill
  161. jobListingsStack.translatesAutoresizingMaskIntoConstraints = false
  162. jobListingsStack.setContentHuggingPriority(.defaultHigh, for: .vertical)
  163. jobListingsStack.setHuggingPriority(.defaultLow, for: .horizontal)
  164. jobListingsContainer.addSubview(jobListingsStack)
  165. NSLayoutConstraint.activate([
  166. jobListingsStack.leadingAnchor.constraint(equalTo: jobListingsContainer.leadingAnchor),
  167. jobListingsStack.trailingAnchor.constraint(equalTo: jobListingsContainer.trailingAnchor),
  168. jobListingsStack.topAnchor.constraint(equalTo: jobListingsContainer.topAnchor),
  169. jobListingsStack.bottomAnchor.constraint(equalTo: jobListingsContainer.bottomAnchor)
  170. ])
  171. jobListingsScrollView.translatesAutoresizingMaskIntoConstraints = false
  172. jobListingsScrollView.hasVerticalScroller = true
  173. jobListingsScrollView.hasHorizontalScroller = false
  174. jobListingsScrollView.autohidesScrollers = true
  175. jobListingsScrollView.drawsBackground = false
  176. jobListingsScrollView.borderType = .noBorder
  177. jobListingsScrollView.documentView = jobListingsContainer
  178. jobListingsScrollView.setContentHuggingPriority(.defaultLow, for: .vertical)
  179. jobListingsScrollView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
  180. mainOverlay.addArrangedSubview(topInset)
  181. mainOverlay.addArrangedSubview(titleBlock)
  182. mainOverlay.addArrangedSubview(midSpacer)
  183. mainOverlay.addArrangedSubview(searchBarShadowHost)
  184. mainOverlay.addArrangedSubview(listingsTopSpacer)
  185. mainOverlay.addArrangedSubview(jobListingsScrollView)
  186. contentStack.addArrangedSubview(sidebar)
  187. contentStack.addArrangedSubview(mainHost)
  188. NSLayoutConstraint.activate([
  189. chromeContainer.leadingAnchor.constraint(equalTo: leadingAnchor),
  190. chromeContainer.trailingAnchor.constraint(equalTo: trailingAnchor),
  191. chromeContainer.topAnchor.constraint(equalTo: topAnchor),
  192. chromeContainer.bottomAnchor.constraint(equalTo: bottomAnchor),
  193. contentStack.leadingAnchor.constraint(equalTo: chromeContainer.leadingAnchor),
  194. contentStack.trailingAnchor.constraint(equalTo: chromeContainer.trailingAnchor),
  195. contentStack.topAnchor.constraint(equalTo: chromeContainer.topAnchor),
  196. contentStack.bottomAnchor.constraint(equalTo: chromeContainer.bottomAnchor),
  197. sidebar.widthAnchor.constraint(equalToConstant: 218),
  198. mainHost.widthAnchor.constraint(greaterThanOrEqualToConstant: 720),
  199. mainOverlay.leadingAnchor.constraint(equalTo: mainHost.leadingAnchor),
  200. mainOverlay.trailingAnchor.constraint(equalTo: mainHost.trailingAnchor),
  201. mainOverlay.topAnchor.constraint(equalTo: mainHost.topAnchor),
  202. mainOverlay.bottomAnchor.constraint(equalTo: mainHost.bottomAnchor, constant: -24),
  203. nonHomeHost.leadingAnchor.constraint(equalTo: mainHost.leadingAnchor),
  204. nonHomeHost.trailingAnchor.constraint(equalTo: mainHost.trailingAnchor),
  205. nonHomeHost.topAnchor.constraint(equalTo: mainHost.topAnchor),
  206. nonHomeHost.bottomAnchor.constraint(equalTo: mainHost.bottomAnchor, constant: -24),
  207. searchBarShadowHost.widthAnchor.constraint(equalTo: mainOverlay.widthAnchor, multiplier: 0.92),
  208. jobListingsScrollView.widthAnchor.constraint(equalTo: mainOverlay.widthAnchor, multiplier: 0.92),
  209. jobListingsContainer.topAnchor.constraint(equalTo: jobListingsScrollView.contentView.topAnchor),
  210. jobListingsContainer.leadingAnchor.constraint(equalTo: jobListingsScrollView.contentView.leadingAnchor),
  211. jobListingsContainer.widthAnchor.constraint(equalTo: jobListingsScrollView.contentView.widthAnchor),
  212. greetingLabel.leadingAnchor.constraint(equalTo: mainOverlay.leadingAnchor, constant: 24),
  213. greetingLabel.trailingAnchor.constraint(equalTo: mainOverlay.trailingAnchor, constant: -24),
  214. subtitleLabel.leadingAnchor.constraint(equalTo: greetingLabel.leadingAnchor),
  215. subtitleLabel.trailingAnchor.constraint(equalTo: greetingLabel.trailingAnchor)
  216. ])
  217. }
  218. private func updateJobListingDescriptionWidths() {
  219. let containerWidth = jobListingsContainer.bounds.width
  220. guard containerWidth > 1 else { return }
  221. let buttonStripReserve: CGFloat = 200
  222. let fallbackTextColumn = max(1, containerWidth - 32 - buttonStripReserve)
  223. var didChange = false
  224. for card in jobListingsStack.arrangedSubviews {
  225. guard let desc = card.viewWithTag(502) as? NSTextField else { continue }
  226. let columnWidth: CGFloat
  227. if let column = desc.superview, column.bounds.width > 1 {
  228. columnWidth = column.bounds.width
  229. } else {
  230. columnWidth = fallbackTextColumn
  231. }
  232. if abs(desc.preferredMaxLayoutWidth - columnWidth) > 0.5 {
  233. desc.preferredMaxLayoutWidth = columnWidth
  234. desc.invalidateIntrinsicContentSize()
  235. didChange = true
  236. }
  237. }
  238. if didChange {
  239. // Wrapping width changed, so card heights need to recompute against the new intrinsic sizes.
  240. jobListingsStack.needsLayout = true
  241. }
  242. }
  243. private func configureJobListings(_ jobs: [JobListing], noResultsForQuery: String?, updateLastResults: Bool = true) {
  244. if updateLastResults {
  245. lastSearchResults = jobs
  246. lastNoResultsQuery = noResultsForQuery
  247. }
  248. jobListingsStack.arrangedSubviews.forEach {
  249. jobListingsStack.removeArrangedSubview($0)
  250. $0.removeFromSuperview()
  251. }
  252. if jobs.isEmpty, let query = noResultsForQuery, !query.isEmpty {
  253. let empty = NSTextField(wrappingLabelWithString: "No jobs match “\(query)”. Try different keywords or browse the full list with an empty search.")
  254. empty.font = .systemFont(ofSize: 14, weight: .regular)
  255. empty.textColor = Theme.secondaryText
  256. empty.alignment = .center
  257. empty.maximumNumberOfLines = 0
  258. empty.translatesAutoresizingMaskIntoConstraints = false
  259. jobListingsStack.addArrangedSubview(empty)
  260. empty.widthAnchor.constraint(equalTo: jobListingsStack.widthAnchor).isActive = true
  261. return
  262. }
  263. for job in jobs {
  264. let card = makeJobListingCard(job)
  265. jobListingsStack.addArrangedSubview(card)
  266. // Force every card to span the full row instead of hugging its intrinsic content width.
  267. card.widthAnchor.constraint(equalTo: jobListingsStack.widthAnchor).isActive = true
  268. }
  269. }
  270. private func makeJobListingCard(_ job: JobListing) -> NSView {
  271. let card = NSView()
  272. card.translatesAutoresizingMaskIntoConstraints = false
  273. card.wantsLayer = true
  274. card.layer?.backgroundColor = Theme.cardBackground.cgColor
  275. card.layer?.cornerRadius = 12
  276. card.layer?.borderWidth = 1
  277. card.layer?.borderColor = Theme.border.cgColor
  278. card.layer?.masksToBounds = true
  279. let titleField = NSTextField(labelWithString: job.title)
  280. titleField.font = .systemFont(ofSize: 16, weight: .semibold)
  281. titleField.textColor = Theme.primaryText
  282. titleField.maximumNumberOfLines = 2
  283. titleField.lineBreakMode = .byWordWrapping
  284. titleField.translatesAutoresizingMaskIntoConstraints = false
  285. let descriptionField = NSTextField(wrappingLabelWithString: job.description)
  286. descriptionField.font = .systemFont(ofSize: 13, weight: .regular)
  287. descriptionField.textColor = Theme.secondaryText
  288. descriptionField.maximumNumberOfLines = 0
  289. descriptionField.tag = 502
  290. descriptionField.translatesAutoresizingMaskIntoConstraints = false
  291. let applyButton = JobPayloadButton(title: "Apply", target: self, action: #selector(didTapJobApply(_:)))
  292. applyButton.jobPayload = job
  293. applyButton.isBordered = false
  294. applyButton.bezelStyle = .rounded
  295. applyButton.font = .systemFont(ofSize: 13, weight: .semibold)
  296. applyButton.wantsLayer = true
  297. applyButton.layer?.cornerRadius = 6
  298. applyButton.layer?.backgroundColor = Theme.brandBlue.cgColor
  299. applyButton.contentTintColor = Theme.proCTAText
  300. applyButton.focusRingType = .none
  301. applyButton.setContentHuggingPriority(.required, for: .horizontal)
  302. applyButton.setContentCompressionResistancePriority(.required, for: .horizontal)
  303. let savedButton = JobPayloadButton(title: "Saved", target: self, action: #selector(didTapJobSaved(_:)))
  304. savedButton.jobPayload = job
  305. savedButton.setButtonType(.toggle)
  306. savedButton.isBordered = false
  307. savedButton.bezelStyle = .rounded
  308. savedButton.font = .systemFont(ofSize: 13, weight: .semibold)
  309. savedButton.focusRingType = .none
  310. savedButton.state = savedJobs.contains(job) ? .on : .off
  311. styleJobSavedButton(savedButton)
  312. savedButton.setContentHuggingPriority(.required, for: .horizontal)
  313. savedButton.setContentCompressionResistancePriority(.required, for: .horizontal)
  314. let dismissButton = JobPayloadButton()
  315. dismissButton.jobPayload = job
  316. dismissButton.image = NSImage(systemSymbolName: "xmark", accessibilityDescription: "Dismiss")
  317. dismissButton.imagePosition = .imageOnly
  318. dismissButton.imageScaling = .scaleProportionallyDown
  319. dismissButton.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 11, weight: .semibold)
  320. dismissButton.isBordered = false
  321. dismissButton.bezelStyle = .rounded
  322. dismissButton.contentTintColor = Theme.secondaryText
  323. dismissButton.target = self
  324. dismissButton.action = #selector(didTapJobDismiss(_:))
  325. dismissButton.toolTip = "Dismiss"
  326. dismissButton.focusRingType = .none
  327. dismissButton.setContentHuggingPriority(.required, for: .horizontal)
  328. let buttonRow = NSStackView(views: [applyButton, savedButton, dismissButton])
  329. buttonRow.orientation = .horizontal
  330. buttonRow.spacing = 8
  331. buttonRow.alignment = .centerY
  332. buttonRow.translatesAutoresizingMaskIntoConstraints = false
  333. buttonRow.setContentHuggingPriority(.required, for: .horizontal)
  334. buttonRow.setContentCompressionResistancePriority(.required, for: .horizontal)
  335. titleField.setContentHuggingPriority(.defaultLow, for: .horizontal)
  336. titleField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
  337. let titleAndActionsRow = NSStackView(views: [titleField, buttonRow])
  338. titleAndActionsRow.orientation = .horizontal
  339. titleAndActionsRow.spacing = 14
  340. titleAndActionsRow.alignment = .centerY
  341. titleAndActionsRow.distribution = .fill
  342. titleAndActionsRow.translatesAutoresizingMaskIntoConstraints = false
  343. let contentColumn = NSStackView(views: [titleAndActionsRow, descriptionField])
  344. contentColumn.orientation = .vertical
  345. contentColumn.spacing = 6
  346. contentColumn.alignment = .width
  347. contentColumn.translatesAutoresizingMaskIntoConstraints = false
  348. card.addSubview(contentColumn)
  349. NSLayoutConstraint.activate([
  350. contentColumn.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: 16),
  351. contentColumn.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -16),
  352. contentColumn.topAnchor.constraint(equalTo: card.topAnchor, constant: 14),
  353. contentColumn.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -14),
  354. applyButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 72),
  355. applyButton.heightAnchor.constraint(equalToConstant: 28),
  356. savedButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 72),
  357. savedButton.heightAnchor.constraint(equalToConstant: 28),
  358. dismissButton.widthAnchor.constraint(equalToConstant: 28),
  359. dismissButton.heightAnchor.constraint(equalToConstant: 28)
  360. ])
  361. return card
  362. }
  363. private func styleJobSavedButton(_ button: NSButton) {
  364. button.wantsLayer = true
  365. button.layer?.cornerRadius = 6
  366. let on = button.state == .on
  367. if on {
  368. button.layer?.backgroundColor = Theme.selectionFill.cgColor
  369. button.layer?.borderWidth = 1
  370. button.layer?.borderColor = Theme.brandBlue.cgColor
  371. button.contentTintColor = Theme.brandBlue
  372. } else {
  373. button.layer?.backgroundColor = Theme.cardBackground.cgColor
  374. button.layer?.borderWidth = 1
  375. button.layer?.borderColor = Theme.border.cgColor
  376. button.contentTintColor = Theme.primaryText
  377. }
  378. }
  379. @objc private func didTapJobApply(_ sender: NSButton) {
  380. guard let job = (sender as? JobPayloadButton)?.jobPayload else { return }
  381. let allowed = CharacterSet.urlQueryAllowed
  382. let q = job.title.addingPercentEncoding(withAllowedCharacters: allowed) ?? ""
  383. guard let url = URL(string: "https://www.indeed.com/jobs?q=\(q)") else { return }
  384. NSWorkspace.shared.open(url)
  385. }
  386. @objc private func didTapJobSaved(_ sender: NSButton) {
  387. guard let job = (sender as? JobPayloadButton)?.jobPayload else { return }
  388. if savedJobs.contains(job) {
  389. savedJobs.remove(job)
  390. } else {
  391. savedJobs.insert(job)
  392. }
  393. sender.state = savedJobs.contains(job) ? .on : .off
  394. styleJobSavedButton(sender)
  395. }
  396. @objc private func didTapJobDismiss(_ sender: NSButton) {
  397. guard let job = (sender as? JobPayloadButton)?.jobPayload else { return }
  398. lastSearchResults.removeAll { $0 == job }
  399. configureJobListings(lastSearchResults, noResultsForQuery: lastNoResultsQuery)
  400. }
  401. private func configureSearchBar() {
  402. let pillCorner: CGFloat = 27
  403. let barHeight: CGFloat = 54
  404. searchBarShadowHost.translatesAutoresizingMaskIntoConstraints = false
  405. searchBarShadowHost.wantsLayer = true
  406. searchBarShadowHost.layer?.masksToBounds = false
  407. searchBarShadowHost.layer?.shadowColor = NSColor.black.withAlphaComponent(0.18).cgColor
  408. searchBarShadowHost.layer?.shadowOffset = CGSize(width: 0, height: 2)
  409. searchBarShadowHost.layer?.shadowRadius = 10
  410. searchBarShadowHost.layer?.shadowOpacity = 1
  411. searchBarShadowHost.setContentHuggingPriority(.defaultHigh, for: .vertical)
  412. searchCard.translatesAutoresizingMaskIntoConstraints = false
  413. searchCard.wantsLayer = true
  414. searchCard.layer?.backgroundColor = Theme.cardBackground.cgColor
  415. searchCard.layer?.cornerRadius = pillCorner
  416. searchCard.layer?.borderWidth = 1
  417. searchCard.layer?.borderColor = Theme.searchBarBorder.cgColor
  418. searchCard.layer?.masksToBounds = true
  419. searchBarShadowHost.addSubview(searchCard)
  420. func configureField(_ field: NSTextField, placeholder: String) {
  421. field.translatesAutoresizingMaskIntoConstraints = false
  422. field.isBordered = false
  423. field.drawsBackground = false
  424. field.focusRingType = .none
  425. field.font = .systemFont(ofSize: 14, weight: .regular)
  426. field.textColor = Theme.primaryText
  427. field.delegate = self
  428. field.placeholderAttributedString = NSAttributedString(
  429. string: placeholder,
  430. attributes: [
  431. .foregroundColor: Theme.secondaryText,
  432. .font: NSFont.systemFont(ofSize: 14, weight: .regular)
  433. ]
  434. )
  435. field.cell?.usesSingleLineMode = true
  436. field.cell?.wraps = false
  437. field.cell?.isScrollable = true
  438. field.target = self
  439. field.action = #selector(didSubmitSearch)
  440. }
  441. jobSearchIcon.translatesAutoresizingMaskIntoConstraints = false
  442. jobSearchIcon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 15, weight: .medium)
  443. jobSearchIcon.image = NSImage(systemSymbolName: "magnifyingglass", accessibilityDescription: "Job search")
  444. jobSearchIcon.contentTintColor = Theme.primaryText
  445. configureField(jobKeywordsField, placeholder: "Job title, keywords, or company")
  446. let ctaHeight: CGFloat = 42
  447. let ctaCorner = ctaHeight / 2
  448. findJobsCTAHost.translatesAutoresizingMaskIntoConstraints = false
  449. findJobsCTAHost.wantsLayer = true
  450. findJobsCTAHost.layer?.masksToBounds = false
  451. findJobsCTAHost.layer?.shadowColor = NSColor.black.cgColor
  452. findJobsCTAHost.layer?.shadowOpacity = 0.16
  453. findJobsCTAHost.layer?.shadowOffset = CGSize(width: 0, height: 2)
  454. findJobsCTAHost.layer?.shadowRadius = 6
  455. findJobsCTAChrome.translatesAutoresizingMaskIntoConstraints = false
  456. findJobsCTAChrome.wantsLayer = true
  457. findJobsCTAChrome.layer?.masksToBounds = true
  458. findJobsCTAChrome.layer?.cornerRadius = ctaCorner
  459. if #available(macOS 11.0, *) {
  460. findJobsCTAChrome.layer?.cornerCurve = .continuous
  461. }
  462. let gradient = CAGradientLayer()
  463. gradient.colors = [Theme.findJobsCTAHighlight.cgColor, Theme.brandBlue.cgColor]
  464. gradient.startPoint = CGPoint(x: 0.5, y: 1)
  465. gradient.endPoint = CGPoint(x: 0.5, y: 0)
  466. findJobsCTAChrome.layer?.addSublayer(gradient)
  467. findJobsCTAGradientLayer = gradient
  468. findJobsButton.translatesAutoresizingMaskIntoConstraints = false
  469. findJobsButton.title = ""
  470. findJobsButton.attributedTitle = NSAttributedString(
  471. string: "Find jobs",
  472. attributes: [
  473. .font: NSFont.systemFont(ofSize: 14, weight: .semibold),
  474. .foregroundColor: Theme.proCTAText,
  475. .kern: 0.35
  476. ]
  477. )
  478. findJobsButton.isBordered = false
  479. findJobsButton.bezelStyle = .rounded
  480. findJobsButton.wantsLayer = true
  481. findJobsButton.layer?.backgroundColor = NSColor.clear.cgColor
  482. findJobsButton.focusRingType = .none
  483. findJobsButton.target = self
  484. findJobsButton.action = #selector(didSubmitSearch)
  485. findJobsButton.setContentHuggingPriority(.required, for: .horizontal)
  486. findJobsButton.setContentCompressionResistancePriority(.required, for: .horizontal)
  487. findJobsCTAHost.addSubview(findJobsCTAChrome)
  488. findJobsCTAHost.addSubview(findJobsButton)
  489. NSLayoutConstraint.activate([
  490. findJobsCTAChrome.leadingAnchor.constraint(equalTo: findJobsCTAHost.leadingAnchor),
  491. findJobsCTAChrome.trailingAnchor.constraint(equalTo: findJobsCTAHost.trailingAnchor),
  492. findJobsCTAChrome.topAnchor.constraint(equalTo: findJobsCTAHost.topAnchor),
  493. findJobsCTAChrome.bottomAnchor.constraint(equalTo: findJobsCTAHost.bottomAnchor),
  494. findJobsButton.leadingAnchor.constraint(equalTo: findJobsCTAHost.leadingAnchor, constant: 14),
  495. findJobsButton.trailingAnchor.constraint(equalTo: findJobsCTAHost.trailingAnchor, constant: -14),
  496. findJobsButton.topAnchor.constraint(equalTo: findJobsCTAHost.topAnchor),
  497. findJobsButton.bottomAnchor.constraint(equalTo: findJobsCTAHost.bottomAnchor)
  498. ])
  499. let keywordsStack = NSStackView(views: [jobSearchIcon, jobKeywordsField])
  500. keywordsStack.orientation = .horizontal
  501. keywordsStack.spacing = 10
  502. keywordsStack.alignment = .centerY
  503. keywordsStack.translatesAutoresizingMaskIntoConstraints = false
  504. keywordsStack.edgeInsets = NSEdgeInsets(top: 0, left: 18, bottom: 0, right: 10)
  505. keywordsStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
  506. let row = NSStackView(views: [keywordsStack, findJobsCTAHost])
  507. row.orientation = .horizontal
  508. row.spacing = 0
  509. row.alignment = .centerY
  510. row.distribution = .fill
  511. row.translatesAutoresizingMaskIntoConstraints = false
  512. row.edgeInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 7)
  513. searchCard.addSubview(row)
  514. NSLayoutConstraint.activate([
  515. searchCard.leadingAnchor.constraint(equalTo: searchBarShadowHost.leadingAnchor),
  516. searchCard.trailingAnchor.constraint(equalTo: searchBarShadowHost.trailingAnchor),
  517. searchCard.topAnchor.constraint(equalTo: searchBarShadowHost.topAnchor),
  518. searchCard.bottomAnchor.constraint(equalTo: searchBarShadowHost.bottomAnchor),
  519. searchBarShadowHost.heightAnchor.constraint(equalToConstant: barHeight),
  520. row.leadingAnchor.constraint(equalTo: searchCard.leadingAnchor),
  521. row.trailingAnchor.constraint(equalTo: searchCard.trailingAnchor),
  522. row.topAnchor.constraint(equalTo: searchCard.topAnchor),
  523. row.bottomAnchor.constraint(equalTo: searchCard.bottomAnchor),
  524. jobSearchIcon.widthAnchor.constraint(equalToConstant: 18),
  525. jobSearchIcon.heightAnchor.constraint(equalToConstant: 18),
  526. findJobsCTAHost.heightAnchor.constraint(equalToConstant: ctaHeight),
  527. findJobsCTAHost.widthAnchor.constraint(greaterThanOrEqualToConstant: 112)
  528. ])
  529. }
  530. private func updateFindJobsCTAShadowPath() {
  531. guard findJobsCTAHost.bounds.width > 0, findJobsCTAHost.bounds.height > 0 else { return }
  532. let r = findJobsCTAHost.bounds
  533. let radius = min(r.height / 2, r.width / 2)
  534. findJobsCTAHost.layer?.shadowPath = CGPath(
  535. roundedRect: r,
  536. cornerWidth: radius,
  537. cornerHeight: radius,
  538. transform: nil
  539. )
  540. }
  541. private func configureNonHomePlaceholder() {
  542. nonHomeHost.translatesAutoresizingMaskIntoConstraints = false
  543. nonHomeHost.wantsLayer = true
  544. nonHomeHost.layer?.backgroundColor = Theme.mainHostBackground.cgColor
  545. nonHomeHost.isHidden = true
  546. nonHomeTitleLabel.font = .systemFont(ofSize: 22, weight: .bold)
  547. nonHomeTitleLabel.textColor = Theme.primaryText
  548. nonHomeTitleLabel.alignment = .center
  549. nonHomeTitleLabel.maximumNumberOfLines = 1
  550. nonHomeSubtitleLabel.font = .systemFont(ofSize: 14, weight: .regular)
  551. nonHomeSubtitleLabel.textColor = Theme.secondaryText
  552. nonHomeSubtitleLabel.alignment = .center
  553. nonHomeSubtitleLabel.maximumNumberOfLines = 0
  554. nonHomeSubtitleLabel.stringValue = "This area is not available in the preview build. Use Home to search jobs."
  555. let stack = NSStackView(views: [nonHomeTitleLabel, nonHomeSubtitleLabel])
  556. stack.orientation = .vertical
  557. stack.spacing = 10
  558. stack.alignment = .centerX
  559. stack.translatesAutoresizingMaskIntoConstraints = false
  560. nonHomeHost.addSubview(stack)
  561. NSLayoutConstraint.activate([
  562. stack.centerXAnchor.constraint(equalTo: nonHomeHost.centerXAnchor),
  563. stack.centerYAnchor.constraint(equalTo: nonHomeHost.centerYAnchor),
  564. stack.leadingAnchor.constraint(greaterThanOrEqualTo: nonHomeHost.leadingAnchor, constant: 32),
  565. stack.trailingAnchor.constraint(lessThanOrEqualTo: nonHomeHost.trailingAnchor, constant: -32),
  566. nonHomeSubtitleLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 420)
  567. ])
  568. }
  569. private func isHomeSidebarIndex(_ index: Int) -> Bool {
  570. guard index >= 0, index < currentSidebarItems.count else { return false }
  571. return currentSidebarItems[index].title == "Home"
  572. }
  573. private func updateMainContentVisibility() {
  574. let home = isHomeSidebarIndex(selectedSidebarIndex)
  575. mainOverlay.isHidden = !home
  576. nonHomeHost.isHidden = home
  577. if !home, selectedSidebarIndex < currentSidebarItems.count {
  578. nonHomeTitleLabel.stringValue = currentSidebarItems[selectedSidebarIndex].title
  579. }
  580. }
  581. /// Removes result cards or the “no matches” message so a new search starts from a blank listing area.
  582. private func clearJobSearchResultsUI() {
  583. configureJobListings([], noResultsForQuery: nil)
  584. if let doc = jobListingsScrollView.documentView {
  585. doc.scroll(NSPoint(x: 0, y: 0))
  586. }
  587. }
  588. /// Restores the main job-search experience: cleared query and no listings until the user searches again.
  589. private func applyHomeState() {
  590. jobKeywordsField.stringValue = ""
  591. clearJobSearchResultsUI()
  592. window?.makeFirstResponder(nil)
  593. }
  594. private func updateSearchBarShadowPath() {
  595. guard searchBarShadowHost.bounds.width > 0, searchBarShadowHost.bounds.height > 0 else { return }
  596. let r = searchBarShadowHost.bounds
  597. let radius = min(r.height / 2, 27)
  598. searchBarShadowHost.layer?.shadowPath = CGPath(
  599. roundedRect: r,
  600. cornerWidth: radius,
  601. cornerHeight: radius,
  602. transform: nil
  603. )
  604. }
  605. @objc private func didSubmitSearch() {
  606. let query = jobKeywordsField.stringValue.trimmingCharacters(in: .whitespacesAndNewlines)
  607. let results = jobsMatchingSearch(query: query, in: catalogJobListings)
  608. let noResultsMessage: String? = (!results.isEmpty || query.isEmpty) ? nil : query
  609. configureJobListings(results, noResultsForQuery: noResultsMessage)
  610. window?.makeFirstResponder(nil)
  611. }
  612. /// Each whitespace-separated token must appear in the title or description (case-insensitive). Empty query returns the full catalog.
  613. private func jobsMatchingSearch(query: String, in jobs: [JobListing]) -> [JobListing] {
  614. let tokens = query
  615. .lowercased()
  616. .split(whereSeparator: { $0.isWhitespace })
  617. .map(String.init)
  618. .filter { !$0.isEmpty }
  619. guard !tokens.isEmpty else { return jobs }
  620. return jobs.filter { job in
  621. let haystack = "\(job.title) \(job.description)".lowercased()
  622. return tokens.allSatisfy { haystack.contains($0) }
  623. }
  624. }
  625. func controlTextDidBeginEditing(_ obj: Notification) {
  626. applySearchFieldInsertionPoint(obj.object)
  627. if (obj.object as? NSTextField) === jobKeywordsField {
  628. clearJobSearchResultsUI()
  629. }
  630. }
  631. func controlTextDidChange(_ obj: Notification) {
  632. applySearchFieldInsertionPoint(obj.object)
  633. }
  634. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  635. guard control === jobKeywordsField, commandSelector == #selector(NSResponder.insertNewline(_:)) else {
  636. return false
  637. }
  638. didSubmitSearch()
  639. return true
  640. }
  641. private func applySearchFieldInsertionPoint(_ object: Any?) {
  642. guard let field = object as? NSTextField,
  643. field === jobKeywordsField,
  644. let textView = field.window?.fieldEditor(true, for: field) as? NSTextView else { return }
  645. textView.insertionPointColor = Theme.primaryText
  646. }
  647. private func configureSidebar() {
  648. let items = currentSidebarItems
  649. sidebar.arrangedSubviews.forEach {
  650. sidebar.removeArrangedSubview($0)
  651. $0.removeFromSuperview()
  652. }
  653. let brand = NSTextField(labelWithString: "Indeed AI\nJob Finder")
  654. brand.font = .systemFont(ofSize: 18, weight: .bold)
  655. brand.textColor = Theme.brandBlue
  656. brand.alignment = .left
  657. sidebar.addArrangedSubview(brand)
  658. let titleToMenuSpacer = NSView()
  659. titleToMenuSpacer.translatesAutoresizingMaskIntoConstraints = false
  660. titleToMenuSpacer.heightAnchor.constraint(equalToConstant: 24).isActive = true
  661. sidebar.addArrangedSubview(titleToMenuSpacer)
  662. items.enumerated().forEach { index, item in
  663. let isSelected = index == selectedSidebarIndex
  664. let rowHost = SidebarNavRowView { [weak self] in
  665. self?.selectSidebarItem(at: index)
  666. }
  667. rowHost.translatesAutoresizingMaskIntoConstraints = false
  668. rowHost.wantsLayer = true
  669. rowHost.layer?.cornerRadius = 8
  670. if isSelected {
  671. rowHost.layer?.backgroundColor = Theme.selectionFill.cgColor
  672. }
  673. rowHost.setAccessibilityLabel(item.title)
  674. rowHost.setAccessibilityRole(.button)
  675. rowHost.setAccessibilitySelected(isSelected)
  676. let row = NSStackView()
  677. row.orientation = .horizontal
  678. row.spacing = 8
  679. row.alignment = .centerY
  680. row.translatesAutoresizingMaskIntoConstraints = false
  681. let icon = NSImageView()
  682. icon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .medium)
  683. icon.image = NSImage(systemSymbolName: item.systemImage, accessibilityDescription: item.title)
  684. icon.contentTintColor = isSelected ? Theme.brandBlue : Theme.secondaryText
  685. let text = NSTextField(labelWithString: item.title)
  686. text.font = .systemFont(ofSize: 14, weight: .medium)
  687. text.textColor = isSelected ? Theme.brandBlue : Theme.secondaryText
  688. text.refusesFirstResponder = true
  689. row.addArrangedSubview(icon)
  690. row.addArrangedSubview(text)
  691. if let badge = item.badge {
  692. let badgeField = NSTextField(labelWithString: badge)
  693. badgeField.font = .systemFont(ofSize: 11, weight: .semibold)
  694. badgeField.textColor = Theme.primaryText
  695. badgeField.wantsLayer = true
  696. badgeField.layer?.backgroundColor = Theme.toggleBackground.cgColor
  697. badgeField.layer?.cornerRadius = 8
  698. badgeField.alignment = .center
  699. badgeField.maximumNumberOfLines = 1
  700. badgeField.lineBreakMode = .byClipping
  701. badgeField.refusesFirstResponder = true
  702. badgeField.translatesAutoresizingMaskIntoConstraints = false
  703. badgeField.widthAnchor.constraint(equalToConstant: 42).isActive = true
  704. row.addArrangedSubview(NSView())
  705. row.addArrangedSubview(badgeField)
  706. }
  707. rowHost.addSubview(row)
  708. NSLayoutConstraint.activate([
  709. row.leadingAnchor.constraint(equalTo: rowHost.leadingAnchor, constant: 10),
  710. row.trailingAnchor.constraint(equalTo: rowHost.trailingAnchor, constant: -10),
  711. row.topAnchor.constraint(equalTo: rowHost.topAnchor, constant: 8),
  712. row.bottomAnchor.constraint(equalTo: rowHost.bottomAnchor, constant: -8)
  713. ])
  714. rowHost.setContentHuggingPriority(.defaultLow, for: .horizontal)
  715. sidebar.addArrangedSubview(rowHost)
  716. let sidebarHorizontalInset = sidebar.edgeInsets.left + sidebar.edgeInsets.right
  717. rowHost.widthAnchor.constraint(equalTo: sidebar.widthAnchor, constant: -sidebarHorizontalInset).isActive = true
  718. }
  719. let sidebarBottomSpacer = NSView()
  720. sidebarBottomSpacer.translatesAutoresizingMaskIntoConstraints = false
  721. sidebarBottomSpacer.setContentHuggingPriority(.defaultLow, for: .vertical)
  722. sidebarBottomSpacer.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
  723. sidebar.addArrangedSubview(sidebarBottomSpacer)
  724. let upgradeCard = NSView()
  725. upgradeCard.translatesAutoresizingMaskIntoConstraints = false
  726. upgradeCard.wantsLayer = true
  727. upgradeCard.layer?.backgroundColor = Theme.proCardFill.cgColor
  728. upgradeCard.layer?.cornerRadius = 14
  729. upgradeCard.layer?.borderWidth = 1
  730. upgradeCard.layer?.borderColor = Theme.proCardBorder.cgColor
  731. upgradeCard.layer?.masksToBounds = true
  732. let accentBar = NSView()
  733. accentBar.translatesAutoresizingMaskIntoConstraints = false
  734. accentBar.wantsLayer = true
  735. accentBar.layer?.backgroundColor = Theme.proAccent.cgColor
  736. let inner = NSStackView()
  737. inner.translatesAutoresizingMaskIntoConstraints = false
  738. inner.orientation = .vertical
  739. inner.spacing = 10
  740. inner.alignment = .centerX
  741. let proIcon = NSImageView()
  742. proIcon.translatesAutoresizingMaskIntoConstraints = false
  743. proIcon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
  744. proIcon.image = NSImage(systemSymbolName: "sparkles", accessibilityDescription: nil)
  745. proIcon.contentTintColor = Theme.proAccent
  746. let proEyebrow = NSTextField(labelWithString: "Premium")
  747. proEyebrow.font = .systemFont(ofSize: 11, weight: .heavy)
  748. proEyebrow.textColor = Theme.proAccent
  749. proEyebrow.alignment = .center
  750. let eyebrowRow = NSStackView(views: [proIcon, proEyebrow])
  751. eyebrowRow.orientation = .horizontal
  752. eyebrowRow.spacing = 6
  753. eyebrowRow.alignment = .centerY
  754. let headline = NSTextField(labelWithString: "Upgrade to Pro")
  755. headline.font = .systemFont(ofSize: 16, weight: .bold)
  756. headline.textColor = Theme.primaryText
  757. headline.alignment = .center
  758. let upgradeDescription = NSTextField(wrappingLabelWithString: "Unlimited AI matches, smart alerts, and interview prep—all in one place.")
  759. upgradeDescription.font = .systemFont(ofSize: 12, weight: .regular)
  760. upgradeDescription.textColor = Theme.secondaryText
  761. upgradeDescription.alignment = .center
  762. // Sidebar content width is 190pt (218 − edge insets); card must stay within that band.
  763. let cardWidth: CGFloat = 186
  764. let innerContentWidth = cardWidth - 28
  765. upgradeDescription.preferredMaxLayoutWidth = innerContentWidth
  766. let upgradeButton = NSButton(title: "Upgrade to Pro", target: self, action: #selector(didTapUpgradeToPro))
  767. upgradeButton.isBordered = false
  768. upgradeButton.bezelStyle = .rounded
  769. upgradeButton.font = .systemFont(ofSize: 13, weight: .bold)
  770. upgradeButton.contentTintColor = Theme.proCTAText
  771. upgradeButton.alignment = .center
  772. upgradeButton.wantsLayer = true
  773. upgradeButton.layer?.backgroundColor = Theme.proCTABackground.cgColor
  774. upgradeButton.layer?.cornerRadius = 20
  775. upgradeButton.translatesAutoresizingMaskIntoConstraints = false
  776. upgradeButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
  777. inner.addArrangedSubview(eyebrowRow)
  778. inner.addArrangedSubview(headline)
  779. inner.addArrangedSubview(upgradeDescription)
  780. inner.addArrangedSubview(upgradeButton)
  781. upgradeCard.addSubview(accentBar)
  782. upgradeCard.addSubview(inner)
  783. NSLayoutConstraint.activate([
  784. upgradeCard.widthAnchor.constraint(equalToConstant: cardWidth),
  785. accentBar.topAnchor.constraint(equalTo: upgradeCard.topAnchor),
  786. accentBar.leadingAnchor.constraint(equalTo: upgradeCard.leadingAnchor),
  787. accentBar.trailingAnchor.constraint(equalTo: upgradeCard.trailingAnchor),
  788. accentBar.heightAnchor.constraint(equalToConstant: 2),
  789. inner.leadingAnchor.constraint(equalTo: upgradeCard.leadingAnchor, constant: 14),
  790. inner.trailingAnchor.constraint(equalTo: upgradeCard.trailingAnchor, constant: -14),
  791. inner.topAnchor.constraint(equalTo: accentBar.bottomAnchor, constant: 12),
  792. inner.bottomAnchor.constraint(equalTo: upgradeCard.bottomAnchor, constant: -14),
  793. upgradeButton.widthAnchor.constraint(equalTo: inner.widthAnchor)
  794. ])
  795. sidebar.addArrangedSubview(upgradeCard)
  796. }
  797. @objc private func didTapUpgradeToPro() {
  798. guard let url = URL(string: "https://www.indeed.com") else { return }
  799. NSWorkspace.shared.open(url)
  800. }
  801. private func selectSidebarItem(at index: Int) {
  802. guard index >= 0, index < currentSidebarItems.count else { return }
  803. let selectingHome = isHomeSidebarIndex(index)
  804. if index == selectedSidebarIndex {
  805. if selectingHome {
  806. applyHomeState()
  807. }
  808. return
  809. }
  810. selectedSidebarIndex = index
  811. configureSidebar()
  812. updateMainContentVisibility()
  813. if selectingHome {
  814. applyHomeState()
  815. }
  816. }
  817. }
  818. /// `NSButton` that carries a `JobListing` for card actions (`representedObject` is unavailable on `NSButton` in this target).
  819. private final class JobPayloadButton: NSButton {
  820. var jobPayload: JobListing?
  821. }
  822. /// Document view for the job list `NSScrollView`; flipped coordinates keep short result sets aligned to the top of the clip (avoids a large empty band above the cards on macOS).
  823. private final class JobListingsDocumentView: NSView {
  824. override var isFlipped: Bool { true }
  825. }
  826. /// Captures clicks for the full sidebar pill so icon, label, and padding behave as one tab.
  827. private final class SidebarNavRowView: NSView {
  828. private let onSelect: () -> Void
  829. init(onSelect: @escaping () -> Void) {
  830. self.onSelect = onSelect
  831. super.init(frame: .zero)
  832. }
  833. @available(*, unavailable)
  834. required init?(coder: NSCoder) {
  835. fatalError("init(coder:) has not been implemented")
  836. }
  837. override func hitTest(_ point: NSPoint) -> NSView? {
  838. guard let superview else { return super.hitTest(point) }
  839. let local = convert(point, from: superview)
  840. return bounds.contains(local) ? self : nil
  841. }
  842. override func mouseDown(with event: NSEvent) {
  843. onSelect()
  844. }
  845. override func updateTrackingAreas() {
  846. super.updateTrackingAreas()
  847. trackingAreas.forEach { removeTrackingArea($0) }
  848. addTrackingArea(NSTrackingArea(
  849. rect: bounds,
  850. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  851. owner: self,
  852. userInfo: nil
  853. ))
  854. }
  855. override func mouseEntered(with event: NSEvent) {
  856. super.mouseEntered(with: event)
  857. NSCursor.pointingHand.push()
  858. }
  859. override func mouseExited(with event: NSEvent) {
  860. super.mouseExited(with: event)
  861. NSCursor.pop()
  862. }
  863. }