// // DashboardView.swift // App for Indeed // import Cocoa import QuartzCore final class DashboardView: NSView, NSTextFieldDelegate { /// Indeed.com-inspired neutrals and brand blue (white surfaces, `#2557a7` accent, `#2d2d2d` / `#767676` text, `#d4d2d0` borders). private enum Theme { static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1) static let pageBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1) static let chromeBackground = NSColor(srgbRed: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1) static let sidebarBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1) static let mainHostBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1) /// Subtitle on the welcome hero: readable blue-gray aligned with brand. static let welcomeSubtitleText = NSColor(srgbRed: 52 / 255, green: 92 / 255, blue: 142 / 255, alpha: 1) static let selectionFill = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.12) static let cardBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1) static let toggleBackground = NSColor(srgbRed: 232 / 255, green: 232 / 255, blue: 232 / 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 tertiaryText = 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) /// Job search bar outer stroke (charcoal). static let searchBarBorder = NSColor(srgbRed: 58 / 255, green: 58 / 255, blue: 58 / 255, alpha: 1) static let proCardFill = NSColor(srgbRed: 239 / 255, green: 244 / 255, blue: 252 / 255, alpha: 1) static let proCardBorder = NSColor(srgbRed: 212 / 255, green: 210 / 255, blue: 208 / 255, alpha: 1) static let proAccent = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1) static let proCTABackground = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1) static let proCTAText = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1) /// Slightly lighter blue for the top of the search-bar “Find jobs” pill (reads less flat than a solid fill). static let findJobsCTAHighlight = NSColor(srgbRed: 54 / 255, green: 110 / 255, blue: 198 / 255, alpha: 1) } private let contentStack = NSStackView() private let chromeContainer = NSView() private let sidebar = NSStackView() private let mainHost = NSView() private let mainOverlay = NSStackView() private let greetingLabel = NSTextField(labelWithString: "") private let subtitleLabel = NSTextField(labelWithString: "") private let searchBarShadowHost = NSView() private let searchCard = NSView() private let jobSearchIcon = NSImageView() private let jobKeywordsField = NSTextField() private let findJobsButton = NSButton() private let findJobsCTAHost = NSView() private let findJobsCTAChrome = NSView() private var findJobsCTAGradientLayer: CAGradientLayer? private let jobListingsScrollView = NSScrollView() /// Flipped so short result lists stay visually under the search bar instead of leaving a gap above the cards. private let jobListingsContainer = JobListingsDocumentView() private let jobListingsStack = NSStackView() private var currentSidebarItems: [SidebarItem] = [] private var selectedSidebarIndex: Int = 0 /// Full list from `DashboardData`; results are shown after the user runs a search. private var catalogJobListings: [JobListing] = [] override init(frame frameRect: NSRect) { super.init(frame: frameRect) setupLayout() } required init?(coder: NSCoder) { super.init(coder: coder) setupLayout() } override func layout() { super.layout() updateSearchBarShadowPath() findJobsCTAGradientLayer?.frame = findJobsCTAChrome.bounds updateFindJobsCTAShadowPath() updateJobListingDescriptionWidths() } func render(_ data: DashboardData) { greetingLabel.stringValue = "Welcome" subtitleLabel.stringValue = data.subtitle currentSidebarItems = data.sidebarItems if selectedSidebarIndex >= currentSidebarItems.count { selectedSidebarIndex = max(0, currentSidebarItems.count - 1) } configureSidebar() catalogJobListings = data.jobListings configureJobListings([], noResultsForQuery: nil) } private func setupLayout() { wantsLayer = true layer?.backgroundColor = Theme.pageBackground.cgColor contentStack.orientation = .horizontal contentStack.spacing = 20 contentStack.distribution = .fill contentStack.translatesAutoresizingMaskIntoConstraints = false contentStack.alignment = .height contentStack.edgeInsets = NSEdgeInsets(top: 24, left: 24, bottom: 24, right: 24) chromeContainer.translatesAutoresizingMaskIntoConstraints = false chromeContainer.wantsLayer = true chromeContainer.layer?.backgroundColor = Theme.chromeBackground.cgColor chromeContainer.layer?.cornerRadius = 0 addSubview(chromeContainer) chromeContainer.addSubview(contentStack) sidebar.orientation = .vertical sidebar.spacing = 10 sidebar.distribution = .fill sidebar.alignment = .leading sidebar.wantsLayer = true sidebar.layer?.backgroundColor = Theme.sidebarBackground.cgColor sidebar.layer?.cornerRadius = 16 sidebar.edgeInsets = NSEdgeInsets(top: 18, left: 14, bottom: 18, right: 14) sidebar.translatesAutoresizingMaskIntoConstraints = false mainHost.translatesAutoresizingMaskIntoConstraints = false mainHost.wantsLayer = true mainHost.layer?.backgroundColor = Theme.mainHostBackground.cgColor mainHost.layer?.cornerRadius = 16 mainHost.layer?.masksToBounds = true sidebar.setContentHuggingPriority(.required, for: .horizontal) mainHost.setContentHuggingPriority(.defaultLow, for: .horizontal) mainHost.addSubview(mainOverlay) mainOverlay.orientation = .vertical mainOverlay.spacing = 0 mainOverlay.alignment = .centerX mainOverlay.distribution = .fill mainOverlay.translatesAutoresizingMaskIntoConstraints = false mainOverlay.setContentHuggingPriority(.defaultLow, for: .vertical) greetingLabel.font = .systemFont(ofSize: 32, weight: .bold) greetingLabel.textColor = Theme.brandBlue greetingLabel.alignment = .center greetingLabel.maximumNumberOfLines = 1 subtitleLabel.font = .systemFont(ofSize: 15, weight: .regular) subtitleLabel.textColor = Theme.welcomeSubtitleText subtitleLabel.alignment = .center subtitleLabel.maximumNumberOfLines = 2 let topInset = NSView() topInset.translatesAutoresizingMaskIntoConstraints = false topInset.heightAnchor.constraint(equalToConstant: 32).isActive = true configureSearchBar() let titleBlock = NSStackView(views: [greetingLabel, subtitleLabel]) titleBlock.orientation = .vertical titleBlock.spacing = 10 titleBlock.alignment = .centerX let midSpacer = NSView() midSpacer.translatesAutoresizingMaskIntoConstraints = false midSpacer.heightAnchor.constraint(equalToConstant: 20).isActive = true let listingsTopSpacer = NSView() listingsTopSpacer.translatesAutoresizingMaskIntoConstraints = false listingsTopSpacer.heightAnchor.constraint(equalToConstant: 12).isActive = true jobListingsContainer.translatesAutoresizingMaskIntoConstraints = false jobListingsStack.orientation = .vertical jobListingsStack.spacing = 14 // `.leading` keeps cards left-anchored; explicit width constraints below stretch each card across the full row. jobListingsStack.alignment = .leading jobListingsStack.distribution = .fill jobListingsStack.translatesAutoresizingMaskIntoConstraints = false jobListingsStack.setContentHuggingPriority(.defaultHigh, for: .vertical) jobListingsStack.setHuggingPriority(.defaultLow, for: .horizontal) jobListingsContainer.addSubview(jobListingsStack) NSLayoutConstraint.activate([ jobListingsStack.leadingAnchor.constraint(equalTo: jobListingsContainer.leadingAnchor), jobListingsStack.trailingAnchor.constraint(equalTo: jobListingsContainer.trailingAnchor), jobListingsStack.topAnchor.constraint(equalTo: jobListingsContainer.topAnchor), jobListingsStack.bottomAnchor.constraint(equalTo: jobListingsContainer.bottomAnchor) ]) jobListingsScrollView.translatesAutoresizingMaskIntoConstraints = false jobListingsScrollView.hasVerticalScroller = true jobListingsScrollView.hasHorizontalScroller = false jobListingsScrollView.autohidesScrollers = true jobListingsScrollView.drawsBackground = false jobListingsScrollView.borderType = .noBorder jobListingsScrollView.documentView = jobListingsContainer jobListingsScrollView.setContentHuggingPriority(.defaultLow, for: .vertical) jobListingsScrollView.setContentCompressionResistancePriority(.defaultLow, for: .vertical) mainOverlay.addArrangedSubview(topInset) mainOverlay.addArrangedSubview(titleBlock) mainOverlay.addArrangedSubview(midSpacer) mainOverlay.addArrangedSubview(searchBarShadowHost) mainOverlay.addArrangedSubview(listingsTopSpacer) mainOverlay.addArrangedSubview(jobListingsScrollView) contentStack.addArrangedSubview(sidebar) contentStack.addArrangedSubview(mainHost) NSLayoutConstraint.activate([ chromeContainer.leadingAnchor.constraint(equalTo: leadingAnchor), chromeContainer.trailingAnchor.constraint(equalTo: trailingAnchor), chromeContainer.topAnchor.constraint(equalTo: topAnchor), chromeContainer.bottomAnchor.constraint(equalTo: bottomAnchor), contentStack.leadingAnchor.constraint(equalTo: chromeContainer.leadingAnchor), contentStack.trailingAnchor.constraint(equalTo: chromeContainer.trailingAnchor), contentStack.topAnchor.constraint(equalTo: chromeContainer.topAnchor), contentStack.bottomAnchor.constraint(equalTo: chromeContainer.bottomAnchor), sidebar.widthAnchor.constraint(equalToConstant: 218), mainHost.widthAnchor.constraint(greaterThanOrEqualToConstant: 720), mainOverlay.leadingAnchor.constraint(equalTo: mainHost.leadingAnchor), mainOverlay.trailingAnchor.constraint(equalTo: mainHost.trailingAnchor), mainOverlay.topAnchor.constraint(equalTo: mainHost.topAnchor), mainOverlay.bottomAnchor.constraint(equalTo: mainHost.bottomAnchor, constant: -24), searchBarShadowHost.widthAnchor.constraint(equalTo: mainOverlay.widthAnchor, multiplier: 0.92), jobListingsScrollView.widthAnchor.constraint(equalTo: mainOverlay.widthAnchor, multiplier: 0.92), jobListingsContainer.topAnchor.constraint(equalTo: jobListingsScrollView.contentView.topAnchor), jobListingsContainer.leadingAnchor.constraint(equalTo: jobListingsScrollView.contentView.leadingAnchor), jobListingsContainer.widthAnchor.constraint(equalTo: jobListingsScrollView.contentView.widthAnchor), greetingLabel.leadingAnchor.constraint(equalTo: mainOverlay.leadingAnchor, constant: 24), greetingLabel.trailingAnchor.constraint(equalTo: mainOverlay.trailingAnchor, constant: -24), subtitleLabel.leadingAnchor.constraint(equalTo: greetingLabel.leadingAnchor), subtitleLabel.trailingAnchor.constraint(equalTo: greetingLabel.trailingAnchor) ]) } private func updateJobListingDescriptionWidths() { let containerWidth = jobListingsContainer.bounds.width guard containerWidth > 1 else { return } let innerWidth = containerWidth - 32 var didChange = false for card in jobListingsStack.arrangedSubviews { guard let desc = card.viewWithTag(502) as? NSTextField else { continue } if abs(desc.preferredMaxLayoutWidth - innerWidth) > 0.5 { desc.preferredMaxLayoutWidth = innerWidth desc.invalidateIntrinsicContentSize() didChange = true } } if didChange { // Wrapping width changed, so card heights need to recompute against the new intrinsic sizes. jobListingsStack.needsLayout = true } } private func configureJobListings(_ jobs: [JobListing], noResultsForQuery: String?) { jobListingsStack.arrangedSubviews.forEach { jobListingsStack.removeArrangedSubview($0) $0.removeFromSuperview() } if jobs.isEmpty, let query = noResultsForQuery, !query.isEmpty { let empty = NSTextField(wrappingLabelWithString: "No jobs match “\(query)”. Try different keywords or browse the full list with an empty search.") empty.font = .systemFont(ofSize: 14, weight: .regular) empty.textColor = Theme.secondaryText empty.alignment = .center empty.maximumNumberOfLines = 0 empty.translatesAutoresizingMaskIntoConstraints = false jobListingsStack.addArrangedSubview(empty) empty.widthAnchor.constraint(equalTo: jobListingsStack.widthAnchor).isActive = true return } for job in jobs { let card = makeJobListingCard(job) jobListingsStack.addArrangedSubview(card) // Force every card to span the full row instead of hugging its intrinsic content width. card.widthAnchor.constraint(equalTo: jobListingsStack.widthAnchor).isActive = true } } private func makeJobListingCard(_ job: JobListing) -> NSView { let card = NSView() card.translatesAutoresizingMaskIntoConstraints = false card.wantsLayer = true card.layer?.backgroundColor = Theme.cardBackground.cgColor card.layer?.cornerRadius = 12 card.layer?.borderWidth = 1 card.layer?.borderColor = Theme.border.cgColor card.layer?.masksToBounds = true let titleField = NSTextField(labelWithString: job.title) titleField.font = .systemFont(ofSize: 16, weight: .semibold) titleField.textColor = Theme.primaryText titleField.maximumNumberOfLines = 2 titleField.lineBreakMode = .byWordWrapping titleField.translatesAutoresizingMaskIntoConstraints = false let descriptionField = NSTextField(wrappingLabelWithString: job.description) descriptionField.font = .systemFont(ofSize: 13, weight: .regular) descriptionField.textColor = Theme.secondaryText descriptionField.maximumNumberOfLines = 0 descriptionField.tag = 502 descriptionField.translatesAutoresizingMaskIntoConstraints = false let inner = NSStackView(views: [titleField, descriptionField]) inner.orientation = .vertical inner.spacing = 6 inner.alignment = .leading inner.translatesAutoresizingMaskIntoConstraints = false card.addSubview(inner) NSLayoutConstraint.activate([ inner.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: 16), inner.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -16), inner.topAnchor.constraint(equalTo: card.topAnchor, constant: 14), inner.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -14), titleField.leadingAnchor.constraint(equalTo: inner.leadingAnchor), titleField.trailingAnchor.constraint(equalTo: inner.trailingAnchor), descriptionField.leadingAnchor.constraint(equalTo: inner.leadingAnchor), descriptionField.trailingAnchor.constraint(equalTo: inner.trailingAnchor) ]) return card } private func configureSearchBar() { let pillCorner: CGFloat = 27 let barHeight: CGFloat = 54 searchBarShadowHost.translatesAutoresizingMaskIntoConstraints = false searchBarShadowHost.wantsLayer = true searchBarShadowHost.layer?.masksToBounds = false searchBarShadowHost.layer?.shadowColor = NSColor.black.withAlphaComponent(0.18).cgColor searchBarShadowHost.layer?.shadowOffset = CGSize(width: 0, height: 2) searchBarShadowHost.layer?.shadowRadius = 10 searchBarShadowHost.layer?.shadowOpacity = 1 searchBarShadowHost.setContentHuggingPriority(.defaultHigh, for: .vertical) searchCard.translatesAutoresizingMaskIntoConstraints = false searchCard.wantsLayer = true searchCard.layer?.backgroundColor = Theme.cardBackground.cgColor searchCard.layer?.cornerRadius = pillCorner searchCard.layer?.borderWidth = 1 searchCard.layer?.borderColor = Theme.searchBarBorder.cgColor searchCard.layer?.masksToBounds = true searchBarShadowHost.addSubview(searchCard) func configureField(_ field: NSTextField, placeholder: String) { field.translatesAutoresizingMaskIntoConstraints = false field.isBordered = false field.drawsBackground = false field.focusRingType = .none field.font = .systemFont(ofSize: 14, weight: .regular) field.textColor = Theme.primaryText field.delegate = self field.placeholderAttributedString = NSAttributedString( string: placeholder, attributes: [ .foregroundColor: Theme.secondaryText, .font: NSFont.systemFont(ofSize: 14, weight: .regular) ] ) field.cell?.usesSingleLineMode = true field.cell?.wraps = false field.cell?.isScrollable = true field.target = self field.action = #selector(didSubmitSearch) } jobSearchIcon.translatesAutoresizingMaskIntoConstraints = false jobSearchIcon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 15, weight: .medium) jobSearchIcon.image = NSImage(systemSymbolName: "magnifyingglass", accessibilityDescription: "Job search") jobSearchIcon.contentTintColor = Theme.primaryText configureField(jobKeywordsField, placeholder: "Job title, keywords, or company") let ctaHeight: CGFloat = 42 let ctaCorner = ctaHeight / 2 findJobsCTAHost.translatesAutoresizingMaskIntoConstraints = false findJobsCTAHost.wantsLayer = true findJobsCTAHost.layer?.masksToBounds = false findJobsCTAHost.layer?.shadowColor = NSColor.black.cgColor findJobsCTAHost.layer?.shadowOpacity = 0.16 findJobsCTAHost.layer?.shadowOffset = CGSize(width: 0, height: 2) findJobsCTAHost.layer?.shadowRadius = 6 findJobsCTAChrome.translatesAutoresizingMaskIntoConstraints = false findJobsCTAChrome.wantsLayer = true findJobsCTAChrome.layer?.masksToBounds = true findJobsCTAChrome.layer?.cornerRadius = ctaCorner if #available(macOS 11.0, *) { findJobsCTAChrome.layer?.cornerCurve = .continuous } let gradient = CAGradientLayer() gradient.colors = [Theme.findJobsCTAHighlight.cgColor, Theme.brandBlue.cgColor] gradient.startPoint = CGPoint(x: 0.5, y: 1) gradient.endPoint = CGPoint(x: 0.5, y: 0) findJobsCTAChrome.layer?.addSublayer(gradient) findJobsCTAGradientLayer = gradient findJobsButton.translatesAutoresizingMaskIntoConstraints = false findJobsButton.title = "" findJobsButton.attributedTitle = NSAttributedString( string: "Find jobs", attributes: [ .font: NSFont.systemFont(ofSize: 14, weight: .semibold), .foregroundColor: Theme.proCTAText, .kern: 0.35 ] ) findJobsButton.isBordered = false findJobsButton.bezelStyle = .rounded findJobsButton.wantsLayer = true findJobsButton.layer?.backgroundColor = NSColor.clear.cgColor findJobsButton.focusRingType = .none findJobsButton.target = self findJobsButton.action = #selector(didSubmitSearch) findJobsButton.setContentHuggingPriority(.required, for: .horizontal) findJobsButton.setContentCompressionResistancePriority(.required, for: .horizontal) findJobsCTAHost.addSubview(findJobsCTAChrome) findJobsCTAHost.addSubview(findJobsButton) NSLayoutConstraint.activate([ findJobsCTAChrome.leadingAnchor.constraint(equalTo: findJobsCTAHost.leadingAnchor), findJobsCTAChrome.trailingAnchor.constraint(equalTo: findJobsCTAHost.trailingAnchor), findJobsCTAChrome.topAnchor.constraint(equalTo: findJobsCTAHost.topAnchor), findJobsCTAChrome.bottomAnchor.constraint(equalTo: findJobsCTAHost.bottomAnchor), findJobsButton.leadingAnchor.constraint(equalTo: findJobsCTAHost.leadingAnchor, constant: 14), findJobsButton.trailingAnchor.constraint(equalTo: findJobsCTAHost.trailingAnchor, constant: -14), findJobsButton.topAnchor.constraint(equalTo: findJobsCTAHost.topAnchor), findJobsButton.bottomAnchor.constraint(equalTo: findJobsCTAHost.bottomAnchor) ]) let keywordsStack = NSStackView(views: [jobSearchIcon, jobKeywordsField]) keywordsStack.orientation = .horizontal keywordsStack.spacing = 10 keywordsStack.alignment = .centerY keywordsStack.translatesAutoresizingMaskIntoConstraints = false keywordsStack.edgeInsets = NSEdgeInsets(top: 0, left: 18, bottom: 0, right: 10) keywordsStack.setContentHuggingPriority(.defaultLow, for: .horizontal) let row = NSStackView(views: [keywordsStack, findJobsCTAHost]) row.orientation = .horizontal row.spacing = 0 row.alignment = .centerY row.distribution = .fill row.translatesAutoresizingMaskIntoConstraints = false row.edgeInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 7) searchCard.addSubview(row) NSLayoutConstraint.activate([ searchCard.leadingAnchor.constraint(equalTo: searchBarShadowHost.leadingAnchor), searchCard.trailingAnchor.constraint(equalTo: searchBarShadowHost.trailingAnchor), searchCard.topAnchor.constraint(equalTo: searchBarShadowHost.topAnchor), searchCard.bottomAnchor.constraint(equalTo: searchBarShadowHost.bottomAnchor), searchBarShadowHost.heightAnchor.constraint(equalToConstant: barHeight), row.leadingAnchor.constraint(equalTo: searchCard.leadingAnchor), row.trailingAnchor.constraint(equalTo: searchCard.trailingAnchor), row.topAnchor.constraint(equalTo: searchCard.topAnchor), row.bottomAnchor.constraint(equalTo: searchCard.bottomAnchor), jobSearchIcon.widthAnchor.constraint(equalToConstant: 18), jobSearchIcon.heightAnchor.constraint(equalToConstant: 18), findJobsCTAHost.heightAnchor.constraint(equalToConstant: ctaHeight), findJobsCTAHost.widthAnchor.constraint(greaterThanOrEqualToConstant: 112) ]) } private func updateFindJobsCTAShadowPath() { guard findJobsCTAHost.bounds.width > 0, findJobsCTAHost.bounds.height > 0 else { return } let r = findJobsCTAHost.bounds let radius = min(r.height / 2, r.width / 2) findJobsCTAHost.layer?.shadowPath = CGPath( roundedRect: r, cornerWidth: radius, cornerHeight: radius, transform: nil ) } private func updateSearchBarShadowPath() { guard searchBarShadowHost.bounds.width > 0, searchBarShadowHost.bounds.height > 0 else { return } let r = searchBarShadowHost.bounds let radius = min(r.height / 2, 27) searchBarShadowHost.layer?.shadowPath = CGPath( roundedRect: r, cornerWidth: radius, cornerHeight: radius, transform: nil ) } @objc private func didSubmitSearch() { let query = jobKeywordsField.stringValue.trimmingCharacters(in: .whitespacesAndNewlines) let results = jobsMatchingSearch(query: query, in: catalogJobListings) let noResultsMessage: String? = (!results.isEmpty || query.isEmpty) ? nil : query configureJobListings(results, noResultsForQuery: noResultsMessage) window?.makeFirstResponder(nil) } /// Each whitespace-separated token must appear in the title or description (case-insensitive). Empty query returns the full catalog. private func jobsMatchingSearch(query: String, in jobs: [JobListing]) -> [JobListing] { let tokens = query .lowercased() .split(whereSeparator: { $0.isWhitespace }) .map(String.init) .filter { !$0.isEmpty } guard !tokens.isEmpty else { return jobs } return jobs.filter { job in let haystack = "\(job.title) \(job.description)".lowercased() return tokens.allSatisfy { haystack.contains($0) } } } func controlTextDidBeginEditing(_ obj: Notification) { applySearchFieldInsertionPoint(obj.object) } func controlTextDidChange(_ obj: Notification) { applySearchFieldInsertionPoint(obj.object) } func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { guard control === jobKeywordsField, commandSelector == #selector(NSResponder.insertNewline(_:)) else { return false } didSubmitSearch() return true } private func applySearchFieldInsertionPoint(_ object: Any?) { guard let field = object as? NSTextField, field === jobKeywordsField, let textView = field.window?.fieldEditor(true, for: field) as? NSTextView else { return } textView.insertionPointColor = Theme.primaryText } private func configureSidebar() { let items = currentSidebarItems sidebar.arrangedSubviews.forEach { sidebar.removeArrangedSubview($0) $0.removeFromSuperview() } let brand = NSTextField(labelWithString: "Indeed AI\nJob Finder") brand.font = .systemFont(ofSize: 18, weight: .bold) brand.textColor = Theme.brandBlue brand.alignment = .left sidebar.addArrangedSubview(brand) let titleToMenuSpacer = NSView() titleToMenuSpacer.translatesAutoresizingMaskIntoConstraints = false titleToMenuSpacer.heightAnchor.constraint(equalToConstant: 24).isActive = true sidebar.addArrangedSubview(titleToMenuSpacer) items.enumerated().forEach { index, item in let isSelected = index == selectedSidebarIndex let rowHost = SidebarNavRowView { [weak self] in self?.selectSidebarItem(at: index) } rowHost.translatesAutoresizingMaskIntoConstraints = false rowHost.wantsLayer = true rowHost.layer?.cornerRadius = 8 if isSelected { rowHost.layer?.backgroundColor = Theme.selectionFill.cgColor } rowHost.setAccessibilityLabel(item.title) rowHost.setAccessibilityRole(.button) rowHost.setAccessibilitySelected(isSelected) let row = NSStackView() row.orientation = .horizontal row.spacing = 8 row.alignment = .centerY row.translatesAutoresizingMaskIntoConstraints = false let icon = NSImageView() icon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .medium) icon.image = NSImage(systemSymbolName: item.systemImage, accessibilityDescription: item.title) icon.contentTintColor = isSelected ? Theme.brandBlue : Theme.secondaryText let text = NSTextField(labelWithString: item.title) text.font = .systemFont(ofSize: 14, weight: .medium) text.textColor = isSelected ? Theme.brandBlue : Theme.secondaryText text.refusesFirstResponder = true row.addArrangedSubview(icon) row.addArrangedSubview(text) if let badge = item.badge { let badgeField = NSTextField(labelWithString: badge) badgeField.font = .systemFont(ofSize: 11, weight: .semibold) badgeField.textColor = Theme.primaryText badgeField.wantsLayer = true badgeField.layer?.backgroundColor = Theme.toggleBackground.cgColor badgeField.layer?.cornerRadius = 8 badgeField.alignment = .center badgeField.maximumNumberOfLines = 1 badgeField.lineBreakMode = .byClipping badgeField.refusesFirstResponder = true badgeField.translatesAutoresizingMaskIntoConstraints = false badgeField.widthAnchor.constraint(equalToConstant: 42).isActive = true row.addArrangedSubview(NSView()) row.addArrangedSubview(badgeField) } rowHost.addSubview(row) NSLayoutConstraint.activate([ row.leadingAnchor.constraint(equalTo: rowHost.leadingAnchor, constant: 10), row.trailingAnchor.constraint(equalTo: rowHost.trailingAnchor, constant: -10), row.topAnchor.constraint(equalTo: rowHost.topAnchor, constant: 8), row.bottomAnchor.constraint(equalTo: rowHost.bottomAnchor, constant: -8) ]) rowHost.setContentHuggingPriority(.defaultLow, for: .horizontal) sidebar.addArrangedSubview(rowHost) let sidebarHorizontalInset = sidebar.edgeInsets.left + sidebar.edgeInsets.right rowHost.widthAnchor.constraint(equalTo: sidebar.widthAnchor, constant: -sidebarHorizontalInset).isActive = true } let sidebarBottomSpacer = NSView() sidebarBottomSpacer.translatesAutoresizingMaskIntoConstraints = false sidebarBottomSpacer.setContentHuggingPriority(.defaultLow, for: .vertical) sidebarBottomSpacer.setContentCompressionResistancePriority(.defaultLow, for: .vertical) sidebar.addArrangedSubview(sidebarBottomSpacer) let upgradeCard = NSView() upgradeCard.translatesAutoresizingMaskIntoConstraints = false upgradeCard.wantsLayer = true upgradeCard.layer?.backgroundColor = Theme.proCardFill.cgColor upgradeCard.layer?.cornerRadius = 14 upgradeCard.layer?.borderWidth = 1 upgradeCard.layer?.borderColor = Theme.proCardBorder.cgColor upgradeCard.layer?.masksToBounds = true let accentBar = NSView() accentBar.translatesAutoresizingMaskIntoConstraints = false accentBar.wantsLayer = true accentBar.layer?.backgroundColor = Theme.proAccent.cgColor let inner = NSStackView() inner.translatesAutoresizingMaskIntoConstraints = false inner.orientation = .vertical inner.spacing = 10 inner.alignment = .centerX let proIcon = NSImageView() proIcon.translatesAutoresizingMaskIntoConstraints = false proIcon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold) proIcon.image = NSImage(systemSymbolName: "sparkles", accessibilityDescription: nil) proIcon.contentTintColor = Theme.proAccent let proEyebrow = NSTextField(labelWithString: "Premium") proEyebrow.font = .systemFont(ofSize: 11, weight: .heavy) proEyebrow.textColor = Theme.proAccent proEyebrow.alignment = .center let eyebrowRow = NSStackView(views: [proIcon, proEyebrow]) eyebrowRow.orientation = .horizontal eyebrowRow.spacing = 6 eyebrowRow.alignment = .centerY let headline = NSTextField(labelWithString: "Upgrade to Pro") headline.font = .systemFont(ofSize: 16, weight: .bold) headline.textColor = Theme.primaryText headline.alignment = .center let upgradeDescription = NSTextField(wrappingLabelWithString: "Unlimited AI matches, smart alerts, and interview prep—all in one place.") upgradeDescription.font = .systemFont(ofSize: 12, weight: .regular) upgradeDescription.textColor = Theme.secondaryText upgradeDescription.alignment = .center // Sidebar content width is 190pt (218 − edge insets); card must stay within that band. let cardWidth: CGFloat = 186 let innerContentWidth = cardWidth - 28 upgradeDescription.preferredMaxLayoutWidth = innerContentWidth let upgradeButton = NSButton(title: "Upgrade to Pro", target: self, action: #selector(didTapUpgradeToPro)) upgradeButton.isBordered = false upgradeButton.bezelStyle = .rounded upgradeButton.font = .systemFont(ofSize: 13, weight: .bold) upgradeButton.contentTintColor = Theme.proCTAText upgradeButton.alignment = .center upgradeButton.wantsLayer = true upgradeButton.layer?.backgroundColor = Theme.proCTABackground.cgColor upgradeButton.layer?.cornerRadius = 20 upgradeButton.translatesAutoresizingMaskIntoConstraints = false upgradeButton.heightAnchor.constraint(equalToConstant: 40).isActive = true inner.addArrangedSubview(eyebrowRow) inner.addArrangedSubview(headline) inner.addArrangedSubview(upgradeDescription) inner.addArrangedSubview(upgradeButton) upgradeCard.addSubview(accentBar) upgradeCard.addSubview(inner) NSLayoutConstraint.activate([ upgradeCard.widthAnchor.constraint(equalToConstant: cardWidth), accentBar.topAnchor.constraint(equalTo: upgradeCard.topAnchor), accentBar.leadingAnchor.constraint(equalTo: upgradeCard.leadingAnchor), accentBar.trailingAnchor.constraint(equalTo: upgradeCard.trailingAnchor), accentBar.heightAnchor.constraint(equalToConstant: 2), inner.leadingAnchor.constraint(equalTo: upgradeCard.leadingAnchor, constant: 14), inner.trailingAnchor.constraint(equalTo: upgradeCard.trailingAnchor, constant: -14), inner.topAnchor.constraint(equalTo: accentBar.bottomAnchor, constant: 12), inner.bottomAnchor.constraint(equalTo: upgradeCard.bottomAnchor, constant: -14), upgradeButton.widthAnchor.constraint(equalTo: inner.widthAnchor) ]) sidebar.addArrangedSubview(upgradeCard) } @objc private func didTapUpgradeToPro() { guard let url = URL(string: "https://www.indeed.com") else { return } NSWorkspace.shared.open(url) } private func selectSidebarItem(at index: Int) { guard index >= 0, index < currentSidebarItems.count, index != selectedSidebarIndex else { return } selectedSidebarIndex = index configureSidebar() } } /// 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). private final class JobListingsDocumentView: NSView { override var isFlipped: Bool { true } } /// Captures clicks for the full sidebar pill so icon, label, and padding behave as one tab. private final class SidebarNavRowView: NSView { private let onSelect: () -> Void init(onSelect: @escaping () -> Void) { self.onSelect = onSelect super.init(frame: .zero) } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func hitTest(_ point: NSPoint) -> NSView? { guard let superview else { return super.hitTest(point) } let local = convert(point, from: superview) return bounds.contains(local) ? self : nil } override func mouseDown(with event: NSEvent) { onSelect() } override func updateTrackingAreas() { super.updateTrackingAreas() trackingAreas.forEach { removeTrackingArea($0) } addTrackingArea(NSTrackingArea( rect: bounds, options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect], owner: self, userInfo: nil )) } override func mouseEntered(with event: NSEvent) { super.mouseEntered(with: event) NSCursor.pointingHand.push() } override func mouseExited(with event: NSEvent) { super.mouseExited(with: event) NSCursor.pop() } }