Просмотр исходного кода

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 недель назад: 3
Родитель
Сommit
7bcf41f2d5
2 измененных файлов с 22 добавлено и 14 удалено
  1. 15 5
      App for Indeed/Views/CVMakerPageView.swift
  2. 7 9
      App for Indeed/Views/DashboardView.swift

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

@@ -596,8 +596,8 @@ final class CVMakerPageView: NSView {
596
     /// Every visible gallery card (not keyed by id — duplicate AI ids would collapse in a dictionary and break single-selection visuals).
596
     /// Every visible gallery card (not keyed by id — duplicate AI ids would collapse in a dictionary and break single-selection visuals).
597
     private var templateCardsInGrid: [CVTemplateCard] = []
597
     private var templateCardsInGrid: [CVTemplateCard] = []
598
 
598
 
599
-    /// 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.
600
-    var onContinueToProfileSelection: ((String) -> Void)?
599
+    /// 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.
600
+    var onContinueToProfileSelection: ((CVTemplate) -> Void)?
601
 
601
 
602
     func templateInGallery(withID id: String) -> CVTemplate? {
602
     func templateInGallery(withID id: String) -> CVTemplate? {
603
         resolvedTemplate(withID: id)
603
         resolvedTemplate(withID: id)
@@ -964,12 +964,20 @@ final class CVMakerPageView: NSView {
964
     }
964
     }
965
 
965
 
966
     @objc private func didTapUseTemplate() {
966
     @objc private func didTapUseTemplate() {
967
-        guard let id = selectedTemplateID,
968
-              activeCatalog.contains(where: { $0.id == id }) else {
967
+        let chosen: CVTemplate?
968
+        if let token = selectedTemplateCardToken,
969
+           let card = templateCardsInGrid.first(where: { $0.selectionToken == token }) {
970
+            chosen = card.catalogTemplate
971
+        } else if let id = selectedTemplateID {
972
+            chosen = resolvedTemplate(withID: id)
973
+        } else {
974
+            chosen = nil
975
+        }
976
+        guard let template = chosen else {
969
             presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
977
             presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
970
             return
978
             return
971
         }
979
         }
972
-        onContinueToProfileSelection?(id)
980
+        onContinueToProfileSelection?(template)
973
     }
981
     }
974
 
982
 
975
     private func updateSelectedChipStates() {
983
     private func updateSelectedChipStates() {
@@ -1248,6 +1256,8 @@ private final class CVTemplateCard: NSView {
1248
     /// Distinguishes this card from others that may share the same catalog `template.id`.
1256
     /// Distinguishes this card from others that may share the same catalog `template.id`.
1249
     let selectionToken = UUID()
1257
     let selectionToken = UUID()
1250
     var templateID: String { template.id }
1258
     var templateID: String { template.id }
1259
+    /// Definition used for this card’s preview; pass through on “Use template” so layout cannot diverge from a later id-only lookup.
1260
+    var catalogTemplate: CVTemplate { template }
1251
     private let template: CVTemplate
1261
     private let template: CVTemplate
1252
     private let palette: CVTemplateCardPalette
1262
     private let palette: CVTemplateCardPalette
1253
     private let previewSurface = NSView()
1263
     private let previewSurface = NSView()

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

@@ -136,8 +136,8 @@ final class DashboardView: NSView, NSTextFieldDelegate {
136
     private var isProfileEditorPresented = false
136
     private var isProfileEditorPresented = false
137
     /// When true, the merged CV preview is visible instead of the profiles list or editor.
137
     /// When true, the merged CV preview is visible instead of the profiles list or editor.
138
     private var isCVDocumentPreviewPresented = false
138
     private var isCVDocumentPreviewPresented = false
139
-    /// Template id chosen in CV Maker until the user leaves Profile or starts a new CV Maker hand-off.
140
-    private var pendingCVTemplateID: String?
139
+    /// 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).
140
+    private var pendingCVTemplate: CVTemplate?
141
     private let cvFilledPreviewPageView = CVFilledPreviewPageView()
141
     private let cvFilledPreviewPageView = CVFilledPreviewPageView()
142
 
142
 
143
     private var currentSidebarItems: [SidebarItem] = []
143
     private var currentSidebarItems: [SidebarItem] = []
@@ -1344,11 +1344,10 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1344
             cvMakerPageView.bottomAnchor.constraint(equalTo: cvMakerPageContainer.bottomAnchor)
1344
             cvMakerPageView.bottomAnchor.constraint(equalTo: cvMakerPageContainer.bottomAnchor)
1345
         ])
1345
         ])
1346
 
1346
 
1347
-        cvMakerPageView.onContinueToProfileSelection = { [weak self] templateID in
1347
+        cvMakerPageView.onContinueToProfileSelection = { [weak self] template in
1348
             guard let self else { return }
1348
             guard let self else { return }
1349
-            self.pendingCVTemplateID = templateID
1350
-            let name = self.cvMakerPageView.resolvedTemplate(withID: templateID)?.name ?? "Selected template"
1351
-            self.profilesListPageView.setPendingCVTemplateDisplayName(name)
1349
+            self.pendingCVTemplate = template
1350
+            self.profilesListPageView.setPendingCVTemplateDisplayName(template.name)
1352
             self.selectProfileSidebarForCVMakerFlow()
1351
             self.selectProfileSidebarForCVMakerFlow()
1353
         }
1352
         }
1354
     }
1353
     }
@@ -1400,8 +1399,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1400
         }
1399
         }
1401
         profilesListPageView.onBuildCVWithProfile = { [weak self] profileID in
1400
         profilesListPageView.onBuildCVWithProfile = { [weak self] profileID in
1402
             guard let self,
1401
             guard let self,
1403
-                  let tid = self.pendingCVTemplateID,
1404
-                  let template = self.cvMakerPageView.resolvedTemplate(withID: tid),
1402
+                  let template = self.pendingCVTemplate,
1405
                   let profile = SavedProfilesStore.profile(id: profileID) else { return }
1403
                   let profile = SavedProfilesStore.profile(id: profileID) else { return }
1406
             self.presentCVDocumentPreview(profile: profile, template: template)
1404
             self.presentCVDocumentPreview(profile: profile, template: template)
1407
         }
1405
         }
@@ -1749,7 +1747,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1749
         if !profile {
1747
         if !profile {
1750
             isProfileEditorPresented = false
1748
             isProfileEditorPresented = false
1751
             isCVDocumentPreviewPresented = false
1749
             isCVDocumentPreviewPresented = false
1752
-            pendingCVTemplateID = nil
1750
+            pendingCVTemplate = nil
1753
             profilesListPageView.setPendingCVTemplateDisplayName(nil)
1751
             profilesListPageView.setPendingCVTemplateDisplayName(nil)
1754
             cvFilledPreviewPageView.isHidden = true
1752
             cvFilledPreviewPageView.isHidden = true
1755
             profilesListPageView.isHidden = false
1753
             profilesListPageView.isHidden = false