-
Notifications
You must be signed in to change notification settings - Fork 3
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 #16 from ananjaemin/4-api-page-개발
4 api page 개발
- Loading branch information
Showing
15 changed files
with
292 additions
and
56 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
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,64 @@ | ||
import styled from '@emotion/styled'; | ||
export const SkeletonUIBox = styled.div<{ randomWitdh: string }>` | ||
display: flex; | ||
background-color: var(--color-backgorund-filelistbox); | ||
border-radius: 10px; | ||
margin-bottom: 1.5rem; | ||
min-height: 4.6rem; | ||
min-width: ${(props) => props.randomWitdh}rem; | ||
overflow: hidden; | ||
&::before { | ||
content: ' '; | ||
width: 100%; | ||
height: auto; | ||
animation: loading 2s infinite; | ||
box-shadow: 0 0 30px 30px rgba(255, 255, 255, 0.3); | ||
} | ||
@keyframes loading { | ||
0% { | ||
transform: translateX(-50%); | ||
} | ||
50% { | ||
transform: translateX(100%); | ||
} | ||
100% { | ||
transform: translate(200%); | ||
} | ||
} | ||
`; | ||
export const SkeletonUIApiBox = styled(SkeletonUIBox)` | ||
min-height: 6.2rem; | ||
margin: 1rem; | ||
`; | ||
|
||
export const SkeletonUI = styled.div<{ | ||
width: string; | ||
height: string; | ||
margin: string; | ||
}>` | ||
display: flex; | ||
min-width: ${(props) => props.width}; | ||
min-height: ${(props) => props.height}; | ||
margin: ${(props) => props.margin}; | ||
background: var(--color-backgorund-filelistbox); | ||
border-radius: 10px; | ||
overflow: hidden; | ||
&::before { | ||
content: ' '; | ||
width: 100%; | ||
height: auto; | ||
animation: loading 2s infinite; | ||
box-shadow: 0 0 30px 30px rgba(255, 255, 255, 0.3); | ||
} | ||
@keyframes loading { | ||
0% { | ||
transform: translateX(-50%); | ||
} | ||
50% { | ||
transform: translateX(100%); | ||
} | ||
100% { | ||
transform: translate(200%); | ||
} | ||
} | ||
`; |
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,71 @@ | ||
import axios from 'axios'; | ||
import React, { useState, useEffect } from 'react'; | ||
import { Route, Routes, Link } from 'react-router-dom'; | ||
|
||
import { SkeletonUIApiBox } from '../../components'; | ||
import { ApiPostPage } from '../postApi'; | ||
import * as S from './styled'; | ||
|
||
export const ApiPage: React.FC = () => { | ||
const [loading, setLoading] = useState(false); | ||
const [apiInfo, setApiInfo] = useState<any[]>(); | ||
const SkeletonUIRandomWidth = ['40', '50', '55', '45']; | ||
const getApiInfo = async () => { | ||
await axios({ | ||
method: 'get', | ||
url: 'https://tfb.minpeter.cf/info', | ||
}).then((res) => { | ||
console.log(res.data); | ||
setApiInfo(res.data); | ||
setTimeout(() => { | ||
setLoading(true); //loading 확인하고싶으면 false로 바꿔주세요. | ||
}, 1200); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
getApiInfo(); | ||
}, []); | ||
|
||
return ( | ||
<S.ApiPageContainer> | ||
<Routes> | ||
<Route | ||
path="/" | ||
element={ | ||
<> | ||
<S.ApiListSection> | ||
{loading ? ( | ||
<> | ||
{apiInfo?.map((item, index) => ( | ||
<Link key={index} to={item.apiHandler} style={{ textDecoration: 'none' }}> | ||
<S.ApiListBox>{item.apiUrl}</S.ApiListBox> | ||
</Link> | ||
))} | ||
</> | ||
) : ( | ||
<> | ||
<SkeletonUIApiBox | ||
randomWitdh={SkeletonUIRandomWidth[Math.floor(Math.random() * 4)]} | ||
/> | ||
<SkeletonUIApiBox | ||
randomWitdh={SkeletonUIRandomWidth[Math.floor(Math.random() * 4)]} | ||
/> | ||
<SkeletonUIApiBox | ||
randomWitdh={SkeletonUIRandomWidth[Math.floor(Math.random() * 4)]} | ||
/> | ||
<SkeletonUIApiBox | ||
randomWitdh={SkeletonUIRandomWidth[Math.floor(Math.random() * 4)]} | ||
/> | ||
</> | ||
)} | ||
</S.ApiListSection> | ||
<S.ApiListSectionShadow /> | ||
</> | ||
} | ||
/> | ||
<Route path=":urlApi" element={<ApiPostPage />} /> | ||
</Routes> | ||
</S.ApiPageContainer> | ||
); | ||
}; |
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,40 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const ApiPageContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
`; | ||
|
||
export const ApiListSection = styled.div` | ||
overflow-y: auto; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
max-height: 40rem; | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
export const ApiListBox = styled.div` | ||
background-color: var(--color-backgorund-filelistbox); | ||
color: var(--color-text-tertiary); | ||
border-radius: 10px; | ||
padding: 2rem 1.4rem 2rem 1.4rem; | ||
margin: 1rem; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
font-size: 2.2rem; | ||
font-weight: 700; | ||
cursor: pointer; | ||
`; | ||
|
||
export const ApiListSectionShadow = styled.div` | ||
width: 100%; | ||
height: 6rem; | ||
position: relative; | ||
top: -25px; | ||
background: linear-gradient(180deg, rgba(40, 42, 58, 0) 0%, #282a3a 45.31%); | ||
`; |
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,68 @@ | ||
import axios from 'axios'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { toast } from 'react-toastify'; | ||
|
||
import { Button, SkeletonUI } from '../../components'; | ||
import * as S from './styled'; | ||
|
||
export const ApiPostPage: React.FC = () => { | ||
const [apiInfo, setApiInfo] = useState<any>(); | ||
const [loading, setLoading] = useState(false); | ||
const { urlApi } = useParams<{ urlApi: string }>(); | ||
const navigate = useNavigate(); | ||
useEffect(() => { | ||
const getUrlApiInfo = async () => { | ||
await axios({ | ||
method: 'get', | ||
url: `https://tfb.minpeter.cf/info?api=${urlApi}`, | ||
}) | ||
.then((res) => { | ||
if (res.data?.message === 'invalid api name') { | ||
navigate('/'); //나중에 404페이지로 이동하게 | ||
} else { | ||
setApiInfo(res.data); | ||
setTimeout(() => { | ||
setLoading(true); //loading 확인하고싶으면 false로 바꿔주세요. | ||
}, 1200); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}; | ||
getUrlApiInfo(); | ||
}, [navigate, urlApi]); | ||
return ( | ||
<> | ||
{loading ? ( | ||
<> | ||
<S.ApiBox> | ||
{apiInfo?.apiName} / method: {apiInfo?.method} | ||
</S.ApiBox> | ||
<S.ApiDescText>{apiInfo?.desc}</S.ApiDescText> | ||
<S.ApiCommandBox>{apiInfo?.command}</S.ApiCommandBox> | ||
<Button | ||
click={() => { | ||
navigator.clipboard.writeText(apiInfo?.command); | ||
toast.success('복사 완료', { | ||
autoClose: 1000, | ||
position: toast.POSITION.BOTTOM_RIGHT, | ||
}); | ||
}} | ||
bgColor="var(--color-button-primary)" | ||
label="명령어 복사" | ||
/> | ||
</> | ||
) : ( | ||
<> | ||
<SkeletonUI width="30.8rem" height="6.2rem" margin="1rem" /> | ||
<SkeletonUI width="38rem" height="2.6rem" margin="1.5rem 1rem 2rem 1rem" /> | ||
<SkeletonUI width="74rem" height="12rem" margin="1rem 1rem 3rem 1rem" /> | ||
<SkeletonUI width="14rem" height="6rem" margin="0px" /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.