Finish
This commit is contained in:
parent
a9c934cb2c
commit
c030f9e7a7
8 changed files with 65 additions and 96 deletions
|
|
@ -4,10 +4,10 @@ import './index.css'
|
||||||
|
|
||||||
import Header from '~components/Header'
|
import Header from '~components/Header'
|
||||||
|
|
||||||
import New from '~routes/New'
|
import NewRoute from '~routes/NewRoute'
|
||||||
import Party from '~routes/Party'
|
import PartyRoute from '~routes/PartyRoute'
|
||||||
import Parties from '~routes/Parties'
|
import PartiesRoute from '~routes/PartiesRoute'
|
||||||
import Profile from '~routes/Profile'
|
import ProfileRoute from '~routes/ProfileRoute'
|
||||||
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
|
@ -17,10 +17,10 @@ const App = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header navigate={route} />
|
<Header navigate={route} />
|
||||||
<Route exact path='/' component={New} />
|
<Route exact path='/' component={NewRoute} />
|
||||||
<Route exact path='/parties/' component={Parties} />
|
<Route exact path='/parties/' component={PartiesRoute} />
|
||||||
<Route path='/p/:hash' component={Party} />
|
<Route path='/p/:hash' component={PartyRoute} />
|
||||||
<Route exact path='/:username' component={Profile} />
|
<Route exact path='/:username' component={ProfileRoute} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import SignupModal from '~components/SignupModal'
|
||||||
import { useModal as useSignupModal } from '~utils/useModal'
|
import { useModal as useSignupModal } from '~utils/useModal'
|
||||||
import { useModal as useLoginModal } from '~utils/useModal'
|
import { useModal as useLoginModal } from '~utils/useModal'
|
||||||
import { Link, Route } from 'react-router-dom'
|
import { Link, Route } from 'react-router-dom'
|
||||||
import Profile from '~routes/Profile'
|
import Profile from '~routes/ProfileRoute'
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,14 @@ export enum GridType {
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
mainWeapon?: Weapon
|
||||||
|
mainSummon?: Summon
|
||||||
|
friendSummon?: Summon
|
||||||
|
weapons?: GridArray<Weapon>
|
||||||
|
summons?: GridArray<Summon>
|
||||||
editable: boolean
|
editable: boolean
|
||||||
exists: boolean
|
exists: boolean
|
||||||
pushHistory: (path: string) => void
|
pushHistory?: (path: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const Party = (props: Props) => {
|
const Party = (props: Props) => {
|
||||||
|
|
@ -43,6 +48,14 @@ const Party = (props: Props) => {
|
||||||
const [mainSummon, setMainSummon] = useState<Summon>()
|
const [mainSummon, setMainSummon] = useState<Summon>()
|
||||||
const [friendSummon, setFriendSummon] = useState<Summon>()
|
const [friendSummon, setFriendSummon] = useState<Summon>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMainWeapon(props.mainWeapon)
|
||||||
|
setMainSummon(props.mainSummon)
|
||||||
|
setFriendSummon(props.friendSummon)
|
||||||
|
setWeapons(props.weapons || {})
|
||||||
|
setSummons(props.summons || {})
|
||||||
|
}, [props.mainWeapon, props.mainSummon, props.friendSummon, props.weapons, props.summons])
|
||||||
|
|
||||||
const weaponGrid = (
|
const weaponGrid = (
|
||||||
<WeaponGrid
|
<WeaponGrid
|
||||||
userId={cookies.user ? cookies.user.userId : ''}
|
userId={cookies.user ? cookies.user.userId : ''}
|
||||||
|
|
@ -72,28 +85,23 @@ const Party = (props: Props) => {
|
||||||
<CharacterGrid
|
<CharacterGrid
|
||||||
editable={props.editable}
|
editable={props.editable}
|
||||||
exists={props.exists}
|
exists={props.exists}
|
||||||
onSelect={saveCharacter}
|
onSelect={itemSelected}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
const [currentGrid, setCurrentGrid] = useState<JSX.Element>(weaponGrid)
|
|
||||||
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
|
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
|
||||||
|
|
||||||
const [partyId, setPartyId] = useState('')
|
const [partyId, setPartyId] = useState('')
|
||||||
|
|
||||||
function segmentClicked(event: React.ChangeEvent<HTMLInputElement>) {
|
function segmentClicked(event: React.ChangeEvent<HTMLInputElement>) {
|
||||||
switch(event.target.value) {
|
switch(event.target.value) {
|
||||||
case 'characters':
|
case 'characters':
|
||||||
setCurrentTab(GridType.Character)
|
setCurrentTab(GridType.Character)
|
||||||
setCurrentGrid(characterGrid)
|
|
||||||
break
|
break
|
||||||
case 'weapons':
|
case 'weapons':
|
||||||
setCurrentTab(GridType.Weapon)
|
setCurrentTab(GridType.Weapon)
|
||||||
setCurrentGrid(weaponGrid)
|
|
||||||
break
|
break
|
||||||
case 'summons':
|
case 'summons':
|
||||||
setCurrentTab(GridType.Summon)
|
setCurrentTab(GridType.Summon)
|
||||||
setCurrentGrid(summonGrid)
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|
@ -115,10 +123,10 @@ const Party = (props: Props) => {
|
||||||
})
|
})
|
||||||
.then(partyId => {
|
.then(partyId => {
|
||||||
setPartyId(partyId)
|
setPartyId(partyId)
|
||||||
save(partyId, type, item, position)
|
saveItem(partyId, type, item, position)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
save(partyId, type, item, position)
|
saveItem(partyId, type, item, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +140,7 @@ const Party = (props: Props) => {
|
||||||
return await api.endpoints.parties.create(body, headers)
|
return await api.endpoints.parties.create(body, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
function save(partyId: string, type: GridType, item: Character | Weapon | Summon, position: number) {
|
function saveItem(partyId: string, type: GridType, item: Character | Weapon | Summon, position: number) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case GridType.Class:
|
case GridType.Class:
|
||||||
saveClass()
|
saveClass()
|
||||||
|
|
@ -157,6 +165,7 @@ const Party = (props: Props) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Weapons
|
||||||
function storeWeapon(weapon: Weapon, position: number) {
|
function storeWeapon(weapon: Weapon, position: number) {
|
||||||
if (position == -1) {
|
if (position == -1) {
|
||||||
setMainWeapon(weapon)
|
setMainWeapon(weapon)
|
||||||
|
|
@ -179,6 +188,7 @@ const Party = (props: Props) => {
|
||||||
}, headers)
|
}, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Summons
|
||||||
function storeSummon(summon: Summon, position: number) {
|
function storeSummon(summon: Summon, position: number) {
|
||||||
if (position == -1) {
|
if (position == -1) {
|
||||||
setMainSummon(summon)
|
setMainSummon(summon)
|
||||||
|
|
@ -204,10 +214,12 @@ const Party = (props: Props) => {
|
||||||
}, headers)
|
}, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Character
|
||||||
function saveCharacter(character: Character, position: number, party: string) {
|
function saveCharacter(character: Character, position: number, party: string) {
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Class
|
||||||
function saveClass() {
|
function saveClass() {
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +231,18 @@ const Party = (props: Props) => {
|
||||||
onClick={segmentClicked}
|
onClick={segmentClicked}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{currentGrid}
|
{
|
||||||
|
(() => {
|
||||||
|
switch(currentTab) {
|
||||||
|
case GridType.Character:
|
||||||
|
return characterGrid
|
||||||
|
case GridType.Weapon:
|
||||||
|
return weaponGrid
|
||||||
|
case GridType.Summon:
|
||||||
|
return summonGrid
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
const PartySegmentedControl = (props: Props) => {
|
const PartySegmentedControl = (props: Props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<SegmentedControl>
|
<SegmentedControl>
|
||||||
|
|
@ -29,21 +30,21 @@ const PartySegmentedControl = (props: Props) => {
|
||||||
<Segment
|
<Segment
|
||||||
groupName="grid"
|
groupName="grid"
|
||||||
name="characters"
|
name="characters"
|
||||||
selected={props.selectedTab === GridType.Character}
|
selected={props.selectedTab == GridType.Character}
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
>Characters</Segment>
|
>Characters</Segment>
|
||||||
|
|
||||||
<Segment
|
<Segment
|
||||||
groupName="grid"
|
groupName="grid"
|
||||||
name="weapons"
|
name="weapons"
|
||||||
selected={props.selectedTab === GridType.Weapon}
|
selected={props.selectedTab == GridType.Weapon}
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
>Weapons</Segment>
|
>Weapons</Segment>
|
||||||
|
|
||||||
<Segment
|
<Segment
|
||||||
groupName="grid"
|
groupName="grid"
|
||||||
name="summons"
|
name="summons"
|
||||||
selected={props.selectedTab === GridType.Summon}
|
selected={props.selectedTab == GridType.Summon}
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
>Summons</Segment>
|
>Summons</Segment>
|
||||||
</SegmentedControl>
|
</SegmentedControl>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import Party from '~components/Party'
|
||||||
interface Props {}
|
interface Props {}
|
||||||
interface NewProps extends RouteComponentProps<Props> {}
|
interface NewProps extends RouteComponentProps<Props> {}
|
||||||
|
|
||||||
const New: React.FC<NewProps> = () => {
|
const NewRoute: React.FC<NewProps> = () => {
|
||||||
function callback(path: string) {
|
function callback(path: string) {
|
||||||
// This is scuffed, how do we do this natively?
|
// This is scuffed, how do we do this natively?
|
||||||
window.history.replaceState(null, `Grid Tool`, `${path}`)
|
window.history.replaceState(null, `Grid Tool`, `${path}`)
|
||||||
|
|
@ -23,4 +23,4 @@ const New: React.FC<NewProps> = () => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default New
|
export default NewRoute
|
||||||
|
|
@ -4,7 +4,7 @@ interface State {
|
||||||
parties: {id: string, hash: string}[]
|
parties: {id: string, hash: string}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
class Parties extends React.Component {
|
class PartiesRoute extends React.Component {
|
||||||
state: State
|
state: State
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|
@ -36,4 +36,4 @@ class Parties extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Parties
|
export default PartiesRoute
|
||||||
|
|
@ -3,10 +3,7 @@ import { withCookies, useCookies } from 'react-cookie'
|
||||||
import { RouteComponentProps, withRouter } from 'react-router-dom'
|
import { RouteComponentProps, withRouter } from 'react-router-dom'
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
|
|
||||||
import PartySegmentedControl from '~components/PartySegmentedControl'
|
import Party from '~components/Party'
|
||||||
import WeaponGrid from '~components/WeaponGrid'
|
|
||||||
import SummonGrid from '~components/SummonGrid'
|
|
||||||
import CharacterGrid from '~components/CharacterGrid'
|
|
||||||
import Button from '~components/Button'
|
import Button from '~components/Button'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -15,7 +12,7 @@ interface Props {
|
||||||
|
|
||||||
interface PartyProps extends RouteComponentProps<Props> {}
|
interface PartyProps extends RouteComponentProps<Props> {}
|
||||||
|
|
||||||
const Party: React.FC<PartyProps> = ({ match }) => {
|
const PartyRoute: React.FC<PartyProps> = ({ match }) => {
|
||||||
const [found, setFound] = useState(false)
|
const [found, setFound] = useState(false)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [editable, setEditable] = useState(false)
|
const [editable, setEditable] = useState(false)
|
||||||
|
|
@ -28,9 +25,7 @@ const Party: React.FC<PartyProps> = ({ match }) => {
|
||||||
const [friendSummon, setFriendSummon] = useState<Summon>()
|
const [friendSummon, setFriendSummon] = useState<Summon>()
|
||||||
|
|
||||||
const [partyId, setPartyId] = useState('')
|
const [partyId, setPartyId] = useState('')
|
||||||
const [cookies, setCookie] = useCookies(['userId'])
|
const [cookies, setCookie] = useCookies(['user'])
|
||||||
const [selectedTab, setSelectedTab] = useState('weapons')
|
|
||||||
const [tab, setTab] = useState<JSX.Element>()
|
|
||||||
const shortcode = match.params.hash || ''
|
const shortcode = match.params.hash || ''
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -84,68 +79,18 @@ const Party: React.FC<PartyProps> = ({ match }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function segmentClicked(event: React.ChangeEvent<HTMLInputElement>) {
|
|
||||||
setSelectedTab(event.target.value)
|
|
||||||
|
|
||||||
switch(event.target.value) {
|
|
||||||
case 'weapons':
|
|
||||||
setTab((
|
|
||||||
<WeaponGrid
|
|
||||||
userId={cookies.user ? cookies.user.user_id : ''}
|
|
||||||
partyId={partyId}
|
|
||||||
mainhand={mainWeapon}
|
|
||||||
grid={weapons}
|
|
||||||
editable={editable}
|
|
||||||
exists={true}
|
|
||||||
found={found}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
break
|
|
||||||
case 'summons':
|
|
||||||
setTab((
|
|
||||||
<SummonGrid
|
|
||||||
userId={cookies.user ? cookies.user.user_id : ''}
|
|
||||||
partyId={partyId}
|
|
||||||
main={mainSummon}
|
|
||||||
friend={friendSummon}
|
|
||||||
grid={summons}
|
|
||||||
editable={editable}
|
|
||||||
exists={true}
|
|
||||||
found={found}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
break
|
|
||||||
case 'characters':
|
|
||||||
setTab((
|
|
||||||
<CharacterGrid
|
|
||||||
editable={true}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
return (
|
return (
|
||||||
<div id="Content">
|
<div id="Content">
|
||||||
<PartySegmentedControl
|
<Party
|
||||||
selectedTab={selectedTab}
|
mainWeapon={mainWeapon}
|
||||||
onClick={segmentClicked}
|
mainSummon={mainSummon}
|
||||||
|
friendSummon={friendSummon}
|
||||||
|
weapons={weapons}
|
||||||
|
summons={summons}
|
||||||
|
editable={editable}
|
||||||
|
exists={found}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{tab || (
|
|
||||||
<WeaponGrid
|
|
||||||
userId={cookies.user ? cookies.user.user_id : ''}
|
|
||||||
partyId={partyId}
|
|
||||||
mainhand={mainWeapon}
|
|
||||||
grid={weapons}
|
|
||||||
editable={editable}
|
|
||||||
exists={true}
|
|
||||||
found={found}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +116,6 @@ const Party: React.FC<PartyProps> = ({ match }) => {
|
||||||
export default
|
export default
|
||||||
withCookies(
|
withCookies(
|
||||||
withRouter(
|
withRouter(
|
||||||
Party
|
PartyRoute
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -25,7 +25,7 @@ interface Party {
|
||||||
|
|
||||||
interface ProfileProps extends RouteComponentProps<Props> {}
|
interface ProfileProps extends RouteComponentProps<Props> {}
|
||||||
|
|
||||||
const Profile: React.FC<ProfileProps> = ({ history, match }) => {
|
const ProfileRoute: React.FC<ProfileProps> = ({ history, match }) => {
|
||||||
const [cookies, setCookie] = useCookies(['user'])
|
const [cookies, setCookie] = useCookies(['user'])
|
||||||
|
|
||||||
const [found, setFound] = useState(false)
|
const [found, setFound] = useState(false)
|
||||||
|
|
@ -128,6 +128,6 @@ const Profile: React.FC<ProfileProps> = ({ history, match }) => {
|
||||||
export default
|
export default
|
||||||
withCookies(
|
withCookies(
|
||||||
withRouter(
|
withRouter(
|
||||||
Profile
|
ProfileRoute
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Loading…
Reference in a new issue