@@ -29,8 +29,9 @@ import { useRouter } from 'vue-router'
2929
3030import { isRectIntersecting , useBottomSticky , useContentSize } from ' @/utils/dom'
3131import { assertNever , localStorageRef , timeout , untilNotNull } from ' @/utils/utils'
32+ import { untilLoaded } from ' @/utils/query'
3233import { useMessageHandle } from ' @/utils/exception'
33- import { isSignedIn , useSignedInUser } from ' @/stores/user'
34+ import { isSignedIn , useSignedInStateQuery } from ' @/stores/user'
3435import { useDraggable , type Offset } from ' @/utils/draggable'
3536import { providePopupContainer , UIButton , UITooltip } from ' @/components/ui'
3637import CopilotInput from ' ./CopilotInput.vue'
@@ -397,7 +398,7 @@ onBeforeUnmount(
397398)
398399
399400// Copilot open handling, implemented here due to high business logic coupling
400- const signedInUser = useSignedInUser ()
401+ const signedInStateQuery = useSignedInStateQuery ()
401402const usedCopilotUsersRef = localStorageRef <string []>(' spx-gui-used-copilot-users' , [])
402403watch (
403404 router .currentRoute ,
@@ -411,12 +412,17 @@ watch(
411412 immediate: true
412413 }
413414)
414- /**
415- * Records that the current user has used Copilot when the specified condition is met.
416- */
415+ /** Whether the current user has not used Copilot. */
416+ const copilotNotUsed = computed (() => {
417+ const signedInState = signedInStateQuery .data .value
418+ if (signedInState == null ) return false
419+ return ! signedInState .isSignedIn || ! usedCopilotUsersRef .value .includes (signedInState .user .username )
420+ })
421+ /** Records that the current user has used Copilot when the specified condition is met. */
417422async function recordCopilotUsage(shouldRecord : () => boolean ) {
418- if (! isSignedIn ()) return
419- const { username } = await untilNotNull (signedInUser )
423+ const signedInState = await untilLoaded (signedInStateQuery )
424+ if (! signedInState .isSignedIn ) return
425+ const { username } = signedInState .user
420426 const userUsedCopilot = usedCopilotUsersRef .value
421427 // Skip if condition is not met or user has already been recorded
422428 if (! shouldRecord () || userUsedCopilot .includes (username )) return
@@ -434,9 +440,9 @@ watch(
434440)
435441/** Open copilot for signed-in users on their first copilot use */
436442onMounted (async () => {
437- if ( ! isSignedIn ()) return
438- const user = await untilNotNull ( signedInUser )
439- if (usedCopilotUsersRef .value .includes (user .username )) return
443+ const signedInState = await untilLoaded ( signedInStateQuery )
444+ if ( ! signedInState . isSignedIn ) return
445+ if (usedCopilotUsersRef .value .includes (signedInState . user .username )) return
440446 copilot .open ()
441447})
442448 </script >
@@ -540,7 +546,7 @@ onMounted(async () => {
540546 <svg xmlns =" http://www.w3.org/2000/svg" width =" 16" height =" 16" viewBox =" 0 0 16 16" fill =" none" >
541547 <path d =" M12 12.6667V3.33333" stroke-width =" 1.33333" stroke-linecap =" round" stroke-linejoin =" round" />
542548 <path
543- :class =" { arrow: signedInUser == null || !usedCopilotUsersRef.includes(signedInUser.username) }"
549+ :class =" { animating: copilotNotUsed }"
544550 d =" M3.33301 3.33334L8.66634 8L3.33301 12.6667"
545551 stroke-width =" 1.33333"
546552 stroke-linecap =" round"
@@ -831,7 +837,7 @@ $toColor: #c390ff;
831837 }
832838 }
833839
834- .arrow {
840+ .animating {
835841 animation : nudge 0.5s ease-in-out infinite alternate ;
836842 }
837843
0 commit comments