-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
템플릿 생성 및 수정시 파일명 랜덤 생성 및 중복호출 막기, 공개 범위 설정 radio UI로 변경 #939
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
511c8b6
refactor(pages): 템플릿 생성 및 수정시 파일명 랜덤 생성 및 중복호출 막기
Hain-tain e8e77f0
refactor(pages): 공개 범위 설정 radio UI로 변경
Hain-tain 8571a69
refactor(src): 중복되는 함수(validateTemplate, generateUniqueFilename) 분리
Hain-tain fbf192b
refactor(pages): 템플릿 설명 입력 UI Textarea로 변경
Hain-tain 30abb18
Merge branch 'dev/fe' of https://github.com/woowacourse-teams/2024-co…
Hain-tain 24317df
fix(api): checkName 이 response return 하도록 변경
Hain-tain 3750cfc
feat(src): Radio 컴포넌트 생성 및 적용
Hain-tain 16632f8
refactor(src): usePreventDuplicateMutation hook 생성 및 적용
Hain-tain 8616347
refactor(TemplateEditPage): 불필요한 try-catch 문 제거
Hain-tain f020b76
refactor(src): Radio에서 options 을 객체로 받아 사용하도록 변경
Hain-tain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -12,10 +12,10 @@ export const postLogin = async (loginInfo: LoginRequest) => { | |
|
||
export const postLogout = async () => await apiClient.post(END_POINTS.LOGOUT, {}); | ||
|
||
export const getLoginState = async () => apiClient.get(END_POINTS.LOGIN_CHECK); | ||
export const getLoginState = async () => await apiClient.get(END_POINTS.LOGIN_CHECK); | ||
|
||
export const checkName = async (name: string) => { | ||
const params = new URLSearchParams({ name }); | ||
|
||
await apiClient.get(`${END_POINTS.CHECK_NAME}?${params.toString()}`); | ||
return await apiClient.get(`${END_POINTS.CHECK_NAME}?${params.toString()}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; |
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,22 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
|
||
import Radio from './Radio'; | ||
|
||
const meta: Meta<typeof Radio> = { | ||
title: 'Radio', | ||
component: Radio, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Radio>; | ||
|
||
export const Default: Story = { | ||
render: () => { | ||
const options = { 코: '코', 드: '드', 잽: '잽' }; | ||
const [currentValue, setCurrentValue] = useState('코'); | ||
|
||
return <Radio options={options} currentValue={currentValue} handleCurrentValue={setCurrentValue} />; | ||
}, | ||
}; |
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 styled from '@emotion/styled'; | ||
|
||
export const RadioContainer = styled.div` | ||
display: flex; | ||
gap: 2rem; | ||
`; | ||
|
||
export const RadioOption = styled.button` | ||
cursor: pointer; | ||
|
||
display: flex; | ||
gap: 1rem; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
export const RadioCircle = styled.div<{ isSelected: boolean }>` | ||
width: 1rem; | ||
height: 1rem; | ||
|
||
background-color: ${({ theme, isSelected }) => | ||
isSelected ? theme.color.light.primary_500 : theme.color.light.secondary_300}; | ||
border: ${({ theme }) => `0.18rem solid ${theme.color.light.secondary_300}`}; | ||
border-radius: 100%; | ||
`; |
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 { Text } from '@/components'; | ||
import { theme } from '@/style/theme'; | ||
|
||
import * as S from './Radio.style'; | ||
|
||
interface Props<T extends string> { | ||
options: Record<T, T | string | number>; | ||
currentValue: T; | ||
handleCurrentValue: (value: T) => void; | ||
} | ||
|
||
const Radio = <T extends string>({ options, currentValue, handleCurrentValue }: Props<T>) => ( | ||
<S.RadioContainer> | ||
{Object.keys(options).map((optionKey) => ( | ||
<S.RadioOption key={optionKey} onClick={() => handleCurrentValue(optionKey as T)}> | ||
<S.RadioCircle isSelected={currentValue === optionKey} /> | ||
<Text.Medium color={theme.color.light.secondary_800}>{options[optionKey as T]}</Text.Medium> | ||
</S.RadioOption> | ||
))} | ||
</S.RadioContainer> | ||
); | ||
|
||
export default Radio; |
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,38 @@ | ||
import { useMutation, UseMutationOptions, UseMutationResult, MutationFunction } from '@tanstack/react-query'; | ||
import { useRef } from 'react'; | ||
|
||
type RequiredMutationFn<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = UseMutationOptions< | ||
TData, | ||
TError, | ||
TVariables, | ||
TContext | ||
> & { | ||
mutationFn: MutationFunction<TData, TVariables>; | ||
}; | ||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mutationFn 을 반드시 전달하도록 타입으로 강제하기위해 이렇게 설정해주었습니다! |
||
|
||
export const usePreventDuplicateMutation = <TData = unknown, TError = Error, TVariables = void, TContext = unknown>( | ||
options: RequiredMutationFn<TData, TError, TVariables, TContext>, | ||
): UseMutationResult<TData, TError, TVariables, TContext> => { | ||
const isMutatingRef = useRef(false); | ||
|
||
const originalMutationFn = options.mutationFn; | ||
|
||
const preventDuplicateMutationFn: MutationFunction<TData, TVariables> = async (variables: TVariables) => { | ||
if (isMutatingRef.current) { | ||
return undefined as TData; | ||
} | ||
|
||
isMutatingRef.current = true; | ||
|
||
try { | ||
return await originalMutationFn(variables); | ||
} finally { | ||
isMutatingRef.current = false; | ||
} | ||
}; | ||
|
||
return useMutation({ | ||
...options, | ||
mutationFn: preventDuplicateMutationFn, | ||
}); | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번에
Radio
컴포넌트에서 ThemeProvider theme을 사용하여서 추가하게 되었습니다