@@ -38,18 +38,15 @@ struct SampleLink: View {
3838 // of its map when a keyboard is presented in landscape mode.
3939 . ignoresSafeArea ( . keyboard, edges: . bottom)
4040 } label: {
41- SampleRow (
42- name: sample. name. boldingFirstOccurrence ( of: textToBold) ,
43- description: sample. description. boldingFirstOccurrence ( of: textToBold)
44- )
41+ SampleRow ( sample, textToBold: textToBold)
4542 }
4643 }
4744}
4845
4946private extension SampleLink {
5047 struct SampleRow : View {
51- /// The name of the sample .
52- private let name : String
48+ /// The sample for the row .
49+ private let sample : Sample
5350
5451 /// The name of the sample with attributes.
5552 private let attributedName : AttributedString
@@ -63,15 +60,10 @@ private extension SampleLink {
6360 /// The names of the favorite samples loaded from user defaults.
6461 @AppFavorites private var favoriteNames
6562
66- /// A Boolean value indicating whether the sample is a favorite.
67- private var sampleIsFavorite : Bool {
68- favoriteNames. contains ( name)
69- }
70-
71- init ( name: AttributedString , description: AttributedString ) {
72- self . name = String ( name. characters)
73- self . attributedName = name
74- self . attributedDescription = description
63+ init ( _ sample: Sample , textToBold: String ) {
64+ self . sample = sample
65+ self . attributedName = sample. name. boldingFirstOccurrence ( of: textToBold)
66+ self . attributedDescription = sample. description. boldingFirstOccurrence ( of: textToBold)
7567 }
7668
7769 var body : some View {
@@ -88,7 +80,7 @@ private extension SampleLink {
8880 }
8981 Spacer ( )
9082
91- if sampleIsFavorite {
83+ if favoriteNames . contains ( sample . name ) {
9284 Image ( systemName: " star.fill " )
9385 . foregroundStyle ( . yellow)
9486 }
@@ -103,16 +95,7 @@ private extension SampleLink {
10395 }
10496 }
10597 . contextMenu {
106- Button {
107- if sampleIsFavorite {
108- favoriteNames. removeAll { $0 == name }
109- } else {
110- favoriteNames. append ( name)
111- }
112- } label: {
113- Label ( sampleIsFavorite ? " Unfavorite " : " Favorite " , systemImage: " star " )
114- . symbolVariant ( sampleIsFavorite ? . slash : . none)
115- }
98+ SampleMenuButtons ( sample: sample)
11699 }
117100 . animation ( . easeOut( duration: 0.2 ) , value: isShowingDescription)
118101 }
0 commit comments