Bind server select button and store selected server in redux store.
This commit is contained in:
parent
574b362d12
commit
cb68c34abe
@ -23,7 +23,7 @@ import { LoggerUtil } from 'common/logging/loggerutil'
|
|||||||
import { DistributionAPI } from 'common/distribution/DistributionAPI'
|
import { DistributionAPI } from 'common/distribution/DistributionAPI'
|
||||||
import { getServerStatus } from 'common/mojang/net/ServerStatusAPI'
|
import { getServerStatus } from 'common/mojang/net/ServerStatusAPI'
|
||||||
import { Distribution } from 'helios-distribution-types'
|
import { Distribution } from 'helios-distribution-types'
|
||||||
import { HeliosDistribution } from 'common/distribution/DistributionFactory'
|
import { HeliosDistribution, HeliosServer } from 'common/distribution/DistributionFactory'
|
||||||
|
|
||||||
import './Application.css'
|
import './Application.css'
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ interface ApplicationProps {
|
|||||||
currentView: View
|
currentView: View
|
||||||
overlayQueue: OverlayPushAction<unknown>[]
|
overlayQueue: OverlayPushAction<unknown>[]
|
||||||
distribution: HeliosDistribution
|
distribution: HeliosDistribution
|
||||||
|
selectedServer: HeliosServer
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ApplicationState {
|
interface ApplicationState {
|
||||||
@ -52,7 +53,8 @@ const mapState = (state: StoreType): Partial<ApplicationProps> => {
|
|||||||
return {
|
return {
|
||||||
currentView: state.currentView,
|
currentView: state.currentView,
|
||||||
overlayQueue: state.overlayQueue,
|
overlayQueue: state.overlayQueue,
|
||||||
distribution: state.app.distribution!
|
distribution: state.app.distribution!,
|
||||||
|
selectedServer: state.app.selectedServer!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const mapDispatch = {
|
const mapDispatch = {
|
||||||
@ -63,7 +65,7 @@ const mapDispatch = {
|
|||||||
|
|
||||||
class Application extends React.Component<ApplicationProps & typeof mapDispatch, ApplicationState> {
|
class Application extends React.Component<ApplicationProps & typeof mapDispatch, ApplicationState> {
|
||||||
|
|
||||||
private readonly logger = LoggerUtil.getLogger('Application')
|
private static readonly logger = LoggerUtil.getLogger('ApplicationTSX')
|
||||||
|
|
||||||
private bkid!: number
|
private bkid!: number
|
||||||
|
|
||||||
@ -87,7 +89,7 @@ class Application extends React.Component<ApplicationProps & typeof mapDispatch,
|
|||||||
</>
|
</>
|
||||||
case View.LANDING:
|
case View.LANDING:
|
||||||
return <>
|
return <>
|
||||||
<Landing />
|
<Landing distribution={this.props.distribution} selectedServer={this.props.selectedServer} />
|
||||||
</>
|
</>
|
||||||
case View.LOGIN:
|
case View.LOGIN:
|
||||||
return <>
|
return <>
|
||||||
@ -161,7 +163,11 @@ class Application extends React.Component<ApplicationProps & typeof mapDispatch,
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
this.props.setDistribution(new HeliosDistribution(rawDisto))
|
const distro = new HeliosDistribution(rawDisto)
|
||||||
|
this.props.setDistribution(distro)
|
||||||
|
// TODO TEMP USE CONFIG
|
||||||
|
// TODO TODO TODO TODO
|
||||||
|
this.props.setSelectedServer(distro.servers[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Setup hook for distro refresh every ~ 5 mins.
|
// TODO Setup hook for distro refresh every ~ 5 mins.
|
||||||
@ -190,27 +196,12 @@ class Application extends React.Component<ApplicationProps & typeof mapDispatch,
|
|||||||
console.log(serverStatus)
|
console.log(serverStatus)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.props.pushServerSelectOverlay({
|
|
||||||
servers: this.props.distribution.servers,
|
|
||||||
selectedId: this.props.distribution.servers[0].rawServer.id,
|
|
||||||
onSelection: (serverId: string) => this.logger.info('Server Selection Change:', serverId)
|
|
||||||
})
|
|
||||||
// this.props.pushGenericOverlay({
|
// this.props.pushGenericOverlay({
|
||||||
// title: 'Test Title 2',
|
// title: 'Test Title 2',
|
||||||
// description: 'Test Description',
|
// description: 'Test Description',
|
||||||
// dismissible: true
|
// dismissible: true
|
||||||
// })
|
// })
|
||||||
// this.props.pushGenericOverlay({
|
// this.props.pushGenericOverlay({
|
||||||
// title: 'Test Title 3',
|
|
||||||
// description: 'Test Description',
|
|
||||||
// dismissible: true
|
|
||||||
// })
|
|
||||||
// this.props.pushGenericOverlay({
|
|
||||||
// title: 'Test Title 4',
|
|
||||||
// description: 'Test Description',
|
|
||||||
// dismissible: true
|
|
||||||
// })
|
|
||||||
// this.props.pushGenericOverlay({
|
|
||||||
// title: 'Test Title IMPORTANT',
|
// title: 'Test Title IMPORTANT',
|
||||||
// description: 'Test Description',
|
// description: 'Test Description',
|
||||||
// dismissible: true
|
// dismissible: true
|
||||||
|
@ -1,25 +1,49 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import News from '../news/News'
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
|
import { StoreType } from '../../redux/store'
|
||||||
|
import { AppActionDispatch } from '../..//redux/actions/appActions'
|
||||||
|
import { OverlayActionDispatch } from '../../redux/actions/overlayActions'
|
||||||
|
import { HeliosDistribution, HeliosServer } from 'common/distribution/DistributionFactory'
|
||||||
import { MojangStatus, MojangStatusColor } from 'common/mojang/rest/internal/MojangStatus'
|
import { MojangStatus, MojangStatusColor } from 'common/mojang/rest/internal/MojangStatus'
|
||||||
import { MojangResponse } from 'common/mojang/rest/internal/MojangResponse'
|
import { MojangResponse } from 'common/mojang/rest/internal/MojangResponse'
|
||||||
import { MojangRestAPI } from 'common/mojang/rest/MojangRestAPI'
|
import { MojangRestAPI } from 'common/mojang/rest/MojangRestAPI'
|
||||||
import { RestResponseStatus } from 'common/got/RestResponse'
|
import { RestResponseStatus } from 'common/got/RestResponse'
|
||||||
import { LoggerUtil } from 'common/logging/loggerutil'
|
import { LoggerUtil } from 'common/logging/loggerutil'
|
||||||
|
|
||||||
|
import News from '../news/News'
|
||||||
|
|
||||||
import './Landing.css'
|
import './Landing.css'
|
||||||
|
|
||||||
|
interface LandingProps {
|
||||||
|
distribution: HeliosDistribution
|
||||||
|
selectedServer: HeliosServer
|
||||||
|
}
|
||||||
|
|
||||||
interface LandingState {
|
interface LandingState {
|
||||||
mojangStatuses: MojangStatus[]
|
mojangStatuses: MojangStatus[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Landing extends React.Component<unknown, LandingState> {
|
const mapState = (state: StoreType): Partial<LandingProps> => {
|
||||||
|
return {
|
||||||
|
distribution: state.app.distribution!,
|
||||||
|
selectedServer: state.app.selectedServer!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const mapDispatch = {
|
||||||
|
...AppActionDispatch,
|
||||||
|
...OverlayActionDispatch
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly logger = LoggerUtil.getLogger('Landing')
|
type InternalLandingProps = LandingProps & typeof mapDispatch
|
||||||
|
|
||||||
|
class Landing extends React.Component<InternalLandingProps, LandingState> {
|
||||||
|
|
||||||
|
private static readonly logger = LoggerUtil.getLogger('LandingTSX')
|
||||||
|
|
||||||
private mojangStatusInterval!: NodeJS.Timeout
|
private mojangStatusInterval!: NodeJS.Timeout
|
||||||
|
|
||||||
constructor(props: unknown) {
|
constructor(props: InternalLandingProps) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
mojangStatuses: []
|
mojangStatuses: []
|
||||||
@ -109,6 +133,25 @@ export default class Landing extends React.Component<unknown, LandingState> {
|
|||||||
return statuses
|
return statuses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private openServerSelect = (): void => {
|
||||||
|
this.props.pushServerSelectOverlay({
|
||||||
|
servers: this.props.distribution.servers,
|
||||||
|
selectedId: this.props.selectedServer.rawServer.id,
|
||||||
|
onSelection: (serverId: string) => {
|
||||||
|
Landing.logger.info('Server Selection Change:', serverId)
|
||||||
|
this.props.setSelectedServer(this.props.distribution.getServerById(serverId)!)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private getSelectedServerText = (): string => {
|
||||||
|
if(this.props.selectedServer != null) {
|
||||||
|
return `• ${this.props.selectedServer.rawServer.id}`
|
||||||
|
} else {
|
||||||
|
return '• No Server Selected'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
return <>
|
return <>
|
||||||
|
|
||||||
@ -254,7 +297,7 @@ export default class Landing extends React.Component<unknown, LandingState> {
|
|||||||
<div id="launch_content">
|
<div id="launch_content">
|
||||||
<button id="launch_button">PLAY</button>
|
<button id="launch_button">PLAY</button>
|
||||||
<div className="bot_divider"></div>
|
<div className="bot_divider"></div>
|
||||||
<button id="server_selection_button" className="bot_label">• No Server Selected</button>
|
<button onClick={this.openServerSelect} id="server_selection_button" className="bot_label">{this.getSelectedServerText()}</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="launch_details">
|
<div id="launch_details">
|
||||||
<div id="launch_details_left">
|
<div id="launch_details_left">
|
||||||
@ -276,4 +319,6 @@ export default class Landing extends React.Component<unknown, LandingState> {
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default connect<unknown, typeof mapDispatch>(mapState, mapDispatch)(Landing)
|
@ -47,7 +47,7 @@ class ServerSelectOverlay extends React.Component<InternalServerSelectOverlayPro
|
|||||||
this.props.popOverlayContent()
|
this.props.popOverlayContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
getMainServerStar(): JSX.Element {
|
private getMainServerStar(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className="serverListingStarWrapper">
|
<div className="serverListingStarWrapper">
|
||||||
<svg id="mainServerSVG" viewBox="0 0 107.45 104.74" width="20px" height="20px">
|
<svg id="mainServerSVG" viewBox="0 0 107.45 104.74" width="20px" height="20px">
|
||||||
@ -59,7 +59,7 @@ class ServerSelectOverlay extends React.Component<InternalServerSelectOverlayPro
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getServers(): JSX.Element[] {
|
private getServerListings(): JSX.Element[] {
|
||||||
const servers: JSX.Element[] = []
|
const servers: JSX.Element[] = []
|
||||||
|
|
||||||
for(const { rawServer: raw } of this.props.servers) {
|
for(const { rawServer: raw } of this.props.servers) {
|
||||||
@ -89,7 +89,7 @@ class ServerSelectOverlay extends React.Component<InternalServerSelectOverlayPro
|
|||||||
<span id="serverSelectHeader">Available Servers</span>
|
<span id="serverSelectHeader">Available Servers</span>
|
||||||
<div id="serverSelectList">
|
<div id="serverSelectList">
|
||||||
<div id="serverSelectListScrollable">
|
<div id="serverSelectListScrollable">
|
||||||
{this.getServers()}
|
{this.getServerListings()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="serverSelectActions">
|
<div id="serverSelectActions">
|
||||||
|
@ -29,6 +29,7 @@ ReactDOM.render(
|
|||||||
currentView={store.getState().currentView}
|
currentView={store.getState().currentView}
|
||||||
overlayQueue={store.getState().overlayQueue}
|
overlayQueue={store.getState().overlayQueue}
|
||||||
distribution={store.getState().app.distribution!}
|
distribution={store.getState().app.distribution!}
|
||||||
|
selectedServer={store.getState().app.selectedServer!}
|
||||||
/>
|
/>
|
||||||
</Provider>
|
</Provider>
|
||||||
</AppContainer>,
|
</AppContainer>,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Action } from 'redux'
|
import { Action } from 'redux'
|
||||||
import { HeliosDistribution } from 'common/distribution/DistributionFactory'
|
import { HeliosDistribution, HeliosServer } from 'common/distribution/DistributionFactory'
|
||||||
|
|
||||||
export enum AppActionType {
|
export enum AppActionType {
|
||||||
SetDistribution = 'SET_DISTRIBUTION'
|
SetDistribution = 'SET_DISTRIBUTION',
|
||||||
|
SetSelectedServer = 'SET_SELECTED_SERVER'
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
@ -12,6 +13,10 @@ export interface SetDistributionAction extends AppAction {
|
|||||||
payload: HeliosDistribution
|
payload: HeliosDistribution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SetSelectedServerAction extends AppAction {
|
||||||
|
payload: HeliosServer
|
||||||
|
}
|
||||||
|
|
||||||
export function setDistribution(distribution: HeliosDistribution): SetDistributionAction {
|
export function setDistribution(distribution: HeliosDistribution): SetDistributionAction {
|
||||||
return {
|
return {
|
||||||
type: AppActionType.SetDistribution,
|
type: AppActionType.SetDistribution,
|
||||||
@ -19,6 +24,14 @@ export function setDistribution(distribution: HeliosDistribution): SetDistributi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setSelectedServer(server: HeliosServer): SetSelectedServerAction {
|
||||||
|
return {
|
||||||
|
type: AppActionType.SetSelectedServer,
|
||||||
|
payload: server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const AppActionDispatch = {
|
export const AppActionDispatch = {
|
||||||
setDistribution: (d: HeliosDistribution): SetDistributionAction => setDistribution(d)
|
setDistribution: (d: HeliosDistribution): SetDistributionAction => setDistribution(d),
|
||||||
|
setSelectedServer: (s: HeliosServer): SetSelectedServerAction => setSelectedServer(s)
|
||||||
}
|
}
|
@ -1,13 +1,15 @@
|
|||||||
import { AppActionType, AppAction, SetDistributionAction } from '../actions/appActions'
|
import { AppActionType, AppAction, SetDistributionAction, SetSelectedServerAction } from '../actions/appActions'
|
||||||
import { Reducer } from 'redux'
|
import { Reducer } from 'redux'
|
||||||
import { HeliosDistribution } from 'common/distribution/DistributionFactory'
|
import { HeliosDistribution, HeliosServer } from 'common/distribution/DistributionFactory'
|
||||||
|
|
||||||
export interface AppState {
|
export interface AppState {
|
||||||
distribution: HeliosDistribution | null
|
distribution: HeliosDistribution | null
|
||||||
|
selectedServer: HeliosServer | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultAppState: AppState = {
|
const defaultAppState: AppState = {
|
||||||
distribution: null!
|
distribution: null,
|
||||||
|
selectedServer: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppReducer: Reducer<AppState, AppAction> = (state = defaultAppState, action) => {
|
const AppReducer: Reducer<AppState, AppAction> = (state = defaultAppState, action) => {
|
||||||
@ -17,6 +19,11 @@ const AppReducer: Reducer<AppState, AppAction> = (state = defaultAppState, actio
|
|||||||
...state,
|
...state,
|
||||||
distribution: (action as SetDistributionAction).payload
|
distribution: (action as SetDistributionAction).payload
|
||||||
}
|
}
|
||||||
|
case AppActionType.SetSelectedServer:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
selectedServer: (action as SetSelectedServerAction).payload
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user