Skip to content

Commit

Permalink
Merge patch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 31, 2023
2 parents bff12fd + a92b405 commit eca2881
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 13 deletions.
53 changes: 51 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jeremyckahn/farmhand",
"version": "1.18.4",
"version": "1.18.5",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -121,6 +121,7 @@
"react-confetti": "^6.1.0",
"react-dom": "^17.0.2",
"react-file-reader-input": "^2.0.0",
"react-helmet": "^6.1.0",
"react-hotkeys": "^2.0.0",
"react-markdown": "^4.3.1",
"react-number-format": "^4.4.1",
Expand Down
76 changes: 76 additions & 0 deletions src/components/ChatRoom/ChatRoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useContext } from 'react'
import { Helmet } from 'react-helmet'
import classNames from 'classnames'
import Button from '@material-ui/core/Button'
import Dialog from '@material-ui/core/Dialog'
import DialogTitle from '@material-ui/core/DialogTitle'
import DialogContent from '@material-ui/core/DialogContent'
import DialogActions from '@material-ui/core/DialogActions'
import Typography from '@material-ui/core/Typography'

import FarmhandContext from '../Farmhand/Farmhand.context'

import './ChatRoom.sass'

const chitchatterDomain = 'https://chitchatter.im'

export const ChatRoom = () => {
const dialogTitleId = 'chat-title'
const dialogContentId = 'chat-content'

const {
handlers: { handleChatRoomOpenStateChange },
gameState: { id, isChatOpen, room },
} = useContext(FarmhandContext)

const handleChatRoomClose = () => {
handleChatRoomOpenStateChange(false)
}

const chatRoomComponent = (
// @ts-ignore
<chat-room
root-url={chitchatterDomain}
room={`__farmhand__${room}`}
user-id={id}
style={{ height: '100%', width: '100%', border: 'none' }}
color-mode="light"
/>
)

return (
<>
<Helmet>
<script src={`${chitchatterDomain}/sdk.js`} />
</Helmet>
<Dialog
{...{
className: classNames('Farmhand', 'ChatRoom'),
fullWidth: true,
keepMounted: true,
fullScreen: true,
open: isChatOpen,
onClose: handleChatRoomClose,
}}
aria-describedby={dialogTitleId}
aria-labelledby={dialogContentId}
>
<DialogTitle {...{ disableTypography: true }}>
<Typography
{...{ id: dialogTitleId, component: 'h2', variant: 'h6' }}
>
Chat room
</Typography>
</DialogTitle>
<DialogContent {...{ id: dialogContentId }}>
{chatRoomComponent}
</DialogContent>
<DialogActions>
<Button onClick={handleChatRoomClose} color="primary" autoFocus>
Close
</Button>
</DialogActions>
</Dialog>
</>
)
}
4 changes: 4 additions & 0 deletions src/components/ChatRoom/ChatRoom.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.ChatRoom
.MuiDialog-container
padding: 1em
height: calc(100% - 2em)
1 change: 1 addition & 0 deletions src/components/ChatRoom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ChatRoom'
12 changes: 12 additions & 0 deletions src/components/Farmhand/Farmhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ import { endpoints, rtcConfig, trackerUrls } from '../../config'

import { scarecrow } from '../../data/items'

import { ChatRoom } from '../ChatRoom'

import { getInventoryQuantities } from './helpers/getInventoryQuantities'
import FarmhandContext from './Farmhand.context'
import { FarmhandReducers } from './FarmhandReducers'
Expand Down Expand Up @@ -238,6 +240,7 @@ const applyPriceEvents = (valueAdjustments, priceCrashes, priceSurges) => {
* of that cellar item sold. The numbers in this map represent a subset of the
* corresponding ones in itemsSold. cellarItemsSold is intended to be used for
* internal bookkeeping.
* @property {boolean} isChatOpen Whether the chat modal is open.
* @property {boolean} isDialogViewOpen
* @property {boolean} isOnline Whether the player is playing online.
* @property {boolean} isWaitingForDayToCompleteIncrementing
Expand Down Expand Up @@ -399,6 +402,11 @@ export default class Farmhand extends FarmhandReducers {
)
}

get isChatAvailable() {
const { isOnline, room } = this.state
return isOnline && room !== DEFAULT_ROOM
}

