11<script setup lang="ts">
2- import { ref , onMounted , onUnmounted , computed } from ' vue'
2+ import { ref , onMounted , onUnmounted , computed , nextTick } from ' vue'
33import { useI18n } from ' vue-i18n'
44import { useRouter } from ' vue-router'
55import DashboardLayout from ' @/components/DashboardLayout.vue'
@@ -14,7 +14,7 @@ import type { McpInstallation } from '@/types/mcp-installations'
1414import { McpInstallationService } from ' @/services/mcpInstallationService'
1515import { TeamService , type Team } from ' @/services/teamService'
1616import { GlobalSettingsService } from ' @/services/globalSettingsService'
17- import { UserPreferencesService } from ' @/services/userPreferencesService' // NEW IMPORT
17+ import { UserPreferencesService } from ' @/services/userPreferencesService'
1818
1919const { t } = useI18n ()
2020const router = useRouter ()
@@ -95,33 +95,31 @@ const handleTeamSelected = async (data: { teamId: string; teamName: string }) =>
9595}
9696
9797// UPDATED: Check walkthrough setting and user completion status
98- const checkWalkthroughSetting = async (): Promise <void > => {
98+ const checkWalkthroughSetting = async (): Promise <boolean > => {
9999 try {
100100 // Step 1: Check if walkthrough is globally enabled
101101 const globalWalkthroughEnabled = await GlobalSettingsService .shouldShowUserWalkthrough ()
102102
103103 if (! globalWalkthroughEnabled ) {
104- showUserWalkthrough .value = false
105- return
104+ return false
106105 }
107106
108107 // Step 2: Check user's personal walkthrough completion status via API
109108 const userPreferences = await UserPreferencesService .getUserPreferences ()
110109 const isWalkthroughCompleted = userPreferences .walkthrough_completed || false
111110
112111 if (isWalkthroughCompleted ) {
113- showUserWalkthrough .value = false
114112 // Also sync to local storage for consistency
115113 eventBus .setState (' walkthrough_completed' , true )
116- return
114+ return false
117115 }
118116
119- // Step 3: Show walkthrough only if globally enabled AND user hasn't completed it
120- showUserWalkthrough . value = true
117+ // Step 3: Return true if walkthrough should be shown
118+ return true
121119
122120 } catch (error ) {
123121 console .error (' Error checking walkthrough setting:' , error )
124- showUserWalkthrough . value = false
122+ return false
125123 }
126124}
127125
@@ -134,6 +132,10 @@ const fetchInstallations = async (): Promise<void> => {
134132 error .value = null
135133
136134 installations .value = await McpInstallationService .getTeamInstallations (selectedTeam .value .id )
135+
136+ // UPDATED: Check and show walkthrough after installations are loaded
137+ await checkAndShowWalkthrough ()
138+
137139 } catch (err ) {
138140 error .value = err instanceof Error ? err .message : ' An unknown error occurred'
139141 installations .value = []
@@ -142,6 +144,46 @@ const fetchInstallations = async (): Promise<void> => {
142144 }
143145}
144146
147+ // Check and show walkthrough with proper timing
148+ const checkAndShowWalkthrough = async (): Promise <void > => {
149+ try {
150+ // Only show walkthrough if there are installations to highlight
151+ if (installations .value .length === 0 ) {
152+ showUserWalkthrough .value = false
153+ return
154+ }
155+
156+ // Check if walkthrough should be shown
157+ const shouldShowWalkthrough = await checkWalkthroughSetting ()
158+
159+ if (! shouldShowWalkthrough ) {
160+ showUserWalkthrough .value = false
161+ return
162+ }
163+
164+ // Wait for DOM to update with the installations list
165+ await nextTick ()
166+
167+ // Add a small delay to ensure the list is fully rendered
168+ setTimeout (() => {
169+ // Verify the target element exists before showing walkthrough
170+ const targetElement = document .getElementById (' last-server-item' )
171+ if (targetElement ) {
172+ showUserWalkthrough .value = true
173+ // Emit step 1 active after showing walkthrough
174+ eventBus .emit (' walkthrough-step1-active' )
175+ } else {
176+ console .warn (' Target element "last-server-item" not found, skipping walkthrough' )
177+ showUserWalkthrough .value = false
178+ }
179+ }, 100 )
180+
181+ } catch (error ) {
182+ console .error (' Error checking and showing walkthrough:' , error )
183+ showUserWalkthrough .value = false
184+ }
185+ }
186+
145187const handleInstallServer = () => {
146188 router .push (' /mcp-server/add' )
147189}
@@ -324,15 +366,7 @@ onMounted(async () => {
324366 // Initialize team context first
325367 await initializeSelectedTeam ()
326368
327- // Check walkthrough setting (now includes API call)
328- await checkWalkthroughSetting ()
329-
330- // If walkthrough should be shown, emit step 1 active
331- if (showUserWalkthrough .value ) {
332- eventBus .emit (' walkthrough-step1-active' )
333- }
334-
335- // Initial fetch after team is set
369+ // Initial fetch after team is set (walkthrough will be handled after installations load)
336370 if (selectedTeam .value ) {
337371 await fetchInstallations ()
338372 }
0 commit comments