Skip to content

Commit

Permalink
refactore: wip 타입스트립트로 마이그레이션
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin committed Dec 25, 2023
1 parent 5b771c0 commit 5f9bdaa
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 21 deletions.
10 changes: 10 additions & 0 deletions @types/emotion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '@emotion/react';

import { lightTheme } from '../src/styles/theme';

declare module '@emotion/react' {
type CustomTheme = typeof lightTheme;

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends CustomTheme {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSnackbar } from 'notistack';

import authResultAtom from '../../recoil/auth';
import userAtom from '../../recoil/user';
import { AuthResultAtomType } from 'src/recoil/auth/atom';

function AuthStatusSnackbar() {
const [{ authSuccess, authError }, setAuthState] = useRecoilState(authResultAtom);
Expand All @@ -14,7 +15,7 @@ function AuthStatusSnackbar() {

const { enqueueSnackbar } = useSnackbar();

const resetState = (state) => setAuthState((prevState) => ({
const resetState = (state: Partial<AuthResultAtomType>) => setAuthState((prevState) => ({
...prevState,
...state,
}));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useRecoilState } from 'recoil';

import { useSnackbar } from 'notistack';

import todosResultAtom from '../../recoil/todos/atom';
import todosResultAtom, { TodosResultAtomType } from '../../recoil/todos/atom';

function TodoStatusSnackbar() {
const [{ todoError, todoSuccess }, setTodoState] = useRecoilState(todosResultAtom);

const { enqueueSnackbar } = useSnackbar();

const resetState = (state) => setTodoState((prevState) => ({
const resetState = (state: Partial<TodosResultAtomType>) => setTodoState((prevState) => ({
...prevState,
...state,
}));
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/ToggleThemeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const ThemeButtonWrapper = styled.div`
})};
display: flex;
justify-content: flex-end;
justify-content: flex-end;
`;

function ToggleThemeButton() {
const [theme, setTheme] = useRecoilState(themeWithChange);

const handleToggle = useCallback(() => setTheme(), [setTheme]);
const handleToggle = useCallback(() => setTheme(), []);

return (
<ThemeButtonWrapper>
Expand Down
11 changes: 0 additions & 11 deletions src/components/footer/ExternalLink.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { render } from '@testing-library/react';
import ExternalLink from './ExternalLink';

describe('Link', () => {
const renderLink = (url) => render((
const renderLink = (url: string) => render((
<ExternalLink
link={url}
>
Expand Down
15 changes: 15 additions & 0 deletions src/components/footer/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { PropsWithChildren } from 'react';

type Props = {
link: string;
};

function ExternalLink({ children, link }: PropsWithChildren<Props>) {
return (
<a href={link} target="_blank" rel="noopener noreferrer">
{children}
</a>
);
}

export default ExternalLink;
File renamed without changes.
File renamed without changes.
8 changes: 7 additions & 1 deletion src/recoil/auth/atom.js → src/recoil/auth/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { atom } from 'recoil';

import { AUTH_FORM_STATUS_ATOM_KEY, AUTH_RESULT_ATOM_KEY } from '../../utils/constants/atomKey';

export type AuthResultAtomType = {
auth: any;
authError: null | string;
authSuccess: null | string;
};

export const authFormStatusAtom = atom({
key: AUTH_FORM_STATUS_ATOM_KEY,
default: {
Expand All @@ -10,7 +16,7 @@ export const authFormStatusAtom = atom({
},
});

const authResultAtom = atom({
const authResultAtom = atom<AuthResultAtomType>({
key: AUTH_RESULT_ATOM_KEY,
default: {
auth: null,
Expand Down
File renamed without changes.
14 changes: 13 additions & 1 deletion src/recoil/todos/atom.js → src/recoil/todos/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import { atom } from 'recoil';

import { FILTER_ATOM_KEY, TODOS_RESULT_ATOM_KEY } from '../../utils/constants/atomKey';

type Todo = {
_id: string;
task: string;
isComplete: boolean;
};

export type TodosResultAtomType = {
todos: Todo[];
todoError: null | string;
todoSuccess: null | string;
};

export const filterAtom = atom({
key: FILTER_ATOM_KEY,
default: 'ALL',
});

const todosResultAtom = atom({
const todosResultAtom = atom<TodosResultAtomType>({
key: TODOS_RESULT_ATOM_KEY,
default: {
todos: [],
Expand Down
4 changes: 2 additions & 2 deletions src/styles/theme.js → src/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const lightTheme = {
'#868e96',
'#495057',
],
};
} as const;

export const darkTheme = {
baseTone: '#6A7BA2',
Expand All @@ -44,4 +44,4 @@ export const darkTheme = {
'#495057',
'#868e96',
],
};
} as const;

0 comments on commit 5f9bdaa

Please sign in to comment.