Remove old routes
This commit is contained in:
parent
e45aa5cb24
commit
7e45533dbb
2 changed files with 0 additions and 171 deletions
|
|
@ -1,39 +0,0 @@
|
||||||
import React from 'react'
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
parties: {id: string, hash: string}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
class PartiesRoute extends React.Component {
|
|
||||||
state: State
|
|
||||||
|
|
||||||
constructor(props: any) {
|
|
||||||
super(props)
|
|
||||||
this.state = {
|
|
||||||
parties: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getParties() {
|
|
||||||
fetch('http://localhost:3001/parties/')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(parties => this.setState({
|
|
||||||
parties: parties
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
this.getParties()
|
|
||||||
const items = this.state.parties.map((party: {id: string, hash: string }) =>
|
|
||||||
<li key={party.id}><a href={'../' + party.hash}>{party.hash}</a></li>
|
|
||||||
)
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>A list of parties</h1>
|
|
||||||
<ul>{items}</ul>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PartiesRoute
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
import React, { useEffect, useState } from 'react'
|
|
||||||
import { withCookies, useCookies } from 'react-cookie'
|
|
||||||
import { useParams, useNavigate } from 'react-router-dom'
|
|
||||||
import api from '~utils/api'
|
|
||||||
|
|
||||||
import GridRep from '~components/GridRep'
|
|
||||||
import GridRepCollection from '~components/GridRepCollection'
|
|
||||||
import { composeInitialProps } from 'react-i18next'
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
username: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface User {
|
|
||||||
id: string
|
|
||||||
username: string
|
|
||||||
granblueId: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Party {
|
|
||||||
id: string
|
|
||||||
shortcode: string
|
|
||||||
weapons: GridWeapon[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const ProfileRoute: React.FC = () => {
|
|
||||||
const params = useParams()
|
|
||||||
const navigate = useNavigate()
|
|
||||||
|
|
||||||
const [cookies, setCookie] = useCookies(['user'])
|
|
||||||
|
|
||||||
const [found, setFound] = useState(false)
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const [parties, setParties] = useState<Party[]>([])
|
|
||||||
const [user, setUser] = useState<User>({
|
|
||||||
id: '',
|
|
||||||
username: '',
|
|
||||||
granblueId: 0
|
|
||||||
})
|
|
||||||
|
|
||||||
const username = params.username || ''
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log(`Fetching profile for ${username}...`)
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
setFound(true)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
if (error.response != null) {
|
|
||||||
if (error.response.status == 404) {
|
|
||||||
setFound(false)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function render() {
|
|
||||||
const content = (parties && parties.length > 0) ? renderGrids() : renderNoGrids()
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>{user.username}</h1>
|
|
||||||
{content}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function goTo(shortcode: string) {
|
|
||||||
navigate(`/p/${shortcode}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderGrids() {
|
|
||||||
return (
|
|
||||||
<GridRepCollection>
|
|
||||||
{
|
|
||||||
parties.map((party, i) => {
|
|
||||||
return <GridRep
|
|
||||||
shortcode={party.shortcode}
|
|
||||||
grid={party.weapons}
|
|
||||||
key={`party-${i}`}
|
|
||||||
onClick={goTo}
|
|
||||||
/>
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</GridRepCollection>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderNoGrids() {
|
|
||||||
return (
|
|
||||||
<div id="NotFound">
|
|
||||||
<h2>This user has no grids.</h2>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderNotFound() {
|
|
||||||
return (
|
|
||||||
<div id="NotFound">
|
|
||||||
<h2>That user doesn't exist.</h2>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found && !loading) {
|
|
||||||
return renderNotFound()
|
|
||||||
} else if (found && !loading) {
|
|
||||||
return render()
|
|
||||||
} else {
|
|
||||||
return (<div />)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default
|
|
||||||
withCookies(
|
|
||||||
ProfileRoute
|
|
||||||
)
|
|
||||||
Loading…
Reference in a new issue