Skip to content

Commit

Permalink
[LandingPage] reuse useCurrentUser in LandingPage
Browse files Browse the repository at this point in the history
which will push user id to gtm dataLayer properly
  • Loading branch information
MrOrz committed Jul 13, 2022
1 parent b2432e2 commit 16ccf15
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions components/LandingPage/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useEffect, useState } from 'react';
import gql from 'graphql-tag';
import { c, t } from 'ttag';
import cx from 'clsx';
import { useQuery, useLazyQuery } from '@apollo/react-hooks';
import { useQuery } from '@apollo/react-hooks';
import { useRouter } from 'next/router';
import { makeStyles, withStyles, useTheme } from '@material-ui/core/styles';
import useMediaQuery from '@material-ui/core/useMediaQuery';
import Badge from '@material-ui/core/Badge';
import { animated, useSpring } from 'react-spring';
import Link from 'next/link';
import Avatar from 'components/AppLayout/Widgets/Avatar';

import useCurrentUser from 'lib/useCurrentUser';
import NavLink from 'components/NavLink';
import * as Widgets from 'components/AppLayout/Widgets';

Expand All @@ -33,17 +33,6 @@ const LIST_UNSOLVED_ARTICLES = gql`
}
`;

const USER_QUERY = gql`
query UserLevelQuery {
GetUser {
id
name
...AvatarData
}
}
${Avatar.fragments.AvatarData}
`;

const CustomBadge = withStyles(theme => ({
root: {
verticalAlign: 'baseline' /* override badge default */,
Expand Down Expand Up @@ -167,8 +156,7 @@ const LandingPageHeader = React.memo(({ onLoginModalOpen }) => {

const [isMobileMenuOpen, setMobileMenuOpen] = useState(false);

const [loadUser, { data: userData }] = useLazyQuery(USER_QUERY);
const user = userData?.GetUser;
const user = useCurrentUser();

const { data } = useQuery(LIST_UNSOLVED_ARTICLES, {
ssr: false, // no number needed for SSR
Expand Down Expand Up @@ -198,9 +186,6 @@ const LandingPageHeader = React.memo(({ onLoginModalOpen }) => {
}
};

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => loadUser(), []);

useEffect(() => {
handleScroll();
window.addEventListener('scroll', handleScroll);
Expand Down

0 comments on commit 16ccf15

Please sign in to comment.