fix popup issues

This commit is contained in:
HF 2022-09-04 01:40:38 +02:00
parent c0ee7b3e0e
commit cd195c9692
16 changed files with 60 additions and 32 deletions

View File

@ -153,7 +153,7 @@ const Window = ({ id }) => {
title={t`Close`}
tabIndex={-1}
></div>
{(popUpTypes[windowType]) && (
{popUpTypes.includes(windowType) && (
<div
onClick={(evt) => {
openPopUp(
@ -224,7 +224,7 @@ const Window = ({ id }) => {
>
{windowTitle}
</span>
{(popUpTypes[windowType]) && (
{popUpTypes.includes(windowType) && (
<span
className="win-topbtn"
key="pobtnm"

View File

@ -15,6 +15,7 @@ import ChannelDropDown from '../contextmenus/ChannelDropDown';
import {
markChannelAsRead,
sendChatMessage,
} from '../../store/actions';
import {
showUserAreaModal,
@ -22,7 +23,6 @@ import {
import {
fetchChatMessages,
} from '../../store/actions/thunks';
import SocketClient from '../../socket/SocketClient';
const Chat = ({
@ -130,7 +130,7 @@ const Chat = ({
const inptMsg = inputRef.current.value.trim();
if (!inptMsg) return;
// send message via websocket
SocketClient.sendChatMessage(inptMsg, chatChannel);
dispatch(sendChatMessage(inptMsg, chatChannel));
inputRef.current.value = '';
}

View File

@ -9,9 +9,6 @@ import { t } from 'ttag';
import {
fetchStats,
} from '../../store/actions/thunks';
import {
setWindowArgs,
} from '../../store/actions/windows';
import useInterval from '../hooks/interval';
import LogInArea from '../LogInArea';
import Tabs from '../Tabs';
@ -23,20 +20,20 @@ const Converter = React.lazy(() => import(/* webpackChunkName: "converter" */ '.
// eslint-disable-next-line max-len
const Modtools = React.lazy(() => import(/* webpackChunkName: "modtools" */ '../Modtools'));
const UserArea = ({ windowId }) => {
const UserArea = ({ args, setArgs, setTitle }) => {
const name = useSelector((state) => state.user.name);
const userlvl = useSelector((state) => state.user.userlvl);
const lastStatsFetch = useSelector((state) => state.ranks.lastFetch);
const {
activeTab = t`Profile`,
} = useSelector((state) => state.windows.args[windowId] || {});
} = args;
const dispatch = useDispatch();
const setActiveTab = useCallback((label) => {
dispatch(setWindowArgs(windowId, {
setArgs({
activeTab: label,
}));
}, [dispatch]);
});
}, [setArgs]);
useInterval(() => {
if (Date.now() - 300000 > lastStatsFetch) {
@ -48,7 +45,7 @@ const UserArea = ({ windowId }) => {
<div style={{ textAlign: 'center' }}>
<Tabs activeTab={activeTab} setActiveTab={setActiveTab}>
<div label={t`Profile`}>
{(name) ? <UserAreaContent /> : <LogInArea windowId={windowId} />}
{(name) ? <UserAreaContent /> : <LogInArea windowId="1" />}
</div>
<div label={t`Ranking`}>
<Rankings />

View File

@ -7,14 +7,17 @@ export const argsTypes = {
CHAT: ['chatChannel'],
};
export function buildPopUpUrl(windowType, args) {
export function buildPopUpUrl(windowType, argsIn) {
const args = { ...argsIn };
let path = `/${windowType.toLowerCase()}`;
const typeArr = argsTypes[windowType];
for (let i = 0; i < typeArr.length; i += 1) {
const key = typeArr[i];
if (args[key]) {
path += `/${args[key]}`;
delete args[key];
if (typeArr) {
for (let i = 0; i < typeArr.length; i += 1) {
const key = typeArr[i];
if (args[key]) {
path += `/${args[key]}`;
delete args[key];
}
}
}
let searchParams = new URLSearchParams();

View File

@ -52,7 +52,7 @@ function generatePopUpPage(lang) {
<html lang="${lang}">
<head>
<meta charset="UTF-8" />
<title>${t`PixelPlanet.Fun PopUp`}</title>
<title>${t`ppfun`}</title>
<meta name="description" content="${t`PixelPlanet.Fun PopUp`}" />
<meta name="google" content="nopagereadaloud" />
<meta name="theme-color" content="#cae3ff" />

View File

@ -147,7 +147,7 @@ export function selectColor(color) {
export function selectCanvas(canvasId) {
return {
type: 'SELECT_CANVAS',
type: 's/SELECT_CANVAS',
canvasId,
};
}
@ -286,6 +286,17 @@ export function receiveOnline(online) {
};
}
export function sendChatMessage(
text,
channel,
) {
return {
type: 's/REQ_CHAT_MESSAGE',
text,
channel,
};
}
export function receiveChatMessage(
name,
text,
@ -463,7 +474,7 @@ export function muteChatChannel(cid) {
export function unmuteChatChannel(cid) {
return {
type: 'UNs/MUTE_CHAT_CHANNEL',
type: 's/UNMUTE_CHAT_CHANNEL',
cid,
};
}

View File

@ -156,7 +156,7 @@ export function cloneWindow(windowId) {
export function toggleMaximizeWindow(windowId) {
return {
type: 's/TGL_MAXIMIZE_WIN',
type: 'TGL_MAXIMIZE_WIN',
windowId,
};
}

View File

@ -10,7 +10,7 @@ const pixelPlanetEvents = new EventEmitter();
export default () => (next) => (action) => {
switch (action.type) {
case 'SELECT_CANVAS': {
case 's/SELECT_CANVAS': {
pixelPlanetEvents.emit('selectcanvas', action.canvasId);
break;
}

View File

@ -48,7 +48,7 @@ export default (store) => (next) => (action) => {
switch (type) {
case 'RELOAD_URL':
case 'SELECT_CANVAS':
case 's/SELECT_CANVAS':
case 'REC_ME': {
const renderer = getRenderer();
const { is3D } = state.canvas;

View File

@ -32,6 +32,15 @@ export default (store) => (next) => (action) => {
break;
}
case 's/REQ_CHAT_MESSAGE': {
const {
text,
channel,
} = action;
SocketClient.sendChatMessage(text, channel);
break;
}
default:
// nothing
}
@ -41,7 +50,7 @@ export default (store) => (next) => (action) => {
// executed after reducers
switch (action.type) {
case 'RELOAD_URL':
case 'SELECT_CANVAS':
case 's/SELECT_CANVAS':
case 'REC_ME': {
const state = store.getState();
const { canvasId } = state.canvas;

View File

@ -40,7 +40,7 @@ export default (store) => (next) => (action) => {
}
case 'SELECT_CANVAS':
case 's/SELECT_CANVAS':
case 'REC_ME':
case 'RELOAD_URL':
case 'ON_VIEW_FINISH_CHANGE': {

View File

@ -278,7 +278,7 @@ export default function canvasReducer(
};
}
case 'SELECT_CANVAS': {
case 's/SELECT_CANVAS': {
let { canvasId } = action;
const { canvases, prevCanvasCoords, canvasId: prevCanvasId } = state;
let canvas = canvases[canvasId];

View File

@ -142,7 +142,7 @@ export default function chatRead(
};
}
case 'UNs/MUTE_CHAT_CHANNEL': {
case 's/UNMUTE_CHAT_CHANNEL': {
const { cid } = action;
const mute = state.mute.filter((id) => (id !== cid));
return {

View File

@ -409,7 +409,7 @@ export default function windows(
});
}
case 's/TGL_MAXIMIZE_WIN': {
case 'TGL_MAXIMIZE_WIN': {
const {
windowId,
} = action;

View File

@ -2,6 +2,6 @@
* selectors for single window / popup
*/
export const selectWindowType = (state) => state.win.windowType;
export const selectWindowType = (state) => state.popup.windowType;
export const selectWIndowArgs = (state) => state.win.args;
export const selectWIndowArgs = (state) => state.popup.args;

View File

@ -16,16 +16,23 @@ import { persistStore } from 'redux-persist';
import sharedReducers from './sharedReducers';
import canvas from './reducers/canvas';
import popup from './reducers/popup';
import user from './reducers/user';
import chat from './reducers/chat';
import fetching from './reducers/fetching';
/*
* middleware
*/
import parent from './middleware/parent';
import titlePopUp from './middleware/titlePopUp';
const reducers = combineReducers({
...sharedReducers,
canvas,
popup,
user,
chat,
fetching,
});
const store = createStore(
@ -33,6 +40,7 @@ const store = createStore(
applyMiddleware(
thunk,
parent,
titlePopUp,
),
);