Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs committed Sep 11, 2023
1 parent 4b7fdb6 commit f9f6045
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
3 changes: 1 addition & 2 deletions frontend/src/components/MarksByGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import {
import { getPerformance } from '../methods';
import calculateAverageMark from '../utils/calculateAverageMark';
import { useSnackbar } from '../hooks';

import Mark from './UI/Mark';
import { handleResponse } from '../utils/handleResponse.ts';
import { handleResponse } from '../utils/handleResponse';

const THIRD_SEC = 30 * 1000;

Expand Down
42 changes: 21 additions & 21 deletions frontend/src/components/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MODAL_COLLEGE_INFO } from '../modals/ModalRoot';
import { Organization } from '../../../shared';
import getCollegeInfo from '../methods/server/getCollegeInfo';
import useSnackbar from '../hooks/useSnackbar';
import logOut from '../utils/logOut.ts';
import logOut from '../utils/logOut';

const styles: CSSProperties = {
margin: 0,
Expand Down Expand Up @@ -45,9 +45,9 @@ const getUserAva = async (): Promise<string | null> => {
const UserInfo = () => {
const [snackbar, showSnackbar] = useSnackbar();
const routeNavigator = useRouteNavigator();

const { openCollegeModal } = useModal();

const [isLoading, setIsLoading] = useState<boolean>(false);
const [isCollegeLoading, setIsCollegeLoading] = useState<boolean>(false);
const [userAva, setUserAva] = useState<string | undefined>();
Expand All @@ -56,20 +56,20 @@ const UserInfo = () => {
setIsCollegeLoading(true);
try {
const data = await getCollegeInfo();

if (data === 429) {
useRateLimitExceeded();
return;
}

await routeNavigator.showModal(MODAL_COLLEGE_INFO);
openCollegeModal(data as Organization);
setIsCollegeLoading(false);
} catch (e) {
console.error(e)
console.error(e);
}
}
};

const [userData, setUserData] = useState<UserData>({
firstName: '',
lastName: '',
Expand All @@ -79,15 +79,15 @@ const UserInfo = () => {
city: '',
group: '',
});

const openInvalidData = () => {
showSnackbar({
title: 'Данные устарели',
icon: <Icon32PrometeyCircleFillRed fill='#fff' width={32} height={32} />,
subtitle: 'Через 5 секунд произойдет автоматический выход из аккаунта, поэтому ищите листок с паролем',
});
};

const getUserInfo = async (handle?: boolean) => {
setIsLoading(true);
const localData = localStorage.getItem('userData');
Expand All @@ -103,20 +103,20 @@ const UserInfo = () => {
return;
}
}

const keys = await getVkStorageKeys();
const data = await getVkStorageData(keys);
const extractedData: Partial<UserData> = data.keys.reduce((acc, item) => {
acc[item.key] = item.value;
return acc;
}, {} as UserData);

const ava = await getUserAva();

if (ava) {
setUserAva(ava);
}

setUserData({
firstName: extractedData.firstName || '',
lastName: extractedData.lastName || '',
Expand All @@ -126,16 +126,16 @@ const UserInfo = () => {
city: extractedData.city || '',
group: extractedData.group || '',
});

localStorage.setItem('userData', JSON.stringify(extractedData));

setIsLoading(false);
};

useEffect(() => {
getUserInfo();
}, []);

useEffect(() => {
logoutTimer = setTimeout(() => {
if (userData.firstName === '') {
Expand All @@ -145,22 +145,22 @@ const UserInfo = () => {
}, 5000);
}
}, 5000);

return () => {
if (logoutTimer) {
clearTimeout(logoutTimer);
}
};
}, [userData]);

if (isLoading) {
return (
<Div>
<Spinner />
</Div>
);
}

return (
<Group>
<Gradient mode='tint' style={styles}>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/handleResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ export function handleResponse<T>(
limitExceededCallback();
errorCallback();
loadingCallback(false);
return;
}
}
8 changes: 4 additions & 4 deletions frontend/src/views/Attestation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { useActiveVkuiLocation, useRouteNavigator } from '@vkontakte/vk-mini-app
import getAttestation from '../methods/server/getAttestation';
import { AttestationResponse } from '../../../shared';
import PanelHeaderWithBack from '../components/UI/PanelHeaderWithBack';
import {useRateLimitExceeded} from '../hooks';
import { useRateLimitExceeded } from '../hooks';
import SubjectList from '../components/UI/SubjectsList.tsx';
import {handleResponse} from "../utils/handleResponse.ts";
import { handleResponse } from '../utils/handleResponse.ts';

interface IAttestation {
id: string;
Expand All @@ -27,7 +27,7 @@ const Attestation: FC<IAttestation> = ({ id }) => {
setIsError(false);
try {
const data = await getAttestation();

handleResponse(
data,
() => {
Expand All @@ -43,7 +43,7 @@ const Attestation: FC<IAttestation> = ({ id }) => {
setIsLoading(isLoading);
},
);

setAttestationData(data as AttestationResponse);
} catch (error) {
setIsError(true);
Expand Down

0 comments on commit f9f6045

Please sign in to comment.