/**
* @returns {farmhand.state}
*/
Expand Down Expand Up @@ -446,6 +454,7 @@ export default class Farmhand extends FarmhandReducers {
isMenuOpen: !doesMenuObstructStage(),
itemsSold: {},
cellarItemsSold: {},
isChatOpen: false,
isDialogViewOpen: false,
isOnline: this.props.match.path.startsWith('/online'),
isWaitingForDayToCompleteIncrementing: false,
Expand Down Expand Up @@ -1268,6 +1277,7 @@ export default class Farmhand extends FarmhandReducers {
state: { redirect },
fieldToolInventory,
handlers,
isChatAvailable,
keyHandlers,
keyMap,
levelEntitlements,
Expand All @@ -1287,6 +1297,7 @@ export default class Farmhand extends FarmhandReducers {
blockInput,
features,
fieldToolInventory,
isChatAvailable,
levelEntitlements,
plantableCropInventory,
playerInventory,
Expand Down Expand Up @@ -1424,6 +1435,7 @@ export default class Farmhand extends FarmhandReducers {
</Fab>
</Tooltip>
</div>
{isChatAvailable ? <ChatRoom /> : null}
<NotificationSystem />
</FarmhandContext.Provider>
</SnackbarProvider>
Expand Down
51 changes: 41 additions & 10 deletions src/components/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
inventorySpaceConsumed,
} from '../../utils'
import { dialogView } from '../../enums'
import { INFINITE_STORAGE_LIMIT, STAGE_TITLE_MAP } from '../../constants'
import {
DEFAULT_ROOM,
INFINITE_STORAGE_LIMIT,
STAGE_TITLE_MAP,
} from '../../constants'
import { MAX_ROOM_NAME_LENGTH } from '../../common/constants'

import AccountingView from '../AccountingView'
Expand Down Expand Up @@ -79,8 +83,10 @@ const FarmNameDisplay = ({ farmName, handleFarmNameUpdate }) => {
const OnlineControls = ({
activePlayers,
handleActivePlayerButtonClick,
handleChatRoomOpenStateChange,
handleOnlineToggleChange,
handleRoomChange,
isChatAvailable,
isOnline,
room,
}) => {
Expand All @@ -90,6 +96,10 @@ const OnlineControls = ({
setDisplayedRoom(room)
}, [room, setDisplayedRoom])

const handleChatButtonClick = () => {
handleChatRoomOpenStateChange(true)
}

return (
<>
<FormControl
Expand Down Expand Up @@ -133,15 +143,30 @@ const OnlineControls = ({
/>
</FormControl>
{activePlayers && (
<Button
{...{
color: 'primary',
onClick: handleActivePlayerButtonClick,
variant: 'contained',
}}
>
Active players: {integerString(activePlayers)}
</Button>
<>
<Button
{...{
color: 'primary',
onClick: handleActivePlayerButtonClick,
variant: 'contained',
}}
>
Active players: {integerString(activePlayers)}
</Button>
{isChatAvailable ? (
<Button
variant="contained"
color="primary"
onClick={handleChatButtonClick}
>
Open chat
</Button>
) : (
<Typography className="chat-placeholder">
Chat is available for online rooms other than "{DEFAULT_ROOM}"
</Typography>
)}
</>
)}
</>
)
Expand Down Expand Up @@ -203,6 +228,7 @@ export const Navigation = ({
currentDialogView,
farmName,
handleActivePlayerButtonClick,
handleChatRoomOpenStateChange,
handleClickDialogViewButton,
handleCloseDialogView,
handleDialogViewExited,
Expand All @@ -212,6 +238,7 @@ export const Navigation = ({
handleViewChange,
inventory,
inventoryLimit,
isChatAvailable,
isDialogViewOpen,
isOnline,
room,
Expand All @@ -231,8 +258,10 @@ export const Navigation = ({
{...{
activePlayers,
handleActivePlayerButtonClick,
handleChatRoomOpenStateChange,
handleOnlineToggleChange,
handleRoomChange,
isChatAvailable,
isOnline,
room,
}}
Expand Down Expand Up @@ -335,6 +364,7 @@ Navigation.propTypes = {
blockInput: bool.isRequired,
farmName: string.isRequired,
handleClickDialogViewButton: func.isRequired,
handleChatRoomOpenStateChange: func.isRequired,
handleActivePlayerButtonClick: func.isRequired,
handleCloseDialogView: func.isRequired,
handleDialogViewExited: func.isRequired,
Expand All @@ -344,6 +374,7 @@ Navigation.propTypes = {
handleViewChange: func.isRequired,
inventory: array.isRequired,
inventoryLimit: number.isRequired,
isChatAvailable: bool.isRequired,
isDialogViewOpen: bool.isRequired,
isOnline: bool.isRequired,
stageFocus: string.isRequired,
Expand Down
5 changes: 5 additions & 0 deletions src/components/Navigation/Navigation.sass
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@

.MuiSelect-select.MuiSelect-select
padding: 1em

.chat-placeholder
font-size: .75em
padding: .5em 0
text-align: center
Loading

1 comment on commit eca2881

@vercel
Copy link

@vercel vercel bot commented on eca2881 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.