Skip to content

Commit

Permalink
fix localstorage listener
Browse files Browse the repository at this point in the history
  • Loading branch information
SixStringer91 committed Oct 6, 2022
1 parent 20adc5f commit 7b25716
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ui/front/src/apps/web/components/app.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { useDispatch } from '@libs/redux';
import OnboardingStep from '@components/shared/git-auth/onboarding/onboardingStep';
import { Popup } from '@components/shared/popup';
import { AchievementList } from '@components/shared/achievments';
import ReferralProgramm from '@components/shared/referral-programm/referralProgramm';
import { Footer } from './footer';
import styles from './app.module.scss';
import { Lendos } from './lendos';
import { Header } from './header';
import { routesData } from './routes';
import ReferralProgramm from "@components/shared/referral-programm/referralProgramm";

function Main() {
const { isApiConnected, isOnLending, connectBeamApi } = useWebMain();
Expand Down Expand Up @@ -113,8 +113,8 @@ function Main() {
element={<OnboardingStep />}
/>
<Route
path="/referral-programm"
element={<ReferralProgramm />}
path="/referral-programm"
element={<ReferralProgramm />}
/>
<Route
path="/download"
Expand Down
7 changes: 4 additions & 3 deletions ui/front/src/components/shared/git-auth/LoginSocialGithub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable @typescript-eslint/no-shadow */
import { notification } from 'antd';
import { NotificationPlacement } from 'antd/lib/notification';
import React, {
memo, useCallback, useEffect, useState
} from 'react';
Expand Down Expand Up @@ -39,7 +41,6 @@ export function LoginSocialGithub({
redirect_uri,
allow_signup = false,
children,
onReject,
onResolve
}: Props) {
const [isProcessing, setIsProcessing] = useState(false);
Expand All @@ -65,18 +66,18 @@ export function LoginSocialGithub({
&& getAccessToken(code);

const onChangeLocalStorage = () => {
window.removeEventListener('storage', onChangeLocalStorage, false);
const code = localStorage.getItem('github');
if (code) {
setIsProcessing(true);
handlePostMessage({ provider: 'github', type: 'code', code });
localStorage.removeItem('instagram');
window.removeEventListener('storage', onChangeLocalStorage);
}
};

const onLogin = () => {
if (!isProcessing) {
window.addEventListener('storage', onChangeLocalStorage, false);
window.addEventListener('storage', onChangeLocalStorage);
const oauthUrl = `
${GITHUB_URL}/login/oauth/authorize?client_id=${client_id}&scope=${encodeURIComponent(scope)}&state=_github&allow_signup=${allow_signup}&redirect_uri=${encodeURIComponent(redirect_uri)}`;

Expand Down
11 changes: 10 additions & 1 deletion ui/front/src/components/shared/git-auth/git-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AC } from '@libs/action-creators';
import { HOST } from '@components/shared/git-auth/profile/constants';
import { useNavigate } from 'react-router-dom';
import { getQueryParam } from '@libs/utils';
import { notification } from 'antd';
import { NotificationPlacement } from 'antd/lib/notification';
import { NavButton } from '../nav-button';
import styles from './git-auth.module.scss';
import { Popup } from '../popup';
Expand Down Expand Up @@ -69,15 +71,22 @@ function GitConnectAuth({ name, small, why }:GitConnectAuthProps) {
.catch(() => {
setVisible(false);
setIsErr(true);
notification.error({
message: 'connection failed',
placement: 'bottomRight' as NotificationPlacement
});
});
setIsDisabled(true);
})
.catch(() => {
setVisible(false);
setIsErr(true);
notification.error({
message: 'connection failed',
placement: 'bottomRight' as NotificationPlacement
});
});
}}
onReject={({ data }) => console.log(data)}
scope="read:user user:email repo"
>
<NavButton
Expand Down
1 change: 1 addition & 0 deletions ui/front/src/libs/redux/reducers/profiles.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const reducer = (
}
case ACTIONS.GIT_USER_LOGOUT: {
newState.data = defaultValue;
localStorage.clear();
return newState;
}
default:
Expand Down

0 comments on commit 7b25716

Please sign in to comment.