Skip to content

Commit

Permalink
Merge pull request #353 from boostcampwm-2022/develop
Browse files Browse the repository at this point in the history
v0.2.9 배포
  • Loading branch information
Yaminyam authored Dec 31, 2022
2 parents 4bb64f7 + 03bfb08 commit 589f192
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ dist

# TernJS port file
.tern-port

# storybook
storybook-static
10 changes: 9 additions & 1 deletion backend/libs/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const MINUTE = 60;
const HOUR = 60 * MINUTE;
export const HOUR = 60 * MINUTE;

export const DAY = 24 * HOUR;

export const WEEK = 7 * DAY;

export const MONTH = 30 * DAY;

export const YEAR = 365 * DAY;

export const EXPIRATION = {
ACCESS_TOKEN: 600,
Expand Down
4 changes: 3 additions & 1 deletion backend/src/user/utils/query.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { YEAR } from '@libs/consts';

export const pinnedRepositoriesQuery = `query pinnedReposities($username: String!) {
user(login: $username) {
organizations(first:100) {
Expand Down Expand Up @@ -110,7 +112,7 @@ export const forkRepositoryQuery = `query repositories($username: String!, $id:
defaultBranchRef {
target {
... on Commit {
history(author: {id: $id}, first: 100) {
history(author: {id: $id}, since: "${new Date(new Date().getTime() - 3 * YEAR * 1000).toISOString()}") {
nodes {
committedDate
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Trans } from 'next-i18next';
import Image from 'next/image';
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import styled, { keyframes } from 'styled-components';
import { useInterval } from '@hooks/useInterval';

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

useInterval(() => {
setCount(count - 1);
}, 1000);
const countDown = useCallback(() => setCount((prev) => prev - 1), []);

useInterval(countDown, 1000, count > 0);

useEffect(() => {
setCount(updateDelayTime);
Expand Down
25 changes: 8 additions & 17 deletions frontend/src/hooks/useInterval.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import { useEffect, useRef } from 'react';
import { useEffect } from 'react';

interface CallbackType {
(): void;
}

export function useInterval(callback: CallbackType, delay: number) {
const savedCallback = useRef<CallbackType>();

export function useInterval(callback: CallbackType, delay: number, isActivate: boolean) {
useEffect(() => {
if (callback) {
savedCallback.current = callback;
}
}, [callback]);
if (!isActivate) return;

useEffect(() => {
function tick() {
if (savedCallback.current) {
savedCallback.current();
}
}
const id = setInterval(callback, delay);

const id = setInterval(tick, delay);
return () => clearInterval(id);
}, [delay]);
return () => {
clearInterval(id);
};
}, [callback, delay, isActivate]);
}
13 changes: 12 additions & 1 deletion frontend/src/pages/profile/[username].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GetServerSideProps } from 'next';
import { useTranslation } from 'next-i18next';
import Image from 'next/image';
import { AxiosError } from 'axios';
import { useEffect } from 'react';
import styled from 'styled-components';
import { useQueryData } from '@hooks';
Expand Down Expand Up @@ -29,10 +30,20 @@ function Profile({ username }: ProfileProps) {

const { mutate, isLoading } = useMutation<ProfileUserResponse>({
mutationFn: () => requestUserInfoByUsername({ username, method: 'PATCH' }),
onError: () => alert('최근에 업데이트 했습니다.'),
onError: (err) => updateErrorHandler(err),
onSettled: () => refetch(),
});

const { t } = useTranslation(['profile', 'meta']);
const updateErrorHandler = (err: unknown) => {
if (err instanceof AxiosError && err.response) {
if (err.response.status >= 500) {
alert('정보를 불러올 수 없는 유저입니다.');
} else if (err.response.status >= 400) {
alert('최근에 업데이트 했습니다. 잠시 후 다시 시도해주세요.');
}
}
};

useEffect(() => {
requestTokenRefresh();
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utils/axiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ instance.interceptors.response.use(
}
}
}

if (originConfig.url.startsWith('/users/') && originConfig.method === 'patch') {
return Promise.reject(err);
}
},
);

Expand Down

0 comments on commit 589f192

Please sign in to comment.