Skip to content

Commit 589f192

Browse files
authored
Merge pull request #353 from boostcampwm-2022/develop
v0.2.9 배포
2 parents 4bb64f7 + 03bfb08 commit 589f192

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ dist
104104

105105
# TernJS port file
106106
.tern-port
107+
108+
# storybook
109+
storybook-static

backend/libs/consts/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
const MINUTE = 60;
2-
const HOUR = 60 * MINUTE;
2+
export const HOUR = 60 * MINUTE;
3+
4+
export const DAY = 24 * HOUR;
5+
6+
export const WEEK = 7 * DAY;
7+
8+
export const MONTH = 30 * DAY;
9+
10+
export const YEAR = 365 * DAY;
311

412
export const EXPIRATION = {
513
ACCESS_TOKEN: 600,

backend/src/user/utils/query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { YEAR } from '@libs/consts';
2+
13
export const pinnedRepositoriesQuery = `query pinnedReposities($username: String!) {
24
user(login: $username) {
35
organizations(first:100) {
@@ -110,7 +112,7 @@ export const forkRepositoryQuery = `query repositories($username: String!, $id:
110112
defaultBranchRef {
111113
target {
112114
... on Commit {
113-
history(author: {id: $id}, first: 100) {
115+
history(author: {id: $id}, since: "${new Date(new Date().getTime() - 3 * YEAR * 1000).toISOString()}") {
114116
nodes {
115117
committedDate
116118
}

frontend/src/components/Profile/ProfileRefreshButton/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Trans } from 'next-i18next';
22
import Image from 'next/image';
3-
import React, { useEffect, useState } from 'react';
3+
import React, { useCallback, useEffect, useState } from 'react';
44
import styled, { keyframes } from 'styled-components';
55
import { useInterval } from '@hooks/useInterval';
66

@@ -13,9 +13,9 @@ interface ProfileRefreshButtonProps {
1313
function ProfileRefreshButton({ updateDelayTime, updateData, isLoading, isMine }: ProfileRefreshButtonProps) {
1414
const [count, setCount] = useState(updateDelayTime);
1515

16-
useInterval(() => {
17-
setCount(count - 1);
18-
}, 1000);
16+
const countDown = useCallback(() => setCount((prev) => prev - 1), []);
17+
18+
useInterval(countDown, 1000, count > 0);
1919

2020
useEffect(() => {
2121
setCount(updateDelayTime);

frontend/src/hooks/useInterval.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
import { useEffect, useRef } from 'react';
1+
import { useEffect } from 'react';
22

33
interface CallbackType {
44
(): void;
55
}
66

7-
export function useInterval(callback: CallbackType, delay: number) {
8-
const savedCallback = useRef<CallbackType>();
9-
7+
export function useInterval(callback: CallbackType, delay: number, isActivate: boolean) {
108
useEffect(() => {
11-
if (callback) {
12-
savedCallback.current = callback;
13-
}
14-
}, [callback]);
9+
if (!isActivate) return;
1510

16-
useEffect(() => {
17-
function tick() {
18-
if (savedCallback.current) {
19-
savedCallback.current();
20-
}
21-
}
11+
const id = setInterval(callback, delay);
2212

23-
const id = setInterval(tick, delay);
24-
return () => clearInterval(id);
25-
}, [delay]);
13+
return () => {
14+
clearInterval(id);
15+
};
16+
}, [callback, delay, isActivate]);
2617
}

frontend/src/pages/profile/[username].tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { GetServerSideProps } from 'next';
22
import { useTranslation } from 'next-i18next';
33
import Image from 'next/image';
4+
import { AxiosError } from 'axios';
45
import { useEffect } from 'react';
56
import styled from 'styled-components';
67
import { useQueryData } from '@hooks';
@@ -29,10 +30,20 @@ function Profile({ username }: ProfileProps) {
2930

3031
const { mutate, isLoading } = useMutation<ProfileUserResponse>({
3132
mutationFn: () => requestUserInfoByUsername({ username, method: 'PATCH' }),
32-
onError: () => alert('최근에 업데이트 했습니다.'),
33+
onError: (err) => updateErrorHandler(err),
3334
onSettled: () => refetch(),
3435
});
36+
3537
const { t } = useTranslation(['profile', 'meta']);
38+
const updateErrorHandler = (err: unknown) => {
39+
if (err instanceof AxiosError && err.response) {
40+
if (err.response.status >= 500) {
41+
alert('정보를 불러올 수 없는 유저입니다.');
42+
} else if (err.response.status >= 400) {
43+
alert('최근에 업데이트 했습니다. 잠시 후 다시 시도해주세요.');
44+
}
45+
}
46+
};
3647

3748
useEffect(() => {
3849
requestTokenRefresh();

frontend/src/utils/axiosInstance.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ instance.interceptors.response.use(
3434
}
3535
}
3636
}
37+
38+
if (originConfig.url.startsWith('/users/') && originConfig.method === 'patch') {
39+
return Promise.reject(err);
40+
}
3741
},
3842
);
3943

0 commit comments

Comments
 (0)