Starts of a Profile route
This commit is contained in:
parent
f4fcf0c073
commit
50869e1ec0
3 changed files with 63 additions and 3 deletions
|
|
@ -3,9 +3,10 @@ import { Router, Route } from 'react-router-dom'
|
|||
|
||||
import history from '~utils/history'
|
||||
|
||||
import New from '~routes/New/New'
|
||||
import Party from '~routes/Party/Party'
|
||||
import Parties from '~routes/Parties/Parties'
|
||||
import New from '~routes/New'
|
||||
import Party from '~routes/Party'
|
||||
import Parties from '~routes/Parties'
|
||||
import Profile from '~routes/Profile'
|
||||
|
||||
// The Main component renders one of the three provided
|
||||
// Routes (provided that one matches). Both the /roster
|
||||
|
|
@ -18,6 +19,7 @@ const Main = () => (
|
|||
<Route exact path='/' component={New} />
|
||||
<Route exact path='/parties/' component={Parties} />
|
||||
<Route path='/p/:hash' component={Party} />
|
||||
<Route path='/:username' component={Profile} />
|
||||
</Router>
|
||||
</main>
|
||||
)
|
||||
|
|
|
|||
57
src/routes/Profile/index.tsx
Normal file
57
src/routes/Profile/index.tsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import React, { useEffect, useState } from 'react'
|
||||
import { withCookies, useCookies } from 'react-cookie'
|
||||
import { RouteComponentProps, withRouter } from 'react-router-dom'
|
||||
import api from '~utils/api'
|
||||
|
||||
interface Props {
|
||||
username: string
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: string
|
||||
username: string
|
||||
granblueId: number
|
||||
}
|
||||
|
||||
interface ProfileProps extends RouteComponentProps<Props> {}
|
||||
|
||||
const Profile: React.FC<ProfileProps> = ({ match }) => {
|
||||
const [cookies, setCookie] = useCookies(['user'])
|
||||
const [user, setUser] = useState<User>({
|
||||
id: '',
|
||||
username: '',
|
||||
granblueId: 0
|
||||
})
|
||||
const [parties, setParties] = useState<GridArray[]>([])
|
||||
|
||||
const username = match.params.username || ''
|
||||
|
||||
useEffect(() => {
|
||||
fetchProfile(username)
|
||||
}, [])
|
||||
|
||||
async function fetchProfile(username: string) {
|
||||
api.endpoints.users.getOne({ id: username })
|
||||
.then(response => {
|
||||
setUser({
|
||||
id: response.data.user.id,
|
||||
username: response.data.user.username,
|
||||
granblueId: response.data.user.granblue_id
|
||||
})
|
||||
setParties(response.data.user.parties)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{user.username}</h1>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default
|
||||
withCookies(
|
||||
withRouter(
|
||||
Profile
|
||||
)
|
||||
)
|
||||
1
src/types/GridArray.d.ts
vendored
Normal file
1
src/types/GridArray.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
type GridArray = { [key: number]: Weapon }
|
||||
Loading…
Reference in a new issue