Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hide page elements based on query param #3323

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/api/localResolvers/kivaAppReferral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default () => {
return {
resolvers: {
Query: {
isKivaAppReferral(obj, args) {
// Takes an argument of the query param value
// and returns a boolean if it is present and equal to true
return args?.kivaAppReferralQueryParam === 'true';
},
}
},
};
};
1 change: 1 addition & 0 deletions src/api/localSchema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extend type Query {
autolending: Autolending
verificationLightbox: VerificationLightbox
hasEverLoggedIn: Boolean
isKivaAppReferral(kivaAppReferralQueryParam: String): Boolean
}

extend type My {
Expand Down
2 changes: 1 addition & 1 deletion src/components/WwwFrame/LendMenu/TheLendMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default {
},
methods: {
onOpen() {
this.$refs.mega.onOpen();
this.$refs?.mega?.onOpen?.();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added optional chaining on these as I was getting an error when the header was hidden.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

},
onClose() {
this.$refs.list.onClose();
Expand Down
2 changes: 1 addition & 1 deletion src/components/WwwFrame/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export default {
},
onLendMenuShow() {
if (this.mgHighlightInNavVersion !== 'shown') {
this.$refs.lendMenu.onOpen();
this.$refs?.lendMenu?.onOpen?.();
}
this.$kvTrackEvent('TopNav', 'hover-Lend-menu', 'Lend');
},
Expand Down
49 changes: 39 additions & 10 deletions src/components/WwwFrame/WwwPage.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<template>
<div class="www-page">
<the-banner-area />
<the-header
:hide-search-in-header="hideSearchInHeader"
:theme="headerTheme"
/>
<slot name="secondary"></slot>
<template v-if="!isKivaAppReferral">
mcstover marked this conversation as resolved.
Show resolved Hide resolved
<the-banner-area />
<the-header
:hide-search-in-header="hideSearchInHeader"
:theme="headerTheme"
/>
<slot name="secondary"></slot>
</template>
<main :class="mainClasses">
<slot name="tertiary"></slot>
<slot></slot>
Expand All @@ -21,8 +23,10 @@
</template>

<script>
import _get from 'lodash/get';
import hasEverLoggedInQuery from '@/graphql/query/shared/hasEverLoggedIn.graphql';
import isKivaAppReferralQuery from '@/graphql/query/shared/isKivaAppReferral.graphql';
import logReadQueryError from '@/util/logReadQueryError';

import { fetchAllExpSettings } from '@/util/experimentPreFetch';
import appInstallMixin from '@/plugins/app-install-mixin';
import CookieBanner from '@/components/WwwFrame/CookieBanner';
Expand Down Expand Up @@ -68,15 +72,40 @@ export default {
default: '',
},
},
data() {
return {
isKivaAppReferral: false
};
},
apollo: {
preFetch(config, client, args) {
preFetch(config, client, { route }) {
return Promise.all([
client.query({ query: hasEverLoggedInQuery }),
fetchAllExpSettings(config, client, {
query: _get(args, 'route.query'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get refactor

path: _get(args, 'route.path')
query: route?.query,
path: route?.path
}),
client.query({
query: isKivaAppReferralQuery,
variables: {
kivaAppReferralQueryParam: route?.query?.kivaAppReferral,
},
})
]);
},
},
created() {
let referralData = {};
try {
referralData = this.apollo.readQuery({
query: isKivaAppReferralQuery,
variables: {
kivaAppReferralQueryParam: this.$route?.query?.kivaAppReferral,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send this query param as the variable. It is a string. We do the casting from string to Boolean in the local resolver.

},
});
this.isKivaAppReferral = referralData?.isKivaAppReferral || false;
mcstover marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
logReadQueryError(e, 'WwwPage isKivaAppReferralQuery');
}
},
computed: {
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/query/shared/isKivaAppReferral.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query isKivaAppReferral($kivaAppReferralQueryParam: String) {
isKivaAppReferral(kivaAppReferralQueryParam: $kivaAppReferralQueryParam) @client
}