From 61f50617bf7fa03ddf8f0771b20470d4f255817e Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Sat, 13 Jan 2024 12:29:25 +0700 Subject: [PATCH 1/3] fix: defer email subscription state fetching --- src/components/MenuAccount.vue | 24 +---------- src/components/ModalEmail.vue | 51 +++++++++++++++++++++++ src/components/ModalEmailManagement.vue | 26 ++++-------- src/components/ModalEmailResend.vue | 22 +++------- src/components/ModalEmailSubscription.vue | 49 +++++++++------------- src/composables/useEmailSubscription.ts | 5 ++- 6 files changed, 88 insertions(+), 89 deletions(-) create mode 100644 src/components/ModalEmail.vue diff --git a/src/components/MenuAccount.vue b/src/components/MenuAccount.vue index 63ff1dbf16c..5a04d72b020 100644 --- a/src/components/MenuAccount.vue +++ b/src/components/MenuAccount.vue @@ -7,17 +7,9 @@ const emit = defineEmits(['switchWallet']); const { domain } = useApp(); const { logout } = useWeb3(); const router = useRouter(); -const { userState, loadEmailSubscriptions } = useEmailSubscription(); const showModalEmail = ref(false); -onMounted(loadEmailSubscriptions); -watch(showModalEmail, () => { - if (!showModalEmail.value) { - loadEmailSubscriptions(); - } -}); - function handleAction(e) { if (e === 'viewProfile') // Link to profile page, if on custom domain then the link is external @@ -90,20 +82,6 @@ function handleAction(e) { - - - + diff --git a/src/components/ModalEmail.vue b/src/components/ModalEmail.vue new file mode 100644 index 00000000000..05d556d8261 --- /dev/null +++ b/src/components/ModalEmail.vue @@ -0,0 +1,51 @@ + + + diff --git a/src/components/ModalEmailManagement.vue b/src/components/ModalEmailManagement.vue index 0a008ab5896..a7a4b831669 100644 --- a/src/components/ModalEmailManagement.vue +++ b/src/components/ModalEmailManagement.vue @@ -1,8 +1,4 @@ diff --git a/src/components/ModalEmailResend.vue b/src/components/ModalEmailResend.vue index 0c9369bd64c..b9f3dd4df62 100644 --- a/src/components/ModalEmailResend.vue +++ b/src/components/ModalEmailResend.vue @@ -1,23 +1,13 @@ diff --git a/src/components/ModalEmailSubscription.vue b/src/components/ModalEmailSubscription.vue index eb4493b11c3..7be76dc906b 100644 --- a/src/components/ModalEmailSubscription.vue +++ b/src/components/ModalEmailSubscription.vue @@ -1,8 +1,4 @@ diff --git a/src/composables/useEmailSubscription.ts b/src/composables/useEmailSubscription.ts index 171a1a3c663..087f2a9eab0 100644 --- a/src/composables/useEmailSubscription.ts +++ b/src/composables/useEmailSubscription.ts @@ -14,6 +14,7 @@ function useEmailSubscriptionComposable() { const userState = ref('NOT_SUBSCRIBED'); const error = ref(''); + const initialized = ref(false); const loading = ref(false); const apiSubscriptions = ref([]); @@ -50,6 +51,7 @@ function useEmailSubscriptionComposable() { userState.value = usrState; apiSubscriptions.value = subscriptions || []; loading.value = false; + initialized.value = true; }; const subscribe = async (email: string) => { @@ -88,7 +90,8 @@ function useEmailSubscriptionComposable() { subscribe, updateSubscriptions, loadEmailSubscriptions, - loading + loading, + initialized }; } From 8c883b5a3146aa67c5bf9eaceb6a266c56082ee8 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:25:41 +0700 Subject: [PATCH 2/3] fix: fix email subscription in post vote modal --- src/components/MenuAccount.vue | 7 +++---- src/components/ModalPostVote.vue | 11 +++++++++-- src/components/SpaceProposalPage.vue | 9 ++------- src/composables/useModal.ts | 5 +++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/components/MenuAccount.vue b/src/components/MenuAccount.vue index 5a04d72b020..d62cd253838 100644 --- a/src/components/MenuAccount.vue +++ b/src/components/MenuAccount.vue @@ -6,10 +6,9 @@ const props = defineProps<{ const emit = defineEmits(['switchWallet']); const { domain } = useApp(); const { logout } = useWeb3(); +const { modalEmailOpen } = useModal(); const router = useRouter(); -const showModalEmail = ref(false); - function handleAction(e) { if (e === 'viewProfile') // Link to profile page, if on custom domain then the link is external @@ -21,7 +20,7 @@ function handleAction(e) { }); if (e === 'switchWallet') return emit('switchWallet'); if (e === 'subscribeEmail') { - showModalEmail.value = true; + modalEmailOpen.value = true; return true; } @@ -82,6 +81,6 @@ function handleAction(e) { - + diff --git a/src/components/ModalPostVote.vue b/src/components/ModalPostVote.vue index 136d167e7c3..64f2e06a055 100644 --- a/src/components/ModalPostVote.vue +++ b/src/components/ModalPostVote.vue @@ -4,7 +4,8 @@ import { ExtendedSpace, Proposal } from '@/helpers/interfaces'; const { shareVote, shareProposalTwitter, shareProposalHey } = useSharing(); const { web3Account } = useWeb3(); -const { userState } = useEmailSubscription(); +const { userState, loadEmailSubscriptions, initialized } = + useEmailSubscription(); const props = defineProps<{ open: boolean; @@ -34,6 +35,12 @@ function share(shareTo: 'twitter' | 'hey') { choices: getChoiceString(props.proposal, props.selectedChoices) }); } + +onMounted(() => { + if (!initialized.value) { + loadEmailSubscriptions(); + } +}); diff --git a/src/composables/useModal.ts b/src/composables/useModal.ts index aa5686ea0b8..ce9a69cf547 100644 --- a/src/composables/useModal.ts +++ b/src/composables/useModal.ts @@ -1,6 +1,7 @@ const modalAccountOpen = ref(false); -const isModalPostVoteOpen = ref(false); +const isModalPostVoteOpen = ref(true); +const modalEmailOpen = ref(false); export function useModal() { - return { modalAccountOpen, isModalPostVoteOpen }; + return { modalAccountOpen, isModalPostVoteOpen, modalEmailOpen }; } From 7d598b7c498be6b7e92ad2a668bd419e86ea9eed Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Sat, 13 Jan 2024 22:09:45 +0700 Subject: [PATCH 3/3] fix: remove debug value --- src/composables/useModal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/composables/useModal.ts b/src/composables/useModal.ts index ce9a69cf547..88edd058b65 100644 --- a/src/composables/useModal.ts +++ b/src/composables/useModal.ts @@ -1,5 +1,5 @@ const modalAccountOpen = ref(false); -const isModalPostVoteOpen = ref(true); +const isModalPostVoteOpen = ref(false); const modalEmailOpen = ref(false); export function useModal() {