Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Nov 8, 2024
1 parent 840f822 commit 9a08ba0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ function MapPlugin({ pinPoint, setPinPoint, answerShown, dest, gameOptions, ws,
useEffect(() => {
if (pinPoint) {
setTimeout(() => {
try {
const bounds = L.latLngBounds([pinPoint, { lat: dest.lat, lng: dest.long }]).pad(0.5);
map.flyToBounds(bounds, { duration: 0.5 });
} catch(e) {}
}, 300);
}
}, [answerShown]);
Expand Down
6 changes: 4 additions & 2 deletions components/chatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MessageParser = ({ children, actions }) => {
);
};

export default function ChatBox({ ws, open, onToggle, enabled, myId, inGame, miniMapShown }) {
export default function ChatBox({ ws, open, onToggle, enabled, myId, inGame, miniMapShown, isGuest }) {
const { t: text } = useTranslation("common");
const [unreadCount, setUnreadCount] = useState(0);

Expand All @@ -133,16 +133,18 @@ export default function ChatBox({ ws, open, onToggle, enabled, myId, inGame, min
}, [ws, open]);

return (
<div className={`chatboxParent ${enabled ? 'enabled' : ''}`}>
<div className={`chatboxParent ${enabled ? 'enabled' : ''} ${isGuest ? 'guest' : ''}`}>
<button className={`chatboxBtn ${open ? 'open' : ''} ${miniMapShown ? 'minimap' : ''}`} style={{ fontSize: '16px', fontWeight: 'bold', color: 'white', background: 'green', border: 'none', borderRadius: '5px', padding: '10px 20px', cursor: 'pointer' }} onClick={onToggle}>
{open ? <FaXmark onClick={onToggle} /> : `${text("chat")}${unreadCount > 0 ? ` (${unreadCount})` : ''}`}
</button>
<div className={`chatbox ${open ? 'open' : ''}`}>
<Chatbot
config={config}
placeholderText={isGuest ? "Please login to chat" : undefined}
messageParser={(props) => <MessageParser {...props} />}
actionProvider={(props) => <ActionProvider {...props} ws={ws} myId={myId} inGame={inGame} />}
validator={(input) => {
if(isGuest) return false;
if (input.length < 1) return false;
if (input.length > 200) return false;
if (Date.now() - lastSend < 1000) return false;
Expand Down
8 changes: 5 additions & 3 deletions components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,9 @@ setShowCountryButtons(false)

const ChatboxMemo = React.useMemo(() => <ChatBox miniMapShown={miniMapShown} ws={ws} open={multiplayerChatOpen} onToggle={() => setMultiplayerChatOpen(!multiplayerChatOpen)} enabled={
multiplayerChatEnabled
} myId={multiplayerState?.gameData?.myId} inGame={multiplayerState?.inGame} />, [multiplayerChatOpen, multiplayerChatEnabled, ws, multiplayerState?.gameData?.myId, multiplayerState?.inGame, miniMapShown])
}
isGuest={session?.token?.secret ? false : true}
myId={multiplayerState?.gameData?.myId} inGame={multiplayerState?.inGame} />, [multiplayerChatOpen, multiplayerChatEnabled, ws, multiplayerState?.gameData?.myId, multiplayerState?.inGame, miniMapShown, session?.token?.secret])

// Send pong every 10 seconds if websocket is connected
useEffect(() => {
Expand Down Expand Up @@ -1830,7 +1832,7 @@ setShowCountryButtons(false)
<main className={`home`} id="main">
{ latLong && latLong?.lat && latLong?.long && legacyMapLoader ? (
<>
<iframe className={`streetview ${(loading) ? 'hidden' : ''} ${false ? 'multiplayer' : ''} ${gameOptions?.nmpz ? 'nmpz' : ''}`} src={`https://www.google.com/maps/embed/v1/streetview?location=${latLong.lat},${latLong.long}&key=AIzaSyA2fHNuyc768n9ZJLTrfbkWLNK3sLOK-iQ&fov=90&language=iw`} id="streetview" referrerPolicy='no-referrer-when-downgrade' allow='accelerometer; autoplay; clipboard-write; encrypted-media; picture-in-picture' onLoad={() => {
<iframe className={`streetview ${(loading || (!((screen === "onboarding"&&!onboarding?.completed) || (screen === "singleplayer" && !singlePlayerRound?.done) || ["getready", "guess"].includes(multiplayerState?.gameData?.state)))) ? 'hidden' : ''} ${false ? 'multiplayer' : ''} ${gameOptions?.nmpz ? 'nmpz' : ''}`} src={`https://www.google.com/maps/embed/v1/streetview?location=${latLong.lat},${latLong.long}&key=AIzaSyA2fHNuyc768n9ZJLTrfbkWLNK3sLOK-iQ&fov=90&language=iw`} id="streetview" referrerPolicy='no-referrer-when-downgrade' allow='accelerometer; autoplay; clipboard-write; encrypted-media; picture-in-picture' onLoad={() => {

setTimeout(() => {
setLoading(false)
Expand Down Expand Up @@ -1881,7 +1883,7 @@ setTimeout(() => {
</>

) : (
<div id="googlemaps" className={`streetview inverted ${((!(latLong && multiplayerState?.gameData?.state !== 'end')) || (!streetViewShown || loading || (showAnswer && !showPanoOnResult) || (multiplayerState?.gameData?.state === 'getready') || !latLong)) ? 'hidden' : ''} ${false ? 'multiplayer' : ''} ${(gameOptions?.npz) ? 'nmpz' : ''}`}></div>
<div id="googlemaps" className={`streetview inverted ${(loading || (!((screen === "onboarding"&&!onboarding?.completed) || (screen === "singleplayer" && !singlePlayerRound?.done) || ["getready", "guess"].includes(multiplayerState?.gameData?.state)))) ? 'hidden' : ''} ${((!(latLong && multiplayerState?.gameData?.state !== 'end')) || (!streetViewShown || loading || (showAnswer && !showPanoOnResult) || (multiplayerState?.gameData?.state === 'getready') || !latLong)) ? 'hidden' : ''} ${false ? 'multiplayer' : ''} ${(gameOptions?.npz) ? 'nmpz' : ''}`}></div>
)}
<BannerText text={`${text("loading")}...`} shown={loading} showCompass={true} />

Expand Down
8 changes: 8 additions & 0 deletions styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,14 @@ screen and (pointer:coarse) {
border-radius: 10px;
height: calc(100% - 65px);
}
input[placeholder="Please login to chat"] {
// disable the div
cursor: not-allowed;
pointer-events: none;
background-color: rgba(225, 225, 225, 1) !important;
}


.react-chatbot-kit-chat-input-container {
border-radius: 10px;
}
Expand Down
3 changes: 2 additions & 1 deletion ws/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ app.ws('/wg', {
game.setGuess(player.id, latLong, final);
}

if (json.type === 'chat' && player.gameId && games.has(player.gameId)) {
if (json.type === 'chat' && player.gameId && games.has(player.gameId) && player.accountId) {

let message = json.message;
const lastMessage = player.lastMessage || 0;
if (typeof message !== 'string' || message.length < 1 || message.length > 200 || Date.now() - lastMessage < 500) {
Expand Down

0 comments on commit 9a08ba0

Please sign in to comment.