@@ -41,7 +41,7 @@ protocol MainMenuViewModelDelegate: AnyObject {
4141@MainActor
4242class MainMenuViewModel : ObservableObject {
4343
44- @Published var menuSections : [ MenuSection ] = [ ]
44+ @Published var items : [ MenuItemModel ] = [ ]
4545 @Published var navigationDestination : MainMenuNavigationDestination ?
4646 @Published var showCreditsWarning : Bool = false
4747 @Published var creditsWarningHeading : String = " "
@@ -73,57 +73,79 @@ class MainMenuViewModel: ObservableObject {
7373 // MARK: - Menu Building
7474
7575 func buildMenuSections( ) {
76- var sections : [ MenuSection ] = [ ]
76+ var allItems : [ MenuItemModel ] = [ ]
7777
78- // Main services section
79- sections. append ( MenuSection ( items: [
80- . buySellDash,
81- . explore
82- ] ) )
78+ // Buy & Sell Dash
79+ allItems. append ( MenuItemModel (
80+ title: NSLocalizedString ( " Buy & sell Dash " , comment: " " ) ,
81+ icon: . custom( " image.buy.and.sell " , maxHeight: 22 ) ,
82+ action: { [ weak self] in
83+ self ? . handleBuySellDash ( )
84+ }
85+ ) )
86+
87+ // Explore
88+ allItems. append ( MenuItemModel (
89+ title: NSLocalizedString ( " Explore " , comment: " " ) ,
90+ icon: . custom( " image.explore " , maxHeight: 22 ) ,
91+ action: { [ weak self] in
92+ self ? . navigationDestination = . explore
93+ }
94+ ) )
8395
84- // Settings section
85- var settingsItems : [ MenuItemType ] = [
86- . security,
87- . settings,
88- . tools,
89- . support
90- ]
96+ // Security
97+ allItems. append ( MenuItemModel (
98+ title: NSLocalizedString ( " Security " , comment: " " ) ,
99+ icon: . custom( " image.security " , maxHeight: 22 ) ,
100+ action: { [ weak self] in
101+ self ? . navigationDestination = . security
102+ }
103+ ) )
104+
105+ // Settings
106+ allItems. append ( MenuItemModel (
107+ title: NSLocalizedString ( " Settings " , comment: " " ) ,
108+ icon: . custom( " image.settings " , maxHeight: 22 ) ,
109+ action: { [ weak self] in
110+ self ? . navigationDestination = . settings
111+ }
112+ ) )
113+
114+ // Tools
115+ allItems. append ( MenuItemModel (
116+ title: NSLocalizedString ( " Tools " , comment: " " ) ,
117+ icon: . custom( " image.tools " , maxHeight: 22 ) ,
118+ action: { [ weak self] in
119+ self ? . navigationDestination = . tools
120+ }
121+ ) )
122+
123+ // Support
124+ allItems. append ( MenuItemModel (
125+ title: NSLocalizedString ( " Support " , comment: " " ) ,
126+ icon: . custom( " image.support " , maxHeight: 22 ) ,
127+ action: { [ weak self] in
128+ self ? . navigationDestination = . support
129+ }
130+ ) )
91131
92132 #if DASHPAY
133+ // Voting
93134 if VotingPrefs . shared. votingEnabled {
94- settingsItems. append ( . voting)
135+ allItems. append ( MenuItemModel (
136+ title: NSLocalizedString ( " Voting " , comment: " " ) ,
137+ icon: . custom( " menu_voting " , maxHeight: 22 ) ,
138+ action: { [ weak self] in
139+ self ? . navigationDestination = . voting
140+ }
141+ ) )
95142 }
96143 #endif
97144
98- sections. append ( MenuSection ( items: settingsItems) )
99-
100- self . menuSections = sections
145+ self . items = allItems
101146 }
102147
103148 // MARK: - Actions
104-
105- func handleMenuAction( _ item: MenuItemType ) {
106- switch item {
107- case . buySellDash:
108- handleBuySellDash ( )
109- case . explore:
110- navigationDestination = . explore
111- case . security:
112- navigationDestination = . security
113- case . settings:
114- navigationDestination = . settings
115- case . tools:
116- navigationDestination = . tools
117- case . support:
118- navigationDestination = . support
119- #if DASHPAY
120- case . invite:
121- navigationDestination = . invite
122- case . voting:
123- navigationDestination = . voting
124- #endif
125- }
126- }
127149
128150 private func handleBuySellDash( ) {
129151 DSAuthenticationManager . sharedInstance ( ) . authenticate (
@@ -147,69 +169,3 @@ class MainMenuViewModel: ObservableObject {
147169 showCreditsWarning = true
148170 }
149171}
150-
151- // MARK: - Data Models
152-
153- struct MenuSection {
154- let items : [ MenuItemType ]
155- }
156-
157- enum MenuItemType : CaseIterable {
158- case buySellDash
159- case explore
160- case security
161- case settings
162- case tools
163- case support
164- #if DASHPAY
165- case invite
166- case voting
167- #endif
168-
169- var title : String {
170- switch self {
171- case . buySellDash:
172- return NSLocalizedString ( " Buy & sell Dash " , comment: " " )
173- case . explore:
174- return NSLocalizedString ( " Explore " , comment: " " )
175- case . security:
176- return NSLocalizedString ( " Security " , comment: " " )
177- case . settings:
178- return NSLocalizedString ( " Settings " , comment: " " )
179- case . tools:
180- return NSLocalizedString ( " Tools " , comment: " " )
181- case . support:
182- return NSLocalizedString ( " Support " , comment: " " )
183- #if DASHPAY
184- case . invite:
185- return NSLocalizedString ( " Invite " , comment: " " )
186- case . voting:
187- return NSLocalizedString ( " Voting " , comment: " " )
188- #endif
189- }
190- }
191-
192- var iconName : IconName {
193- switch self {
194- case . buySellDash:
195- return . custom( " image.buy.and.sell " , maxHeight: 22 )
196- case . explore:
197- return . custom( " image.explore " , maxHeight: 22 )
198- case . security:
199- return . custom( " image.security " , maxHeight: 22 )
200- case . settings:
201- return . custom( " image.settings " , maxHeight: 22 )
202- case . tools:
203- return . custom( " image.tools " , maxHeight: 22 )
204- case . support:
205- return . custom( " image.support " , maxHeight: 22 )
206- #if DASHPAY
207- case . invite:
208- return . custom( " menu_invite " , maxHeight: 22 )
209- case . voting:
210- return . custom( " menu_voting " , maxHeight: 22 )
211- #endif
212- }
213- }
214- }
215-
0 commit comments