소스 검색

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 주 전
부모
커밋
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 596
     /// Every visible gallery card (not keyed by id — duplicate AI ids would collapse in a dictionary and break single-selection visuals).
597 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 602
     func templateInGallery(withID id: String) -> CVTemplate? {
603 603
         resolvedTemplate(withID: id)
@@ -964,12 +964,20 @@ final class CVMakerPageView: NSView {
964 964
     }
965 965
 
966 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 977
             presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
970 978
             return
971 979
         }
972
-        onContinueToProfileSelection?(id)
980
+        onContinueToProfileSelection?(template)
973 981
     }
974 982
 
975 983
     private func updateSelectedChipStates() {
@@ -1248,6 +1256,8 @@ private final class CVTemplateCard: NSView {
1248 1256
     /// Distinguishes this card from others that may share the same catalog `template.id`.
1249 1257
     let selectionToken = UUID()
1250 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 1261
     private let template: CVTemplate
1252 1262
     private let palette: CVTemplateCardPalette
1253 1263
     private let previewSurface = NSView()

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

@@ -136,8 +136,8 @@ final class DashboardView: NSView, NSTextFieldDelegate {
136 136
     private var isProfileEditorPresented = false
137 137
     /// When true, the merged CV preview is visible instead of the profiles list or editor.
138 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 141
     private let cvFilledPreviewPageView = CVFilledPreviewPageView()
142 142
 
143 143
     private var currentSidebarItems: [SidebarItem] = []
@@ -1344,11 +1344,10 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1344 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 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 1351
             self.selectProfileSidebarForCVMakerFlow()
1353 1352
         }
1354 1353
     }
@@ -1400,8 +1399,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1400 1399
         }
1401 1400
         profilesListPageView.onBuildCVWithProfile = { [weak self] profileID in
1402 1401
             guard let self,
1403
-                  let tid = self.pendingCVTemplateID,
1404
-                  let template = self.cvMakerPageView.resolvedTemplate(withID: tid),
1402
+                  let template = self.pendingCVTemplate,
1405 1403
                   let profile = SavedProfilesStore.profile(id: profileID) else { return }
1406 1404
             self.presentCVDocumentPreview(profile: profile, template: template)
1407 1405
         }
@@ -1749,7 +1747,7 @@ final class DashboardView: NSView, NSTextFieldDelegate {
1749 1747
         if !profile {
1750 1748
             isProfileEditorPresented = false
1751 1749
             isCVDocumentPreviewPresented = false
1752
-            pendingCVTemplateID = nil
1750
+            pendingCVTemplate = nil
1753 1751
             profilesListPageView.setPendingCVTemplateDisplayName(nil)
1754 1752
             cvFilledPreviewPageView.isHidden = true
1755 1753
             profilesListPageView.isHidden = false