-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
템플릿 생성 및 수정시 파일명 랜덤 생성 및 중복호출 막기, 공개 범위 설정 radio UI로 변경 (#939)
- Loading branch information
Showing
18 changed files
with
310 additions
and
158 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
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>; | ||
}; | ||
|
||
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.