Skip to content

Commit

Permalink
Revert "Merge pull request #95 from SeanMcGrath/local-storage"
Browse files Browse the repository at this point in the history
This reverts commit 49919a1, reversing
changes made to 3b44e32.
  • Loading branch information
morganecf committed May 9, 2020
1 parent 7d4bf54 commit 504efb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 114 deletions.
52 changes: 0 additions & 52 deletions app/client/jsx/LocalStorage.jsx

This file was deleted.

43 changes: 13 additions & 30 deletions app/client/jsx/Room.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Door from './Door.jsx'
import Adventure from './Adventure.jsx'
import Navigation from './Navigation.jsx'
import { WebSocketApi } from './WebAPI.jsx'
import LocalStorage from './LocalStorage.jsx'

class Room extends Component {
/*
Expand All @@ -28,8 +27,6 @@ class Room extends Component {
constructor(props) {
super(props)

const { room, entered } = this.props.currentRoom

// These are the room types for which we show the map button
this.roomTypesWithMap = {
jitsi: true,
Expand All @@ -43,10 +40,14 @@ class Room extends Component {
iframe: true
}

// Rooms that don't have doors are automatically "entered"
const { room, entered } = this.props.currentRoom
const { type } = this.props.rooms[this.props.currentRoom.room]

this.state = {
room,
entered: false,
users: []
entered: this.roomTypesWithDoors[type] ? entered : true,
showMap: false
}

this.socketApi = new WebSocketApi()
Expand Down Expand Up @@ -136,7 +137,6 @@ class Room extends Component {
setTimeout(this.updateRoom.bind(this, room), 500)
} else {
this.updateRoom(room)
document.activeElement.blur()
}
this.setState({ showMap: false })
}
Expand Down Expand Up @@ -165,27 +165,7 @@ class Room extends Component {
this.setState({ showMap: false })
}

computeMapState(room) {
const mapAlreadyUnlocked = LocalStorage.get("MAP_UNLOCKED")
const mapUnlockThreshold = 3
const visitedRooms = Object.values(this.props.visited).filter(x => x).length
const isMapUnlocked = mapAlreadyUnlocked ||
(_.has(this.roomTypesWithMap, room.type) && (visitedRooms >= mapUnlockThreshold))
const showMapTooltip = !mapAlreadyUnlocked && isMapUnlocked
LocalStorage.set("MAP_UNLOCKED", isMapUnlocked)
return {
mapVisible: isMapUnlocked,
showMapTooltip: showMapTooltip
}
}

render() {
if (Object.keys(this.props.rooms).length === 0) {
// room config not loaded yet
return null
}

LocalStorage.touch("USER") // keep session alive
const room = this.props.rooms[this.state.room]

if (room.type === 'redirect') {
Expand All @@ -199,7 +179,11 @@ class Room extends Component {
<Door room={room} users={userList} tintColor={room.doorTint} onClick={this.onEnterRoom.bind(this)}></Door>

const roomClass = this.state.entered ? "room entered" : "room"
const mapState = this.computeMapState(room)

const mapUnlockThreshold = 3
const visitedRooms = Object.values(this.props.visited).filter(x => x).length
const isMapUnlocked = _.has(this.roomTypesWithMap, room.type) && (visitedRooms >= mapUnlockThreshold)
const showMapTooltip = isMapUnlocked && visitedRooms == mapUnlockThreshold

// Allows modal to have access to react components and state
Modal.setAppElement('.app')
Expand All @@ -214,8 +198,8 @@ class Room extends Component {
<Navigation
directions={room.directions}
onClick={this.onSwitchRoom.bind(this)}
showMapButton={mapState.mapVisible}
showMapTooltip={mapState.showMapTooltip}
showMapButton={isMapUnlocked}
showMapTooltip={showMapTooltip}
handleOpenMap={this.handleOpenMap.bind(this)}></Navigation>
<Beforeunload onBeforeunload={this.handleBeforeUnload.bind(this)} />
<Modal
Expand All @@ -230,7 +214,6 @@ class Room extends Component {
}

export default connect(state => state, {
addRooms: reducers.addRoomsActionCreator,
updateUsers: reducers.updateUsersActionCreator,
updateCurrentRoom: reducers.updateCurrentRoomActionCreator
})(Room)
44 changes: 12 additions & 32 deletions app/client/jsx/Welcome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,16 @@ import reducers from './reducers.jsx'
import { Redirect } from 'react-router-dom'
import PuckSelect from './PuckSelect.jsx'
import { HttpApi } from './WebAPI.jsx'
import LocalStorage from './LocalStorage.jsx'

class Welcome extends Component {
constructor(props) {
super(props)

this.httpApi = new HttpApi()

let user = LocalStorage.get("USER")
if (user) {
this.state = {
username: user.username,
avatar: user.avatar,
redirect: "/party"
}
this.handleUserSelected(user)
} else {
this.state = {
username: null,
avatar: null,
redirect: null
}
this.state = {
username: null,
avatar: null,
redirect: null
}
this.httpApi = new HttpApi()
}

async fetchRooms() {
Expand Down Expand Up @@ -67,26 +54,19 @@ class Welcome extends Component {
const response = await this.httpApi.join(this.state.username, this.state.avatar)
if (response.success) {
const { username, avatar } = this.state
const user = {
this.props.updateUser({
username,
avatar,
userId: response.userId
}
this.props.updateUser(user)
this.handleUserSelected(user)
this.setState({redirect: '/party'})
})
this.props.updateCurrentRoom({
room: 'vestibule',
entered: false
})
this.setState({ redirect: '/party' })
}
}

handleUserSelected(user) {
LocalStorage.set("USER", user)
this.props.updateUser(user)
this.props.updateCurrentRoom({
room: 'vestibule',
entered: false
})
}

render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect}/>
Expand Down

0 comments on commit 504efb8

Please sign in to comment.