Sfoglia il codice sorgente

Fix CV preview using the exact template from the gallery card.

Re-resolving by id could drift from the thumbnail the user chose; the dashboard now keeps the full CVTemplate snapshot from the CTA.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 2 mesi fa
parent
commit
7bcf41f2d5

+ 15 - 5
App for Indeed/Views/CVMakerPageView.swift

@@ -596,8 +596,8 @@ final class CVMakerPageView: NSView {
     /// Every visible gallery card (not keyed by id — duplicate AI ids would collapse in a dictionary and break single-selection visuals).
     private var templateCardsInGrid: [CVTemplateCard] = []
 
-    /// Invoked when the user taps **Use Template & Select Profile** with a valid gallery selection. Delivers the selected template’s catalog id so the host can route to profile pickers or a future editor.
-    var onContinueToProfileSelection: ((String) -> Void)?
+    /// Invoked when the user taps **Use Template & Select Profile** with a valid gallery selection. Delivers the same `CVTemplate` instance the card used for its thumbnail (not a re-lookup by id), so the filled résumé cannot drift from the user’s pick.
+    var onContinueToProfileSelection: ((CVTemplate) -> Void)?
 
     func templateInGallery(withID id: String) -> CVTemplate? {
         resolvedTemplate(withID: id)
@@ -964,12 +964,20 @@ final class CVMakerPageView: NSView {
     }
 
     @objc private func didTapUseTemplate() {
-        guard let id = selectedTemplateID,
-              activeCatalog.contains(where: { $0.id == id }) else {
+        let chosen: CVTemplate?
+        if let token = selectedTemplateCardToken,
+           let card = templateCardsInGrid.first(where: { $0.selectionToken == token }) {
+            chosen = card.catalogTemplate
+        } else if let id = selectedTemplateID {
+            chosen = resolvedTemplate(withID: id)
+        } else {
+            chosen = nil
+        }
+        guard let template = chosen else {
             presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
             return
         }
-        onContinueToProfileSelection?(id)
+        onContinueToProfileSelection?(template)
     }
 
     private func updateSelectedChipStates() {
@@ -1248,6 +1256,8 @@ private final class CVTemplateCard: NSView {
     /// Distinguishes this card from others that may share the same catalog `template.id`.
     let selectionToken = UUID()
     var templateID: String { template.id }
+    /// Definition used for this card’s preview; pass through on “Use template” so layout cannot diverge from a later id-only lookup.
+    var catalogTemplate: CVTemplate { template }
     private let template: CVTemplate
     private let palette: CVTemplateCardPalette
     private let previewSurface = NSView()

+ 7 - 9
App for Indeed/Views/DashboardView.swift

@@ -136,8 +136,8 @@ final class DashboardView: NSView, NSTextFieldDelegate {
     private var isProfileEditorPresented = false
     /// When true, the merged CV preview is visible instead of the profiles list or editor.
     private var isCVDocumentPreviewPresented = false
-    /// Template id chosen in CV Maker until the user leaves Profile or starts a new CV Maker hand-off.
-    private var pendingCVTemplateID: String?
+    /// Exact template chosen in CV Maker until the user leaves Profile or starts a new CV Maker hand-off (avoids re-resolving by id and picking a different row).
+    private var pendingCVTemplate: CVTemplate?
     private let cvFilledPreviewPageView = CVFilledPreviewPageView()
 
     private var currentSidebarItems: [SidebarItem] = []
@@ -1344,11 +1344,10 @@ final class DashboardView: NSView, NSTextFieldDelegate {
             cvMakerPageView.bottomAnchor.constraint(equalTo: cvMakerPageContainer.bottomAnchor)
         ])
 
-        cvMakerPageView.onContinueToProfileSelection = { [weak self] templateID in
+        cvMakerPageView.onContinueToProfileSelection = { [weak self] template in
             guard let self else { return }
-            self.pendingCVTemplateID = templateID
-            let name = self.cvMakerPageView.resolvedTemplate(withID: templateID)?.name ?? "Selected template"
-            self.profilesListPageView.setPendingCVTemplateDisplayName(name)
+            self.pendingCVTemplate = template
+            self.profilesListPageView.setPendingCVTemplateDisplayName(template.name)
             self.selectProfileSidebarForCVMakerFlow()
         }
     }
@@ -1400,8 +1399,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
         }
         profilesListPageView.onBuildCVWithProfile = { [weak self] profileID in
             guard let self,
-                  let tid = self.pendingCVTemplateID,
-                  let template = self.cvMakerPageView.resolvedTemplate(withID: tid),
+                  let template = self.pendingCVTemplate,
                   let profile = SavedProfilesStore.profile(id: profileID) else { return }
             self.presentCVDocumentPreview(profile: profile, template: template)
         }
@@ -1749,7 +1747,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
         if !profile {
             isProfileEditorPresented = false
             isCVDocumentPreviewPresented = false
-            pendingCVTemplateID = nil
+            pendingCVTemplate = nil
             profilesListPageView.setPendingCVTemplateDisplayName(nil)
             cvFilledPreviewPageView.isHidden = true
             profilesListPageView.isHidden = false