Skip to content

Commit

Permalink
feat: add loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pmh-only committed Aug 20, 2023
1 parent 6844699 commit 7195562
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const Button = styled.button`
cursor: pointer;
border-radius: 2px;
font-weight: 900;
&:disabled {
opacity: 0.5;
}
`

export default Button
7 changes: 6 additions & 1 deletion src/components/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {

const CreateModal: FC<Props> = ({ display, action }) => {
const { refresh } = useRefreshNotifier()
const [isLoading, setIsLoading] = useState(false)
const [, updateState] = useState<any>()
const forceUpdate = useCallback(() => { updateState({}) }, [])
const [price, setPrice] = useState(0)
Expand Down Expand Up @@ -62,6 +63,9 @@ const CreateModal: FC<Props> = ({ display, action }) => {
}

async function create (): Promise<void> {
if (isLoading) return
setIsLoading(true)

forceUpdate()
await axios('/api/instances', {
method: 'POST',
Expand All @@ -81,6 +85,7 @@ const CreateModal: FC<Props> = ({ display, action }) => {
})

refresh()
setIsLoading(false)
action(false)
}

Expand Down Expand Up @@ -145,7 +150,7 @@ const CreateModal: FC<Props> = ({ display, action }) => {
</div>
<Bottom>
<h1 style={{ marginRight: '10px' }}>예상 금액: {(price + storage * 0.1).toFixed(2)}$/월</h1>
<Button style={{ backgroundColor: '#ff9900' }} onClick={() => { void create() }}>생성</Button>
<Button disabled={isLoading} style={{ backgroundColor: '#ff9900' }} onClick={() => { void create() }}>{isLoading ? '생성중' : '생성'}</Button>
</Bottom>
</Form>
</Modal>
Expand Down
14 changes: 10 additions & 4 deletions src/components/SocketWatcher/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ const SocketWatcher: FC = () => {
})

socket.on('message', (data) => {
toast(() => (
<Alert type={data.type.toLowerCase()}>
{data.message}
</Alert>
toast.custom((t) => (
<div style={{
opacity: t.visible ? 1 : 0,
transition: 'opacity 100ms ease-in-out'
}}>
<Alert type={data.type.toLowerCase()}>
{data.message}
{data?.error}
</Alert>
</div>
))

refresh()
Expand Down
10 changes: 9 additions & 1 deletion src/components/TopNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ const TopNav: FC = () => {
</div>

<div>
<button className={style.logout} onClick={onLogout}>
<a className={style.text} href="https://aws.gbsw.hs.kr" target="_blank" rel="noreferrer">
메뉴얼
</a>

<a className={style.text} href="https://github.com/GBSWHS" target="_blank" rel="noreferrer">
개발자
</a>

<button className={style.text} onClick={onLogout}>
로그아웃
</button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/TopNav/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@
}
}

.logout {
.text {
background-color: transparent;
border: none;
color: white;
cursor: pointer;
height: auto;
word-break: keep-all;
text-decoration: underline dashed rgb(135, 149, 150);

&:hover {
Expand Down
7 changes: 6 additions & 1 deletion src/components/UpdateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
}

const UpdateModal: FC<Props> = ({ display, booleanAction, instance, instanceAction, uuid }) => {
const [isLoading, setIsLoading] = useState(false)
const [, updateState] = useState<any>()
const forceUpdate = useCallback(() => { updateState({}) }, [])
const { refresh } = useRefreshNotifier()
Expand Down Expand Up @@ -50,6 +51,9 @@ const UpdateModal: FC<Props> = ({ display, booleanAction, instance, instanceActi
}

async function update (): Promise<void> {
if (isLoading) return
setIsLoading(true)

forceUpdate()
await axios(`/api/instances/${uuid}`, {
method: 'PUT',
Expand All @@ -70,6 +74,7 @@ const UpdateModal: FC<Props> = ({ display, booleanAction, instance, instanceActi

refresh()
booleanAction(false)
setIsLoading(false)
}

return (
Expand Down Expand Up @@ -131,7 +136,7 @@ const UpdateModal: FC<Props> = ({ display, booleanAction, instance, instanceActi
</div>
<Bottom>
<h1 style={{ marginRight: '10px' }}>예상 금액: {(price + storage * 0.1).toFixed(2)}$/월</h1>
<Button style={{ backgroundColor: '#ff9900' }} onClick={() => { void update() }}>{isIpChange ? '수정 후 재시작' : '수정'}</Button>
<Button style={{ backgroundColor: '#ff9900' }} onClick={() => { void update() }}>{isLoading ? '수정중.' : (isIpChange ? '수정 후 재시작' : '수정')}</Button>
</Bottom>
</Form>
</Modal>
Expand Down

0 comments on commit 7195562

Please sign in to comment.