-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from kakao-tech-campus-2nd-step3/weekly/10th-week
Weekly/10th week
- Loading branch information
Showing
55 changed files
with
1,481 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,13 @@ | |
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<link rel="preload" as="style" crossorigin | ||
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-dynamic-subset.min.css" /> | ||
<link rel="stylesheet" crossorigin | ||
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-dynamic-subset.min.css" /> | ||
<link rel="stylesheet" href='/index.css' /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
<title>Ditto</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:root { | ||
font-family: 'Pretendard', sans-serif; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import endpoints from '@constants/endpoints'; | ||
import { StudySearchRequestQuery, StudySearchResponse } from '@/types/study'; | ||
import axiosInstance from '@/utils/network'; | ||
|
||
export async function searchStudies(requestQuery: StudySearchRequestQuery) { | ||
const response = await axiosInstance.get<StudySearchResponse>(endpoints.searchStudy, { | ||
params: requestQuery, | ||
}); | ||
return response.data; | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Component, ReactNode } from 'react'; | ||
import { isAxiosError } from 'axios'; | ||
import { | ||
defaultErrorMessage, defaultFetchErrorMessage, | ||
fetchErrorMessages, | ||
} from '@constants/errorMessages'; | ||
import Container from '@components/container'; | ||
|
||
interface FetchErrorBoundaryProps { | ||
children?: ReactNode; | ||
fallback?: ReactNode; | ||
} | ||
|
||
interface FetchErrorBoundaryState { | ||
hasError: boolean; | ||
errorMessage?: string; | ||
} | ||
|
||
class ErrorBoundary extends Component<FetchErrorBoundaryProps, FetchErrorBoundaryState> { | ||
constructor(props: FetchErrorBoundaryProps) { | ||
super(props); | ||
this.state = { | ||
hasError: false, | ||
errorMessage: undefined, | ||
}; | ||
} | ||
|
||
componentDidCatch(error: Error) { | ||
console.error(error); | ||
} | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
if (!isAxiosError(error)) { | ||
return { | ||
hasError: true, | ||
errorMessage: defaultErrorMessage, | ||
}; | ||
} | ||
const errorStatus = error.response?.status; | ||
const errorMessage = !errorStatus || !(errorStatus in fetchErrorMessages) | ||
? defaultFetchErrorMessage | ||
: fetchErrorMessages[errorStatus]; | ||
return { | ||
hasError: true, | ||
errorMessage, | ||
}; | ||
} | ||
|
||
render() { | ||
const { props, state } = this; | ||
const fallback = props.fallback || <Container>{state.errorMessage}</Container>; | ||
return state.hasError ? fallback : props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ReactNode, Suspense } from 'react'; | ||
import ErrorBoundary from '@components/boundary/ErrorBoundary'; | ||
import Spinner from '@components/fallback/Spinner'; | ||
|
||
interface SuspenseErrorBoundaryProps { | ||
suspenseFallback?: ReactNode; | ||
errorFallback?: ReactNode; | ||
children?: ReactNode; | ||
} | ||
|
||
function SuspenseErrorBoundary({ | ||
suspenseFallback, | ||
errorFallback, | ||
children, | ||
}: SuspenseErrorBoundaryProps) { | ||
return ( | ||
<ErrorBoundary fallback={errorFallback}> | ||
<Suspense fallback={suspenseFallback || <Spinner />}> | ||
{children} | ||
</Suspense> | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
export default SuspenseErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { css } from '@emotion/react'; | ||
import type { ContainerProps } from '@components/container/index'; | ||
|
||
function useContainerStyle({ | ||
direction, justify, align, width, height, gap, padding, boxSizing, | ||
}: ContainerProps) { | ||
const containerStyle = css` | ||
display: flex; | ||
flex-direction: ${direction || 'row'}; | ||
justify-content: ${justify || 'center'}; | ||
align-items: ${align || 'center'}; | ||
width: ${width || '100%'}; | ||
height: ${height || 'auto'}; | ||
gap: ${gap || '0'}; | ||
padding: ${padding || '0'}; | ||
box-sizing: ${boxSizing || 'border-box'}; | ||
`; | ||
return { | ||
containerStyle, | ||
}; | ||
} | ||
|
||
export default useContainerStyle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import Spinner from '@components/fallback/Spinner'; | ||
|
||
const meta: Meta<typeof Spinner> = { | ||
title: 'Components/Spinner', | ||
component: Spinner, | ||
argTypes: { | ||
wrapperCss: { control: 'object' }, | ||
circleCss: { control: 'object' }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Spinner>; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css, keyframes, useTheme } from '@emotion/react'; | ||
import Container from '@components/container'; | ||
import { Paragraph } from '@components/text'; | ||
|
||
const spin = keyframes` | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
`; | ||
|
||
function Spinner() { | ||
const theme = useTheme(); | ||
const spinnerStyle = css` | ||
width: 30px; | ||
height: 30px; | ||
border: 5px solid ${theme.colors.border.subtle}; | ||
border-top: 5px solid ${theme.colors.primary.main}; | ||
border-radius: 50%; | ||
margin-bottom: 15px; | ||
animation: ${spin} 1s cubic-bezier(0.42, 0, 0.58, 1) infinite; | ||
`; | ||
return ( | ||
<Container direction="column"> | ||
<div css={spinnerStyle} /> | ||
<Paragraph variant="small" color={theme.colors.text.moderate}>로드 중</Paragraph> | ||
</Container> | ||
); | ||
} | ||
|
||
export default Spinner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ReactNode } from 'react'; | ||
import { CSSObject, useTheme } from '@emotion/react'; | ||
|
||
interface SpanProps { | ||
children?: ReactNode; | ||
css?: CSSObject; | ||
} | ||
|
||
export function PrimarySpan({ children, css }: SpanProps) { | ||
const theme = useTheme(); | ||
return <span css={[{ color: theme.colors.primary.main }, css]}>{children}</span>; | ||
} |
Oops, something went wrong.