| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397 |
- //
- // DashboardView.swift
- // App for Indeed
- //
- import Cocoa
- import QuartzCore
- private enum JobListingCardContext {
- case homeSearchResults
- case savedJobsPage
- }
- 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)
- /// Search bar border on hover (brand-tinted, matches focus affordance elsewhere).
- static let searchBarBorderHover = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.45)
- 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)
- /// Hover states: darker brand blue, deeper gradient top, stronger tints, and subtle neutral fills used across CTAs, toggles, and the sidebar.
- static let brandBlueHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
- static let findJobsCTAHighlightHover = NSColor(srgbRed: 44 / 255, green: 94 / 255, blue: 178 / 255, alpha: 1)
- static let selectionFillHover = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.2)
- static let neutralHoverFill = NSColor(srgbRed: 240 / 255, green: 240 / 255, blue: 240 / 255, alpha: 1)
- static let sidebarRowHoverFill = NSColor(srgbRed: 0, green: 0, blue: 0, alpha: 0.04)
- }
- /// Multiline `NSTextField` often ignores `alignment` for wrapped runs; explicit paragraph alignment matches the title.
- private static func jobListingDescriptionAttributedString(_ plain: String) -> NSAttributedString {
- let paragraph = NSMutableParagraphStyle()
- paragraph.alignment = .left
- paragraph.lineBreakMode = .byWordWrapping
- paragraph.baseWritingDirection = .leftToRight
- let font = NSFont.systemFont(ofSize: 13, weight: .regular)
- return NSAttributedString(string: plain, attributes: [
- .font: font,
- .foregroundColor: Theme.secondaryText,
- .paragraphStyle: paragraph
- ])
- }
- 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 = HoverableView()
- private let jobSearchIcon = NSImageView()
- private let jobKeywordsField = NSTextField()
- private let findJobsButton = HoverableButton()
- private let findJobsCTAHost = NSView()
- private let findJobsCTAChrome = HoverableView()
- 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()
- /// Shown when a sidebar item other than Home is selected.
- private let nonHomeHost = NSView()
- private let nonHomeGenericContainer = NSView()
- private let nonHomeTitleLabel = NSTextField(labelWithString: "")
- private let nonHomeSubtitleLabel = NSTextField(wrappingLabelWithString: "")
- private let savedJobsPageContainer = NSView()
- private let savedJobsPageTitleLabel = NSTextField(labelWithString: "Saved Jobs")
- private let savedJobsPageSubtitleLabel = NSTextField(wrappingLabelWithString: "")
- private let savedJobsScrollView = NSScrollView()
- private let savedJobsDocumentView = JobListingsDocumentView()
- private let savedJobsStack = 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] = []
- /// Last successful search result set (used when removing a card with the dismiss control).
- private var lastSearchResults: [JobListing] = []
- private var lastNoResultsQuery: String?
- /// Most recently saved jobs appear first; persisted across launches.
- private var savedJobOrder: [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
- savedJobOrder = Self.normalizedSavedJobs(SavedJobsStore.load())
- configureJobListings([], noResultsForQuery: nil)
- updateMainContentVisibility()
- }
- private func setupLayout() {
- wantsLayer = true
- layer?.backgroundColor = Theme.pageBackground.cgColor
- contentStack.orientation = .horizontal
- contentStack.spacing = 10
- contentStack.distribution = .fill
- contentStack.translatesAutoresizingMaskIntoConstraints = false
- contentStack.alignment = .height
- // Tighter chrome insets so panels sit closer to the window edges (especially leading / top under the title bar).
- contentStack.edgeInsets = NSEdgeInsets(top: 10, left: 12, bottom: 20, right: 20)
- 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: 16, left: 12, bottom: 16, right: 12)
- 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)
- configureNonHomePlaceholder()
- mainHost.addSubview(nonHomeHost)
- 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: 18).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: safeAreaLayoutGuide.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),
- nonHomeHost.leadingAnchor.constraint(equalTo: mainHost.leadingAnchor),
- nonHomeHost.trailingAnchor.constraint(equalTo: mainHost.trailingAnchor),
- nonHomeHost.topAnchor.constraint(equalTo: mainHost.topAnchor),
- nonHomeHost.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: 16),
- greetingLabel.trailingAnchor.constraint(equalTo: mainOverlay.trailingAnchor, constant: -16),
- subtitleLabel.leadingAnchor.constraint(equalTo: greetingLabel.leadingAnchor),
- subtitleLabel.trailingAnchor.constraint(equalTo: greetingLabel.trailingAnchor)
- ])
- }
- private func updateJobListingDescriptionWidths() {
- updateDescriptionColumnWidths(in: jobListingsStack, containerWidth: jobListingsContainer.bounds.width)
- updateDescriptionColumnWidths(in: savedJobsStack, containerWidth: savedJobsDocumentView.bounds.width)
- }
- private func updateDescriptionColumnWidths(in stack: NSStackView, containerWidth: CGFloat) {
- guard containerWidth > 1 else { return }
- // Matches `contentColumn` insets on the card (16 leading + 16 trailing). The description spans the full row below the buttons, so never subtract a “button strip” here — a too-narrow `preferredMaxLayoutWidth` inside a wider field makes wrapped `NSTextField` text lay out like a trailing-aligned band after resizes.
- let contentHorizontalInset: CGFloat = 32
- var didChange = false
- for card in stack.arrangedSubviews {
- guard let desc = card.viewWithTag(502) as? NSTextField else { continue }
- let cardWidth = card.bounds.width > 1 ? card.bounds.width : containerWidth
- let fallbackColumn = max(1, cardWidth - contentHorizontalInset)
- let columnWidth: CGFloat
- if desc.bounds.width > 1 {
- columnWidth = desc.bounds.width
- } else if let column = desc.superview, column.bounds.width > 1 {
- columnWidth = column.bounds.width
- } else {
- columnWidth = fallbackColumn
- }
- if abs(desc.preferredMaxLayoutWidth - columnWidth) > 0.5 {
- desc.preferredMaxLayoutWidth = columnWidth
- desc.invalidateIntrinsicContentSize()
- didChange = true
- }
- }
- if didChange {
- stack.needsLayout = true
- }
- }
- private func configureJobListings(_ jobs: [JobListing], noResultsForQuery: String?, updateLastResults: Bool = true) {
- if updateLastResults {
- lastSearchResults = jobs
- lastNoResultsQuery = noResultsForQuery
- }
- 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, context: .homeSearchResults)
- 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 static func normalizedSavedJobs(_ jobs: [JobListing]) -> [JobListing] {
- var seen = Set<JobListing>()
- var out: [JobListing] = []
- for job in jobs where seen.insert(job).inserted {
- out.append(job)
- }
- return out
- }
- private func isJobSaved(_ job: JobListing) -> Bool {
- savedJobOrder.contains(job)
- }
- private func persistSavedJobs() {
- SavedJobsStore.save(savedJobOrder)
- }
- private func applySavedState(_ saved: Bool, for job: JobListing) {
- if saved {
- savedJobOrder.removeAll { $0 == job }
- savedJobOrder.insert(job, at: 0)
- } else {
- savedJobOrder.removeAll { $0 == job }
- }
- persistSavedJobs()
- }
- private func makeJobListingCard(_ job: JobListing, context: JobListingCardContext) -> 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.alignment = .left
- titleField.translatesAutoresizingMaskIntoConstraints = false
- let descriptionField = NSTextField(wrappingLabelWithString: job.description)
- descriptionField.font = .systemFont(ofSize: 13, weight: .regular)
- descriptionField.textColor = Theme.secondaryText
- descriptionField.maximumNumberOfLines = 0
- descriptionField.alignment = .left
- descriptionField.lineBreakMode = .byWordWrapping
- descriptionField.baseWritingDirection = .leftToRight
- descriptionField.attributedStringValue = Self.jobListingDescriptionAttributedString(job.description)
- if let cell = descriptionField.cell as? NSTextFieldCell {
- cell.alignment = .left
- cell.wraps = true
- }
- descriptionField.setContentHuggingPriority(.defaultLow, for: .horizontal)
- descriptionField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
- descriptionField.tag = 502
- descriptionField.translatesAutoresizingMaskIntoConstraints = false
- let applyButton = JobPayloadButton(title: "Apply", target: self, action: #selector(didTapJobApply(_:)))
- applyButton.jobPayload = job
- applyButton.cardContext = context
- applyButton.isBordered = false
- applyButton.bezelStyle = .rounded
- applyButton.font = .systemFont(ofSize: 13, weight: .semibold)
- applyButton.wantsLayer = true
- applyButton.layer?.cornerRadius = 6
- applyButton.layer?.backgroundColor = Theme.brandBlue.cgColor
- applyButton.contentTintColor = Theme.proCTAText
- applyButton.focusRingType = .none
- applyButton.pointerCursor = true
- applyButton.hoverHandler = { [weak applyButton] hovering in
- applyButton?.layer?.backgroundColor = (hovering ? Theme.brandBlueHover : Theme.brandBlue).cgColor
- }
- applyButton.setContentHuggingPriority(.required, for: .horizontal)
- applyButton.setContentCompressionResistancePriority(.required, for: .horizontal)
- let savedOn = isJobSaved(job)
- let savedButton = JobPayloadButton(title: savedOn ? "Saved" : "Save", target: self, action: #selector(didTapJobSaved(_:)))
- savedButton.jobPayload = job
- savedButton.cardContext = context
- savedButton.setButtonType(.toggle)
- savedButton.isBordered = false
- savedButton.bezelStyle = .rounded
- savedButton.font = .systemFont(ofSize: 13, weight: .semibold)
- savedButton.focusRingType = .none
- savedButton.state = savedOn ? .on : .off
- savedButton.pointerCursor = true
- savedButton.hoverHandler = { [weak self, weak savedButton] _ in
- guard let savedButton = savedButton else { return }
- self?.styleJobSavedButton(savedButton)
- }
- styleJobSavedButton(savedButton)
- savedButton.setContentHuggingPriority(.required, for: .horizontal)
- savedButton.setContentCompressionResistancePriority(.required, for: .horizontal)
- let dismissButton = JobPayloadButton()
- dismissButton.jobPayload = job
- dismissButton.cardContext = context
- dismissButton.image = NSImage(systemSymbolName: "xmark", accessibilityDescription: "Dismiss")
- dismissButton.imagePosition = .imageOnly
- dismissButton.imageScaling = .scaleProportionallyDown
- dismissButton.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 11, weight: .semibold)
- dismissButton.isBordered = false
- dismissButton.bezelStyle = .rounded
- dismissButton.contentTintColor = Theme.secondaryText
- dismissButton.target = self
- dismissButton.action = #selector(didTapJobDismiss(_:))
- dismissButton.toolTip = context == .savedJobsPage ? "Remove from saved" : "Dismiss"
- dismissButton.focusRingType = .none
- dismissButton.wantsLayer = true
- dismissButton.layer?.cornerRadius = 14
- dismissButton.layer?.backgroundColor = NSColor.clear.cgColor
- dismissButton.pointerCursor = true
- dismissButton.hoverHandler = { [weak dismissButton] hovering in
- dismissButton?.layer?.backgroundColor = (hovering ? Theme.neutralHoverFill : NSColor.clear).cgColor
- dismissButton?.contentTintColor = hovering ? Theme.primaryText : Theme.secondaryText
- }
- dismissButton.setContentHuggingPriority(.required, for: .horizontal)
- let buttonRow = NSStackView(views: [applyButton, savedButton, dismissButton])
- buttonRow.orientation = .horizontal
- buttonRow.spacing = 8
- buttonRow.alignment = .centerY
- buttonRow.translatesAutoresizingMaskIntoConstraints = false
- buttonRow.setContentHuggingPriority(.required, for: .horizontal)
- buttonRow.setContentCompressionResistancePriority(.required, for: .horizontal)
- // Title hugs the leading edge; a low–hugging-priority spacer absorbs remaining width so buttons stay trailing.
- titleField.setContentHuggingPriority(.defaultHigh, for: .horizontal)
- titleField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
- let titleRowSpacer = NSView()
- titleRowSpacer.translatesAutoresizingMaskIntoConstraints = false
- titleRowSpacer.setContentHuggingPriority(NSLayoutConstraint.Priority(1), for: .horizontal)
- titleRowSpacer.setContentCompressionResistancePriority(NSLayoutConstraint.Priority(1), for: .horizontal)
- let titleAndActionsRow = NSStackView(views: [titleField, titleRowSpacer, buttonRow])
- titleAndActionsRow.orientation = .horizontal
- titleAndActionsRow.spacing = 0
- titleAndActionsRow.setCustomSpacing(14, after: titleRowSpacer)
- titleAndActionsRow.alignment = .centerY
- titleAndActionsRow.distribution = .fill
- titleAndActionsRow.userInterfaceLayoutDirection = .leftToRight
- titleAndActionsRow.translatesAutoresizingMaskIntoConstraints = false
- let contentColumn = NSStackView(views: [titleAndActionsRow, descriptionField])
- contentColumn.orientation = .vertical
- contentColumn.spacing = 6
- contentColumn.alignment = .width
- contentColumn.translatesAutoresizingMaskIntoConstraints = false
- card.addSubview(contentColumn)
- NSLayoutConstraint.activate([
- contentColumn.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: 16),
- contentColumn.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -16),
- contentColumn.topAnchor.constraint(equalTo: card.topAnchor, constant: 14),
- contentColumn.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -14),
- applyButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 72),
- applyButton.heightAnchor.constraint(equalToConstant: 28),
- savedButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 72),
- savedButton.heightAnchor.constraint(equalToConstant: 28),
- dismissButton.widthAnchor.constraint(equalToConstant: 28),
- dismissButton.heightAnchor.constraint(equalToConstant: 28),
- descriptionField.widthAnchor.constraint(equalTo: contentColumn.widthAnchor)
- ])
- return card
- }
- private func styleJobSavedButton(_ button: NSButton) {
- button.wantsLayer = true
- button.layer?.cornerRadius = 6
- let on = button.state == .on
- let hovering = (button as? HoverableButton)?.isHovering ?? false
- if on {
- button.layer?.backgroundColor = (hovering ? Theme.selectionFillHover : Theme.selectionFill).cgColor
- button.layer?.borderWidth = 1
- button.layer?.borderColor = Theme.brandBlue.cgColor
- button.contentTintColor = Theme.brandBlue
- } else {
- button.layer?.backgroundColor = (hovering ? Theme.neutralHoverFill : Theme.cardBackground).cgColor
- button.layer?.borderWidth = 1
- button.layer?.borderColor = Theme.border.cgColor
- button.contentTintColor = Theme.primaryText
- }
- }
- @objc private func didTapJobApply(_ sender: NSButton) {
- guard let job = (sender as? JobPayloadButton)?.jobPayload else { return }
- let allowed = CharacterSet.urlQueryAllowed
- let q = job.title.addingPercentEncoding(withAllowedCharacters: allowed) ?? ""
- guard let url = URL(string: "https://www.indeed.com/jobs?q=\(q)") else { return }
- NSWorkspace.shared.open(url)
- }
- @objc private func didTapJobSaved(_ sender: NSButton) {
- guard let job = (sender as? JobPayloadButton)?.jobPayload else { return }
- let willSave = !isJobSaved(job)
- applySavedState(willSave, for: job)
- sender.state = willSave ? .on : .off
- sender.title = willSave ? "Saved" : "Save"
- styleJobSavedButton(sender)
- if isSavedJobsSidebarIndex(selectedSidebarIndex) {
- reloadSavedJobsListings()
- }
- }
- @objc private func didTapJobDismiss(_ sender: NSButton) {
- guard let button = sender as? JobPayloadButton, let job = button.jobPayload else { return }
- switch button.cardContext {
- case .homeSearchResults:
- lastSearchResults.removeAll { $0 == job }
- configureJobListings(lastSearchResults, noResultsForQuery: lastNoResultsQuery)
- case .savedJobsPage:
- applySavedState(false, for: job)
- reloadSavedJobsListings()
- if isHomeSidebarIndex(selectedSidebarIndex), !lastSearchResults.isEmpty {
- configureJobListings(lastSearchResults, noResultsForQuery: lastNoResultsQuery, updateLastResults: false)
- }
- }
- }
- 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
- searchCard.hoverHandler = { [weak self] hovering in
- guard let self else { return }
- CATransaction.begin()
- CATransaction.setAnimationDuration(0.15)
- self.searchCard.layer?.backgroundColor = (hovering ? Theme.neutralHoverFill : Theme.cardBackground).cgColor
- self.searchCard.layer?.borderColor = (hovering ? Theme.searchBarBorderHover : Theme.searchBarBorder).cgColor
- self.searchBarShadowHost.layer?.shadowColor = NSColor.black.withAlphaComponent(hovering ? 0.24 : 0.18).cgColor
- self.searchBarShadowHost.layer?.shadowRadius = hovering ? 12 : 10
- CATransaction.commit()
- }
- 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
- // Tracks hover over the full pill (the button only covers an inset area), so the gradient darkens whenever the mouse is anywhere over the CTA.
- findJobsCTAChrome.pointerCursor = true
- findJobsCTAChrome.hoverHandler = { [weak self] hovering in
- guard let layer = self?.findJobsCTAGradientLayer else { return }
- CATransaction.begin()
- CATransaction.setAnimationDuration(0.15)
- layer.colors = hovering
- ? [Theme.findJobsCTAHighlightHover.cgColor, Theme.brandBlueHover.cgColor]
- : [Theme.findJobsCTAHighlight.cgColor, Theme.brandBlue.cgColor]
- CATransaction.commit()
- }
- 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 configureNonHomePlaceholder() {
- nonHomeHost.translatesAutoresizingMaskIntoConstraints = false
- nonHomeHost.wantsLayer = true
- nonHomeHost.layer?.backgroundColor = Theme.mainHostBackground.cgColor
- nonHomeHost.isHidden = true
- nonHomeGenericContainer.translatesAutoresizingMaskIntoConstraints = false
- savedJobsPageContainer.translatesAutoresizingMaskIntoConstraints = false
- nonHomeHost.addSubview(nonHomeGenericContainer)
- nonHomeHost.addSubview(savedJobsPageContainer)
- NSLayoutConstraint.activate([
- nonHomeGenericContainer.leadingAnchor.constraint(equalTo: nonHomeHost.leadingAnchor),
- nonHomeGenericContainer.trailingAnchor.constraint(equalTo: nonHomeHost.trailingAnchor),
- nonHomeGenericContainer.topAnchor.constraint(equalTo: nonHomeHost.topAnchor),
- nonHomeGenericContainer.bottomAnchor.constraint(equalTo: nonHomeHost.bottomAnchor),
- savedJobsPageContainer.leadingAnchor.constraint(equalTo: nonHomeHost.leadingAnchor),
- savedJobsPageContainer.trailingAnchor.constraint(equalTo: nonHomeHost.trailingAnchor),
- savedJobsPageContainer.topAnchor.constraint(equalTo: nonHomeHost.topAnchor),
- savedJobsPageContainer.bottomAnchor.constraint(equalTo: nonHomeHost.bottomAnchor)
- ])
- nonHomeTitleLabel.font = .systemFont(ofSize: 22, weight: .bold)
- nonHomeTitleLabel.textColor = Theme.primaryText
- nonHomeTitleLabel.alignment = .center
- nonHomeTitleLabel.maximumNumberOfLines = 1
- nonHomeSubtitleLabel.font = .systemFont(ofSize: 14, weight: .regular)
- nonHomeSubtitleLabel.textColor = Theme.secondaryText
- nonHomeSubtitleLabel.alignment = .center
- nonHomeSubtitleLabel.maximumNumberOfLines = 0
- nonHomeSubtitleLabel.stringValue = "This area is not available in the preview build. Use Home to search jobs."
- let genericStack = NSStackView(views: [nonHomeTitleLabel, nonHomeSubtitleLabel])
- genericStack.orientation = .vertical
- genericStack.spacing = 10
- genericStack.alignment = .centerX
- genericStack.translatesAutoresizingMaskIntoConstraints = false
- nonHomeGenericContainer.addSubview(genericStack)
- NSLayoutConstraint.activate([
- genericStack.centerXAnchor.constraint(equalTo: nonHomeGenericContainer.centerXAnchor),
- genericStack.centerYAnchor.constraint(equalTo: nonHomeGenericContainer.centerYAnchor),
- genericStack.leadingAnchor.constraint(greaterThanOrEqualTo: nonHomeGenericContainer.leadingAnchor, constant: 32),
- genericStack.trailingAnchor.constraint(lessThanOrEqualTo: nonHomeGenericContainer.trailingAnchor, constant: -32),
- nonHomeSubtitleLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 420)
- ])
- savedJobsPageTitleLabel.font = .systemFont(ofSize: 22, weight: .bold)
- savedJobsPageTitleLabel.textColor = Theme.primaryText
- savedJobsPageTitleLabel.alignment = .left
- savedJobsPageTitleLabel.maximumNumberOfLines = 1
- savedJobsPageSubtitleLabel.font = .systemFont(ofSize: 14, weight: .regular)
- savedJobsPageSubtitleLabel.textColor = Theme.secondaryText
- savedJobsPageSubtitleLabel.alignment = .left
- savedJobsPageSubtitleLabel.maximumNumberOfLines = 0
- savedJobsDocumentView.translatesAutoresizingMaskIntoConstraints = false
- savedJobsStack.orientation = .vertical
- savedJobsStack.spacing = 14
- savedJobsStack.alignment = .leading
- savedJobsStack.distribution = .fill
- savedJobsStack.translatesAutoresizingMaskIntoConstraints = false
- savedJobsStack.setContentHuggingPriority(.defaultHigh, for: .vertical)
- savedJobsStack.setHuggingPriority(.defaultLow, for: .horizontal)
- savedJobsDocumentView.addSubview(savedJobsStack)
- NSLayoutConstraint.activate([
- savedJobsStack.leadingAnchor.constraint(equalTo: savedJobsDocumentView.leadingAnchor),
- savedJobsStack.trailingAnchor.constraint(equalTo: savedJobsDocumentView.trailingAnchor),
- savedJobsStack.topAnchor.constraint(equalTo: savedJobsDocumentView.topAnchor),
- savedJobsStack.bottomAnchor.constraint(equalTo: savedJobsDocumentView.bottomAnchor)
- ])
- savedJobsScrollView.translatesAutoresizingMaskIntoConstraints = false
- savedJobsScrollView.hasVerticalScroller = true
- savedJobsScrollView.hasHorizontalScroller = false
- savedJobsScrollView.autohidesScrollers = true
- savedJobsScrollView.drawsBackground = false
- savedJobsScrollView.borderType = .noBorder
- savedJobsScrollView.documentView = savedJobsDocumentView
- savedJobsScrollView.setContentHuggingPriority(.defaultLow, for: .vertical)
- savedJobsScrollView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
- let savedHeaderStack = NSStackView(views: [savedJobsPageTitleLabel, savedJobsPageSubtitleLabel])
- savedHeaderStack.orientation = .vertical
- savedHeaderStack.spacing = 6
- savedHeaderStack.alignment = .leading
- savedHeaderStack.translatesAutoresizingMaskIntoConstraints = false
- let savedOuterStack = NSStackView(views: [savedHeaderStack, savedJobsScrollView])
- savedOuterStack.orientation = .vertical
- savedOuterStack.spacing = 16
- // Leading alignment plus explicit column width keeps the title and subtitle on the same edge as the cards.
- savedOuterStack.alignment = .leading
- savedOuterStack.translatesAutoresizingMaskIntoConstraints = false
- savedJobsPageContainer.userInterfaceLayoutDirection = .leftToRight
- savedJobsPageContainer.addSubview(savedOuterStack)
- NSLayoutConstraint.activate([
- savedOuterStack.leadingAnchor.constraint(equalTo: savedJobsPageContainer.leadingAnchor, constant: 32),
- savedOuterStack.trailingAnchor.constraint(equalTo: savedJobsPageContainer.trailingAnchor, constant: -32),
- savedOuterStack.topAnchor.constraint(equalTo: savedJobsPageContainer.topAnchor, constant: 8),
- savedOuterStack.bottomAnchor.constraint(equalTo: savedJobsPageContainer.bottomAnchor),
- savedHeaderStack.widthAnchor.constraint(equalTo: savedOuterStack.widthAnchor),
- savedJobsScrollView.widthAnchor.constraint(equalTo: savedOuterStack.widthAnchor),
- savedJobsDocumentView.topAnchor.constraint(equalTo: savedJobsScrollView.contentView.topAnchor),
- savedJobsDocumentView.leadingAnchor.constraint(equalTo: savedJobsScrollView.contentView.leadingAnchor),
- savedJobsDocumentView.widthAnchor.constraint(equalTo: savedJobsScrollView.contentView.widthAnchor)
- ])
- }
- private func reloadSavedJobsListings() {
- savedJobsStack.arrangedSubviews.forEach {
- savedJobsStack.removeArrangedSubview($0)
- $0.removeFromSuperview()
- }
- if savedJobOrder.isEmpty {
- savedJobsPageSubtitleLabel.stringValue = "Save jobs from Home to see them here."
- let empty = NSTextField(wrappingLabelWithString: "No saved jobs yet. Search on Home, then tap Save on a listing.")
- empty.font = .systemFont(ofSize: 14, weight: .regular)
- empty.textColor = Theme.secondaryText
- empty.alignment = .left
- empty.maximumNumberOfLines = 0
- empty.translatesAutoresizingMaskIntoConstraints = false
- savedJobsStack.addArrangedSubview(empty)
- empty.widthAnchor.constraint(equalTo: savedJobsStack.widthAnchor).isActive = true
- return
- }
- savedJobsPageSubtitleLabel.stringValue = "\(savedJobOrder.count) saved \(savedJobOrder.count == 1 ? "position" : "positions")"
- for job in savedJobOrder {
- let card = makeJobListingCard(job, context: .savedJobsPage)
- savedJobsStack.addArrangedSubview(card)
- card.widthAnchor.constraint(equalTo: savedJobsStack.widthAnchor).isActive = true
- }
- }
- private func isSavedJobsSidebarIndex(_ index: Int) -> Bool {
- guard index >= 0, index < currentSidebarItems.count else { return false }
- return currentSidebarItems[index].title == "Saved Jobs"
- }
- private func isHomeSidebarIndex(_ index: Int) -> Bool {
- guard index >= 0, index < currentSidebarItems.count else { return false }
- return currentSidebarItems[index].title == "Home"
- }
- private func updateMainContentVisibility() {
- let home = isHomeSidebarIndex(selectedSidebarIndex)
- let savedJobs = isSavedJobsSidebarIndex(selectedSidebarIndex)
- mainOverlay.isHidden = !home
- nonHomeHost.isHidden = home
- nonHomeGenericContainer.isHidden = savedJobs
- savedJobsPageContainer.isHidden = !savedJobs
- if !home, selectedSidebarIndex < currentSidebarItems.count {
- if savedJobs {
- reloadSavedJobsListings()
- } else {
- nonHomeTitleLabel.stringValue = currentSidebarItems[selectedSidebarIndex].title
- }
- }
- }
- /// Removes result cards or the “no matches” message so a new search starts from a blank listing area.
- private func clearJobSearchResultsUI() {
- configureJobListings([], noResultsForQuery: nil)
- if let doc = jobListingsScrollView.documentView {
- doc.scroll(NSPoint(x: 0, y: 0))
- }
- }
- /// Restores the main job-search experience: cleared query and no listings until the user searches again.
- private func applyHomeState() {
- jobKeywordsField.stringValue = ""
- clearJobSearchResultsUI()
- window?.makeFirstResponder(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)
- if (obj.object as? NSTextField) === jobKeywordsField {
- clearJobSearchResultsUI()
- }
- }
- 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
- rowHost.restingBackgroundColor = isSelected ? Theme.selectionFill : nil
- rowHost.hoverBackgroundColor = isSelected ? Theme.selectionFillHover : Theme.sidebarRowHoverFill
- 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 the fixed sidebar width minus horizontal edge insets; card must stay within that band.
- let cardWidth: CGFloat = 186
- let innerContentWidth = cardWidth - 28
- upgradeDescription.preferredMaxLayoutWidth = innerContentWidth
- let upgradeButton = HoverableButton(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
- upgradeButton.pointerCursor = true
- upgradeButton.hoverHandler = { [weak upgradeButton] hovering in
- upgradeButton?.layer?.backgroundColor = (hovering ? Theme.brandBlueHover : Theme.proCTABackground).cgColor
- }
- 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 else { return }
- let selectingHome = isHomeSidebarIndex(index)
- if index == selectedSidebarIndex {
- if selectingHome {
- applyHomeState()
- }
- return
- }
- selectedSidebarIndex = index
- configureSidebar()
- updateMainContentVisibility()
- if selectingHome {
- applyHomeState()
- }
- }
- }
- /// `NSButton` that carries a `JobListing` for card actions (`representedObject` is unavailable on `NSButton` in this target).
- private final class JobPayloadButton: HoverableButton {
- var jobPayload: JobListing?
- var cardContext: JobListingCardContext = .homeSearchResults
- }
- /// `NSButton` with a tracking area that reports hover transitions and (optionally) swaps in a pointing-hand cursor while hovered.
- private class HoverableButton: NSButton {
- var hoverHandler: ((Bool) -> Void)?
- var pointerCursor: Bool = false
- private(set) var isHovering: Bool = false
- private var trackingArea: NSTrackingArea?
- private var didPushCursor: Bool = false
- override func updateTrackingAreas() {
- super.updateTrackingAreas()
- if let area = trackingArea { removeTrackingArea(area) }
- 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)
- isHovering = true
- hoverHandler?(true)
- if pointerCursor, !didPushCursor {
- NSCursor.pointingHand.push()
- didPushCursor = true
- }
- }
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- isHovering = false
- hoverHandler?(false)
- if didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- }
- }
- override func viewWillMove(toWindow newWindow: NSWindow?) {
- super.viewWillMove(toWindow: newWindow)
- // Guard against an unbalanced cursor stack if the button is removed mid-hover (e.g. job card replaced after a search).
- if newWindow == nil, didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- isHovering = false
- }
- }
- }
- /// `NSView` companion to `HoverableButton`: emits hover transitions and can manage a pointing-hand cursor. Used to track hover over composite controls like the gradient "Find jobs" pill.
- private class HoverableView: NSView {
- var hoverHandler: ((Bool) -> Void)?
- var pointerCursor: Bool = false
- private(set) var isHovering: Bool = false
- private var trackingArea: NSTrackingArea?
- private var didPushCursor: Bool = false
- override func updateTrackingAreas() {
- super.updateTrackingAreas()
- if let area = trackingArea { removeTrackingArea(area) }
- 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)
- isHovering = true
- hoverHandler?(true)
- if pointerCursor, !didPushCursor {
- NSCursor.pointingHand.push()
- didPushCursor = true
- }
- }
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- isHovering = false
- hoverHandler?(false)
- if didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- }
- }
- override func viewWillMove(toWindow newWindow: NSWindow?) {
- super.viewWillMove(toWindow: newWindow)
- if newWindow == nil, didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- isHovering = false
- }
- }
- }
- /// 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. Manages its own hover background so non-selected rows highlight subtly on hover without disturbing the selected-row fill.
- private final class SidebarNavRowView: NSView {
- private let onSelect: () -> Void
- var restingBackgroundColor: NSColor? {
- didSet { applyBackground() }
- }
- var hoverBackgroundColor: NSColor?
- private var isHovering: Bool = false
- private var didPushCursor: Bool = false
- 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)
- isHovering = true
- applyBackground()
- if !didPushCursor {
- NSCursor.pointingHand.push()
- didPushCursor = true
- }
- }
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- isHovering = false
- applyBackground()
- if didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- }
- }
- override func viewWillMove(toWindow newWindow: NSWindow?) {
- super.viewWillMove(toWindow: newWindow)
- if newWindow == nil, didPushCursor {
- NSCursor.pop()
- didPushCursor = false
- isHovering = false
- }
- }
- private func applyBackground() {
- let color = isHovering ? (hoverBackgroundColor ?? restingBackgroundColor) : restingBackgroundColor
- layer?.backgroundColor = color?.cgColor
- }
- }
|