diff --git a/src/client.js b/src/client.js
index 49fa72e..b7df02d 100644
--- a/src/client.js
+++ b/src/client.js
@@ -17,7 +17,7 @@ import {
removeChatChannel,
setMobile,
windowResize,
-} from './actions';
+} from './store/actions';
import {
receivePixelUpdate,
receivePixelReturn,
diff --git a/src/components/Alert.jsx b/src/components/Alert.jsx
index 41ff687..89be7a9 100644
--- a/src/components/Alert.jsx
+++ b/src/components/Alert.jsx
@@ -7,7 +7,7 @@ import React, { useState, useEffect, useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import GlobalCaptcha from './GlobalCaptcha';
-import { closeAlert } from '../actions';
+import { closeAlert } from '../store/actions';
const Alert = () => {
const [render, setRender] = useState(false);
diff --git a/src/components/ChangeMail.jsx b/src/components/ChangeMail.jsx
index a69457b..3a81a8f 100644
--- a/src/components/ChangeMail.jsx
+++ b/src/components/ChangeMail.jsx
@@ -9,7 +9,7 @@ import { t } from 'ttag';
import {
validateEMail, validatePassword,
} from '../utils/validation';
-import { requestMailChange } from '../actions/fetch';
+import { requestMailChange } from '../store/actions/fetch';
function validate(email, password) {
const errors = [];
diff --git a/src/components/ChangeName.jsx b/src/components/ChangeName.jsx
index 56b57fa..23a4548 100644
--- a/src/components/ChangeName.jsx
+++ b/src/components/ChangeName.jsx
@@ -8,8 +8,8 @@ import { t } from 'ttag';
import { useDispatch } from 'react-redux';
import { validateName } from '../utils/validation';
-import { requestNameChange } from '../actions/fetch';
-import { setName } from '../actions';
+import { requestNameChange } from '../store/actions/fetch';
+import { setName } from '../store/actions';
function validate(name) {
diff --git a/src/components/ChangePassword.jsx b/src/components/ChangePassword.jsx
index 207dcd0..90f2d2b 100644
--- a/src/components/ChangePassword.jsx
+++ b/src/components/ChangePassword.jsx
@@ -7,9 +7,9 @@ import React, { useState } from 'react';
import { t } from 'ttag';
import { useSelector, useDispatch } from 'react-redux';
-import { setMailreg } from '../actions';
+import { setMailreg } from '../store/actions';
import { validatePassword } from '../utils/validation';
-import { requestPasswordChange } from '../actions/fetch';
+import { requestPasswordChange } from '../store/actions/fetch';
function validate(mailreg, password, newPassword, confirmPassword) {
const errors = [];
diff --git a/src/components/ChatMessage.jsx b/src/components/ChatMessage.jsx
index f94bd42..ade0f8b 100644
--- a/src/components/ChatMessage.jsx
+++ b/src/components/ChatMessage.jsx
@@ -5,7 +5,7 @@
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
-import { showContextMenu } from '../actions';
+import { showContextMenu } from '../store/actions';
import { MarkdownParagraph } from './Markdown';
import {
colorFromText,
diff --git a/src/components/CoordinatesBox.jsx b/src/components/CoordinatesBox.jsx
index bf47b97..f7d4b0a 100644
--- a/src/components/CoordinatesBox.jsx
+++ b/src/components/CoordinatesBox.jsx
@@ -8,7 +8,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { t } from 'ttag';
import copy from '../utils/clipboard';
-import { notify } from '../actions';
+import { notify } from '../store/actions';
function renderCoordinates(cell): string {
diff --git a/src/components/DeleteAccount.jsx b/src/components/DeleteAccount.jsx
index 141c913..7dfc6f4 100644
--- a/src/components/DeleteAccount.jsx
+++ b/src/components/DeleteAccount.jsx
@@ -8,8 +8,8 @@ import { useDispatch } from 'react-redux';
import { t } from 'ttag';
import { validatePassword } from '../utils/validation';
-import { requestDeleteAccount } from '../actions/fetch';
-import { logoutUser } from '../actions';
+import { requestDeleteAccount } from '../store/actions/fetch';
+import { logoutUser } from '../store/actions';
function validate(password) {
const errors = [];
diff --git a/src/components/GlobalCaptcha.jsx b/src/components/GlobalCaptcha.jsx
index c79815e..558b358 100644
--- a/src/components/GlobalCaptcha.jsx
+++ b/src/components/GlobalCaptcha.jsx
@@ -8,7 +8,7 @@ import React, { useState } from 'react';
import { t } from 'ttag';
import Captcha from './Captcha';
-import { requestSolveCaptcha } from '../actions/fetch';
+import { requestSolveCaptcha } from '../store/actions/fetch';
const GlobalCaptcha = ({ close }) => {
const [errors, setErrors] = useState([]);
diff --git a/src/components/HistorySelect.jsx b/src/components/HistorySelect.jsx
index a42c60a..dba2693 100644
--- a/src/components/HistorySelect.jsx
+++ b/src/components/HistorySelect.jsx
@@ -9,8 +9,8 @@ import { useSelector, shallowEqual, useDispatch } from 'react-redux';
import { t } from 'ttag';
import { dateToString, getToday } from '../core/utils';
-import { selectHistoricalTime } from '../actions';
-import { requestHistoricalTimes } from '../actions/fetch';
+import { selectHistoricalTime } from '../store/actions';
+import { requestHistoricalTimes } from '../store/actions/fetch';
function stringToDate(dateString) {
diff --git a/src/components/LogInArea.jsx b/src/components/LogInArea.jsx
index b9a5538..a596815 100644
--- a/src/components/LogInArea.jsx
+++ b/src/components/LogInArea.jsx
@@ -6,7 +6,7 @@ import { useDispatch } from 'react-redux';
import { t } from 'ttag';
import LogInForm from './LogInForm';
-import { changeWindowType } from '../actions';
+import { changeWindowType } from '../store/actions';
const logoStyle = {
marginRight: 5,
diff --git a/src/components/LogInForm.jsx b/src/components/LogInForm.jsx
index 8a6c129..99b4a40 100644
--- a/src/components/LogInForm.jsx
+++ b/src/components/LogInForm.jsx
@@ -9,8 +9,8 @@ import { t } from 'ttag';
import {
validateEMail, validateName, validatePassword,
} from '../utils/validation';
-import { requestLogin } from '../actions/fetch';
-import { loginUser } from '../actions';
+import { requestLogin } from '../store/actions/fetch';
+import { loginUser } from '../store/actions';
function validate(nameoremail, password) {
diff --git a/src/components/ModalRoot.jsx b/src/components/ModalRoot.jsx
index b7a698c..cd5ec8c 100644
--- a/src/components/ModalRoot.jsx
+++ b/src/components/ModalRoot.jsx
@@ -14,7 +14,7 @@ import {
closeWindow,
restoreWindow,
removeWindow,
-} from '../actions';
+} from '../store/actions';
import COMPONENTS from './windows';
const ModalRoot = () => {
diff --git a/src/components/OnlineBox.jsx b/src/components/OnlineBox.jsx
index 894d984..8b6e4df 100644
--- a/src/components/OnlineBox.jsx
+++ b/src/components/OnlineBox.jsx
@@ -8,7 +8,7 @@ import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { FaUser, FaPaintBrush, FaFlipboard } from 'react-icons/fa';
import { t } from 'ttag';
-import { toggleOnlineCanvas } from '../actions';
+import { toggleOnlineCanvas } from '../store/actions';
import { numberToString } from '../core/utils';
diff --git a/src/components/Palette.jsx b/src/components/Palette.jsx
index be5d850..3d7550d 100644
--- a/src/components/Palette.jsx
+++ b/src/components/Palette.jsx
@@ -6,7 +6,7 @@
import React, { useState, useEffect } from 'react';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
-import { selectColor } from '../actions';
+import { selectColor } from '../store/actions';
import useWindowSize from './hooks/resize';
diff --git a/src/components/SocialSettings.jsx b/src/components/SocialSettings.jsx
index 148abd4..2e91adc 100644
--- a/src/components/SocialSettings.jsx
+++ b/src/components/SocialSettings.jsx
@@ -10,7 +10,7 @@ import { t } from 'ttag';
import {
setBlockingDm,
setUserBlock,
-} from '../actions';
+} from '../store/actions';
import MdToggleButton from './MdToggleButton';
const SocialSettings = ({ done }) => {
diff --git a/src/components/UserAreaContent.jsx b/src/components/UserAreaContent.jsx
index 072b5f8..2f83f94 100644
--- a/src/components/UserAreaContent.jsx
+++ b/src/components/UserAreaContent.jsx
@@ -13,8 +13,8 @@ import ChangeName from './ChangeName';
import ChangeMail from './ChangeMail';
import DeleteAccount from './DeleteAccount';
import SocialSettings from './SocialSettings';
-import { logoutUser } from '../actions';
-import { requestLogOut } from '../actions/fetch';
+import { logoutUser } from '../store/actions';
+import { requestLogOut } from '../store/actions/fetch';
import { numberToString } from '../core/utils';
diff --git a/src/components/UserMessages.jsx b/src/components/UserMessages.jsx
index d644c0c..69241f2 100644
--- a/src/components/UserMessages.jsx
+++ b/src/components/UserMessages.jsx
@@ -6,7 +6,7 @@ import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { t } from 'ttag';
-import { requestResendVerify } from '../actions/fetch';
+import { requestResendVerify } from '../store/actions/fetch';
const UserMessages = () => {
diff --git a/src/components/Window.jsx b/src/components/Window.jsx
index e5b1ec1..e10f00a 100644
--- a/src/components/Window.jsx
+++ b/src/components/Window.jsx
@@ -17,7 +17,7 @@ import {
maximizeWindow,
cloneWindow,
focusWindow,
-} from '../actions';
+} from '../store/actions';
import useDrag from './hooks/drag';
import COMPONENTS from './windows';
@@ -153,7 +153,7 @@ const Window = ({ id }) => {
>
▨
-
diff --git a/src/components/buttons/CanvasSwitchButton.jsx b/src/components/buttons/CanvasSwitchButton.jsx
index b8f7b31..ed58df6 100644
--- a/src/components/buttons/CanvasSwitchButton.jsx
+++ b/src/components/buttons/CanvasSwitchButton.jsx
@@ -7,7 +7,7 @@ import { useDispatch } from 'react-redux';
import { FaFlipboard } from 'react-icons/fa';
import { t } from 'ttag';
-import { showCanvasSelectionModal } from '../../actions';
+import { showCanvasSelectionModal } from '../../store/actions';
const CanvasSwitchButton = () => {
diff --git a/src/components/buttons/ChatButton.jsx b/src/components/buttons/ChatButton.jsx
index 13b3f89..d9900d7 100644
--- a/src/components/buttons/ChatButton.jsx
+++ b/src/components/buttons/ChatButton.jsx
@@ -13,7 +13,7 @@ import { t } from 'ttag';
import {
hideAllWindowTypes,
openChatWindow,
-} from '../../actions';
+} from '../../store/actions';
/*
* return [ showWindows, chatOpen, chatHiden ]
diff --git a/src/components/buttons/ExpandMenuButton.jsx b/src/components/buttons/ExpandMenuButton.jsx
index bfc181e..357fa50 100644
--- a/src/components/buttons/ExpandMenuButton.jsx
+++ b/src/components/buttons/ExpandMenuButton.jsx
@@ -9,7 +9,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { MdExpandMore, MdExpandLess } from 'react-icons/md';
import { t } from 'ttag';
-import { toggleOpenMenu } from '../../actions';
+import { toggleOpenMenu } from '../../store/actions';
const ExpandMenuButton = () => {
const menuOpen = useSelector((state) => state.gui.menuOpen);
diff --git a/src/components/buttons/HelpButton.jsx b/src/components/buttons/HelpButton.jsx
index b0a7f8d..55122ee 100644
--- a/src/components/buttons/HelpButton.jsx
+++ b/src/components/buttons/HelpButton.jsx
@@ -8,7 +8,7 @@ import { useDispatch } from 'react-redux';
import { FaQuestion } from 'react-icons/fa';
import { t } from 'ttag';
-import { showHelpModal } from '../../actions';
+import { showHelpModal } from '../../store/actions';
const HelpButton = () => {
diff --git a/src/components/buttons/LogInButton.jsx b/src/components/buttons/LogInButton.jsx
index c76393d..39c99ce 100644
--- a/src/components/buttons/LogInButton.jsx
+++ b/src/components/buttons/LogInButton.jsx
@@ -8,7 +8,7 @@ import { useDispatch } from 'react-redux';
import { MdPerson } from 'react-icons/md';
import { t } from 'ttag';
-import { showUserAreaModal } from '../../actions';
+import { showUserAreaModal } from '../../store/actions';
const LogInButton = () => {
diff --git a/src/components/buttons/PalselButton.jsx b/src/components/buttons/PalselButton.jsx
index 9ad1e2f..6abe338 100644
--- a/src/components/buttons/PalselButton.jsx
+++ b/src/components/buttons/PalselButton.jsx
@@ -9,7 +9,7 @@ import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { MdPalette } from 'react-icons/md';
import { t } from 'ttag';
-import { toggleOpenPalette } from '../../actions';
+import { toggleOpenPalette } from '../../store/actions';
const PalselButton = () => {
const paletteOpen = useSelector((state) => state.gui.paletteOpen);
diff --git a/src/components/buttons/SettingsButton.jsx b/src/components/buttons/SettingsButton.jsx
index 15fe84e..b649319 100644
--- a/src/components/buttons/SettingsButton.jsx
+++ b/src/components/buttons/SettingsButton.jsx
@@ -8,7 +8,7 @@ import { useDispatch } from 'react-redux';
import { FaCog } from 'react-icons/fa';
import { t } from 'ttag';
-import { showSettingsModal } from '../../actions';
+import { showSettingsModal } from '../../store/actions';
const SettingsButton = () => {
diff --git a/src/components/contextmenus/ChannelContextMenu.jsx b/src/components/contextmenus/ChannelContextMenu.jsx
index 1008417..98baf83 100644
--- a/src/components/contextmenus/ChannelContextMenu.jsx
+++ b/src/components/contextmenus/ChannelContextMenu.jsx
@@ -15,7 +15,7 @@ import {
setLeaveChannel,
muteChatChannel,
unmuteChatChannel,
-} from '../../actions';
+} from '../../store/actions';
const ChannelContextMenu = () => {
const wrapperRef = useRef(null);
diff --git a/src/components/contextmenus/UserContextMenu.jsx b/src/components/contextmenus/UserContextMenu.jsx
index 4422e99..c8bcba4 100644
--- a/src/components/contextmenus/UserContextMenu.jsx
+++ b/src/components/contextmenus/UserContextMenu.jsx
@@ -16,7 +16,7 @@ import {
startDm,
setUserBlock,
setChatChannel,
-} from '../../actions';
+} from '../../store/actions';
import { escapeMd } from '../../core/utils';
const UserContextMenu = () => {
diff --git a/src/components/windows/CanvasSelect.jsx b/src/components/windows/CanvasSelect.jsx
index 99450d8..d1c0cf7 100644
--- a/src/components/windows/CanvasSelect.jsx
+++ b/src/components/windows/CanvasSelect.jsx
@@ -8,7 +8,7 @@ import { useDispatch, useSelector, shallowEqual } from 'react-redux';
import { t } from 'ttag';
import CanvasItem from '../CanvasItem';
-import { changeWindowType, selectCanvas } from '../../actions';
+import { changeWindowType, selectCanvas } from '../../store/actions';
const CanvasSelect = ({ windowId }) => {
diff --git a/src/components/windows/Chat.jsx b/src/components/windows/Chat.jsx
index f4f9b89..72492a3 100644
--- a/src/components/windows/Chat.jsx
+++ b/src/components/windows/Chat.jsx
@@ -20,7 +20,7 @@ import {
fetchChatMessages,
showContextMenu,
setWindowTitle,
-} from '../../actions';
+} from '../../store/actions';
import SocketClient from '../../socket/SocketClient';
diff --git a/src/components/windows/ForgotPassword.jsx b/src/components/windows/ForgotPassword.jsx
index 052b5ef..0b8be28 100644
--- a/src/components/windows/ForgotPassword.jsx
+++ b/src/components/windows/ForgotPassword.jsx
@@ -6,9 +6,9 @@ import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { t } from 'ttag';
-import { changeWindowType } from '../../actions';
+import { changeWindowType } from '../../store/actions';
import { validateEMail } from '../../utils/validation';
-import { requestNewPassword } from '../../actions/fetch';
+import { requestNewPassword } from '../../store/actions/fetch';
function validate(email) {
const errors = [];
diff --git a/src/components/windows/Register.jsx b/src/components/windows/Register.jsx
index 9362d78..de588a6 100644
--- a/src/components/windows/Register.jsx
+++ b/src/components/windows/Register.jsx
@@ -10,9 +10,9 @@ import Captcha from '../Captcha';
import {
validateEMail, validateName, validatePassword,
} from '../../utils/validation';
-import { requestRegistration } from '../../actions/fetch';
+import { requestRegistration } from '../../store/actions/fetch';
-import { changeWindowType, loginUser } from '../../actions';
+import { changeWindowType, loginUser } from '../../store/actions';
function validate(name, email, password, confirmPassword) {
diff --git a/src/components/windows/Settings.jsx b/src/components/windows/Settings.jsx
index 761e457..4415d7c 100644
--- a/src/components/windows/Settings.jsx
+++ b/src/components/windows/Settings.jsx
@@ -20,7 +20,7 @@ import {
toggleLightGrid,
toggleHistoricalView,
selectStyle,
-} from '../../actions';
+} from '../../store/actions';
const flexy = {
diff --git a/src/components/windows/UserArea.jsx b/src/components/windows/UserArea.jsx
index 67dee37..eef9cc7 100644
--- a/src/components/windows/UserArea.jsx
+++ b/src/components/windows/UserArea.jsx
@@ -7,7 +7,7 @@ import React, { Suspense } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { t } from 'ttag';
-import { fetchStats } from '../../actions';
+import { fetchStats } from '../../store/actions';
import useInterval from '../hooks/interval';
import LogInArea from '../LogInArea';
import Tabs from '../Tabs';
diff --git a/src/controls/PixelPainterControls.js b/src/controls/PixelPainterControls.js
index cac5fb9..ee510ce 100644
--- a/src/controls/PixelPainterControls.js
+++ b/src/controls/PixelPainterControls.js
@@ -20,7 +20,7 @@ import {
moveSouth,
moveEast,
onViewFinishChange,
-} from '../actions';
+} from '../store/actions';
import {
tryPlacePixel,
} from '../ui/placePixel';
diff --git a/src/controls/VoxelPainterControls.js b/src/controls/VoxelPainterControls.js
index 68f056a..4e1bfcf 100644
--- a/src/controls/VoxelPainterControls.js
+++ b/src/controls/VoxelPainterControls.js
@@ -27,7 +27,7 @@ import {
import {
onViewFinishChange,
setViewCoordinates,
-} from '../actions';
+} from '../store/actions';
import {
THREE_CANVAS_HEIGHT,
} from '../core/constants';
diff --git a/src/controls/keypress.js b/src/controls/keypress.js
index 8272237..9501a52 100644
--- a/src/controls/keypress.js
+++ b/src/controls/keypress.js
@@ -1,6 +1,5 @@
/*
* keypress actions
- * @flow
*/
import { t } from 'ttag';
import store from '../ui/store';
@@ -13,11 +12,11 @@ import {
toggleMute,
notify,
selectCanvas,
-} from '../actions';
+} from '../store/actions';
const usedKeys = ['g', 'h', 'x', 'm', 'r', 'p'];
-function onKeyPress(event: KeyboardEvent) {
+function onKeyPress(event) {
// ignore key presses if modal is open or chat is used
if (event.target.nodeName === 'INPUT'
|| event.target.nodeName === 'TEXTAREA'
diff --git a/src/store/README.md b/src/store/README.md
new file mode 100644
index 0000000..75d161d
--- /dev/null
+++ b/src/store/README.md
@@ -0,0 +1,3 @@
+# Store
+We use redux as a state manager of our application:
+https://redux.js.org/
diff --git a/src/actions/fetch.js b/src/store/actions/fetch.js
similarity index 99%
rename from src/actions/fetch.js
rename to src/store/actions/fetch.js
index e29ee95..39fecd0 100644
--- a/src/actions/fetch.js
+++ b/src/store/actions/fetch.js
@@ -6,7 +6,7 @@
import { t } from 'ttag';
-import { dateToString } from '../core/utils';
+import { dateToString } from '../../core/utils';
/*
* Adds customizeable timeout to fetch
diff --git a/src/actions/index.js b/src/store/actions/index.js
similarity index 100%
rename from src/actions/index.js
rename to src/store/actions/index.js
diff --git a/src/actions/types.js b/src/store/actions/types.js
similarity index 100%
rename from src/actions/types.js
rename to src/store/actions/types.js
diff --git a/src/store/array.js b/src/store/array.js
deleted file mode 100644
index 5c56ab1..0000000
--- a/src/store/array.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Copyright 2016 Facebook, Inc.
- *
- * You are hereby granted a non-exclusive, worldwide, royalty-free license to
- * use, copy, modify, and distribute this software in source code or binary
- * form for use in connection with the web services and APIs provided by
- * Facebook.
- *
- * As with any software that integrates with the Facebook platform, your use
- * of this software is subject to the Facebook Developer Principles and
- * Policies [http://developers.facebook.com/policy/]. This copyright notice
- * shall be included in all copies or substantial portions of the software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE
- */
-
-export default () => (next) => (action) => (Array.isArray(action)
- ? action.map(next)
- : next(action));
diff --git a/src/store/configureStore.js b/src/store/configureStore.js
index 5ecd227..90c22b0 100644
--- a/src/store/configureStore.js
+++ b/src/store/configureStore.js
@@ -1,20 +1,18 @@
-/* @flow */
-
import { applyMiddleware, createStore, compose } from 'redux';
import thunk from 'redux-thunk';
import { persistStore } from 'redux-persist';
-import audio from './audio';
-import socketClientHook from './socketClientHook';
-import rendererHook from './rendererHook';
+import audio from './middleware/audio';
+import socketClientHook from './middleware/socketClientHook';
+import rendererHook from './middleware/rendererHook';
// import ads from './ads';
-import array from './array';
-import promise from './promise';
-import notifications from './notifications';
-import title from './title';
-import placePixelControl from './placePixelControl';
-import extensions from './extensions';
-import reducers from '../reducers';
+import array from './middleware/array';
+import promise from './middleware/promise';
+import notifications from './middleware/notifications';
+import title from './middleware/title';
+import placePixelControl from './middleware/placePixelControl';
+import extensions from './middleware/extensions';
+import reducers from './reducers';
const store = createStore(
@@ -37,9 +35,11 @@ const store = createStore(
);
-export default function configureStore(onComplete: ?() => void) {
+export default function configureStore(onComplete) {
persistStore(store, null, () => {
- onComplete(store);
+ if (onComplete) {
+ onComplete(store);
+ }
});
return store;
}
diff --git a/src/store/middleware/array.js b/src/store/middleware/array.js
new file mode 100644
index 0000000..4cbc793
--- /dev/null
+++ b/src/store/middleware/array.js
@@ -0,0 +1,7 @@
+/*
+ * consume array of actions
+ */
+
+export default () => (next) => (action) => (Array.isArray(action)
+ ? action.map(next)
+ : next(action));
diff --git a/src/store/audio.js b/src/store/middleware/audio.js
similarity index 99%
rename from src/store/audio.js
rename to src/store/middleware/audio.js
index 7777065..7e3bc5f 100644
--- a/src/store/audio.js
+++ b/src/store/middleware/audio.js
@@ -1,8 +1,6 @@
-/* @flow
- *
- * play sounds using the HTML5 AudoContext
- *
- * */
+/*
+ * play sounds using the HTML5 AudoContext
+ */
// iPhone needs this
diff --git a/src/store/extensions.js b/src/store/middleware/extensions.js
similarity index 99%
rename from src/store/extensions.js
rename to src/store/middleware/extensions.js
index 83d83ab..5b540e6 100644
--- a/src/store/extensions.js
+++ b/src/store/middleware/extensions.js
@@ -2,7 +2,6 @@
* sends events via window.pixelPlanetEvents to potential
* Extensions and Userscripts
*
- * @flow
*/
import EventEmitter from 'events';
diff --git a/src/store/notifications.js b/src/store/middleware/notifications.js
similarity index 100%
rename from src/store/notifications.js
rename to src/store/middleware/notifications.js
diff --git a/src/store/placePixelControl.js b/src/store/middleware/placePixelControl.js
similarity index 80%
rename from src/store/placePixelControl.js
rename to src/store/middleware/placePixelControl.js
index b54f6f1..a4ed170 100644
--- a/src/store/placePixelControl.js
+++ b/src/store/middleware/placePixelControl.js
@@ -1,10 +1,9 @@
/*
* Hooks for placePixel
*
- * @flow
*/
-import { requestFromQueue } from '../ui/placePixel';
+import { requestFromQueue } from '../../ui/placePixel';
export default (store) => (next) => (action) => {
switch (action.type) {
diff --git a/src/store/middleware/promise.js b/src/store/middleware/promise.js
new file mode 100644
index 0000000..5b1816a
--- /dev/null
+++ b/src/store/middleware/promise.js
@@ -0,0 +1,13 @@
+/*
+ * consume async function as action
+ */
+
+function warn(error) {
+ // eslint-disable-next-line no-console
+ console.warn(error.message || error);
+ throw error; // To let the caller handle the rejection
+}
+
+export default () => (next) => (action) => (typeof action.then === 'function'
+ ? Promise.resolve(action).then(next, warn)
+ : next(action));
diff --git a/src/store/rendererHook.js b/src/store/middleware/rendererHook.js
similarity index 86%
rename from src/store/rendererHook.js
rename to src/store/middleware/rendererHook.js
index 28bc172..6195a82 100644
--- a/src/store/rendererHook.js
+++ b/src/store/middleware/rendererHook.js
@@ -3,25 +3,13 @@
*
*/
-/*
- * set theme-color meta tag that sets the color
- * of address bars on phones
- */
/*
* hooks for rendering
*/
import {
getRenderer,
initRenderer,
-} from '../ui/renderer';
-
-
-function setThemeColorMeta(r, g, b) {
- const metaThemeColor = document.querySelector('meta[name=theme-color]');
- if (metaThemeColor) {
- metaThemeColor.setAttribute('content', `rgb(${r}, ${g}, ${b})`);
- }
-}
+} from '../../ui/renderer';
export default (store) => (next) => (action) => {
const { type } = action;
@@ -63,10 +51,7 @@ export default (store) => (next) => (action) => {
case 'SELECT_CANVAS':
case 'RECEIVE_ME': {
const renderer = getRenderer();
- const { is3D, palette } = state.canvas;
-
- const [r, g, b] = palette.rgb;
- setThemeColorMeta(r, g, b);
+ const { is3D } = state.canvas;
if (is3D === renderer.is3D) {
renderer.updateCanvasData(state);
diff --git a/src/store/socketClientHook.js b/src/store/middleware/socketClientHook.js
similarity index 93%
rename from src/store/socketClientHook.js
rename to src/store/middleware/socketClientHook.js
index 17b022b..9b4e61b 100644
--- a/src/store/socketClientHook.js
+++ b/src/store/middleware/socketClientHook.js
@@ -1,10 +1,9 @@
/*
* Hooks for websocket client to store changes
*
- * @flow
*/
-import SocketClient from '../socket/SocketClient';
+import SocketClient from '../../socket/SocketClient';
export default (store) => (next) => (action) => {
switch (action.type) {
diff --git a/src/store/title.js b/src/store/middleware/title.js
similarity index 65%
rename from src/store/title.js
rename to src/store/middleware/title.js
index 578fa14..cd40ccd 100644
--- a/src/store/title.js
+++ b/src/store/middleware/title.js
@@ -1,12 +1,21 @@
/**
- *
- * @flow
+ * set URL in adress bar, theme-color and title
*/
import {
durationToString,
-} from '../core/utils';
+} from '../../core/utils';
+/*
+ * set theme-color meta tag that sets the color
+ * of address bars on phones
+ */
+function setThemeColorMeta(r, g, b) {
+ const metaThemeColor = document.querySelector('meta[name=theme-color]');
+ if (metaThemeColor) {
+ metaThemeColor.setAttribute('content', `rgb(${r}, ${g}, ${b})`);
+ }
+}
const TITLE = 'PixelPlanet.fun';
@@ -35,12 +44,20 @@ export default (store) => (next) => (action) => {
case 'RECEIVE_ME':
case 'RELOAD_URL':
case 'ON_VIEW_FINISH_CHANGE': {
+ const state = store.getState();
+
const {
view,
viewscale,
canvasIdent,
is3D,
- } = store.getState().canvas;
+ } = state.canvas;
+
+ if (action.type !== 'ON_VIEW_FINISH_CHANGE') {
+ const [r, g, b] = state.canvas.palette.rgb;
+ setThemeColorMeta(r, g, b);
+ }
+
const coords = view.map((u) => Math.round(u)).join(',');
let newhash = `#${canvasIdent},${coords}`;
if (!is3D) {
diff --git a/src/store/promise.js b/src/store/promise.js
deleted file mode 100644
index ef5b91e..0000000
--- a/src/store/promise.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright 2016 Facebook, Inc.
- *
- * You are hereby granted a non-exclusive, worldwide, royalty-free license to
- * use, copy, modify, and distribute this software in source code or binary
- * form for use in connection with the web services and APIs provided by
- * Facebook.
- *
- * As with any software that integrates with the Facebook platform, your use
- * of this software is subject to the Facebook Developer Principles and
- * Policies [http://developers.facebook.com/policy/]. This copyright notice
- * shall be included in all copies or substantial portions of the software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE
- */
-
-function warn(error) {
- // eslint-disable-next-line no-console
- console.warn(error.message || error);
- throw error; // To let the caller handle the rejection
-}
-
-export default () => (next) => (action) => (typeof action.then === 'function'
- ? Promise.resolve(action).then(next, warn)
- : next(action));
diff --git a/src/reducers/.eslintrc b/src/store/reducers/.eslintrc
similarity index 100%
rename from src/reducers/.eslintrc
rename to src/store/reducers/.eslintrc
diff --git a/src/reducers/alert.js b/src/store/reducers/alert.js
similarity index 100%
rename from src/reducers/alert.js
rename to src/store/reducers/alert.js
diff --git a/src/reducers/audio.js b/src/store/reducers/audio.js
similarity index 100%
rename from src/reducers/audio.js
rename to src/store/reducers/audio.js
diff --git a/src/reducers/canvas.js b/src/store/reducers/canvas.js
similarity index 98%
rename from src/reducers/canvas.js
rename to src/store/reducers/canvas.js
index 5be1a2c..6705034 100644
--- a/src/reducers/canvas.js
+++ b/src/store/reducers/canvas.js
@@ -1,10 +1,10 @@
-import Palette from '../core/Palette';
+import Palette from '../../core/Palette';
import {
clamp,
getIdFromObject,
getHistoricalCanvasSize,
getMaxTiledZoom,
-} from '../core/utils';
+} from '../../core/utils';
import {
@@ -13,7 +13,7 @@ import {
DEFAULT_CANVAS_ID,
DEFAULT_CANVASES,
TILE_SIZE,
-} from '../core/constants';
+} from '../../core/constants';
export type CanvasState = {
canvasId: number,
diff --git a/src/reducers/chat.js b/src/store/reducers/chat.js
similarity index 98%
rename from src/reducers/chat.js
rename to src/store/reducers/chat.js
index dd54cac..d8a2fb7 100644
--- a/src/reducers/chat.js
+++ b/src/store/reducers/chat.js
@@ -1,4 +1,4 @@
-import { MAX_CHAT_MESSAGES } from '../core/constants';
+import { MAX_CHAT_MESSAGES } from '../../core/constants';
const initialState = {
/*
diff --git a/src/reducers/chatRead.js b/src/store/reducers/chatRead.js
similarity index 100%
rename from src/reducers/chatRead.js
rename to src/store/reducers/chatRead.js
diff --git a/src/reducers/contextMenu.js b/src/store/reducers/contextMenu.js
similarity index 100%
rename from src/reducers/contextMenu.js
rename to src/store/reducers/contextMenu.js
diff --git a/src/reducers/fetching.js b/src/store/reducers/fetching.js
similarity index 100%
rename from src/reducers/fetching.js
rename to src/store/reducers/fetching.js
diff --git a/src/reducers/gui.js b/src/store/reducers/gui.js
similarity index 100%
rename from src/reducers/gui.js
rename to src/store/reducers/gui.js
diff --git a/src/reducers/index.js b/src/store/reducers/index.js
similarity index 100%
rename from src/reducers/index.js
rename to src/store/reducers/index.js
diff --git a/src/reducers/ranks.js b/src/store/reducers/ranks.js
similarity index 100%
rename from src/reducers/ranks.js
rename to src/store/reducers/ranks.js
diff --git a/src/reducers/user.js b/src/store/reducers/user.js
similarity index 100%
rename from src/reducers/user.js
rename to src/store/reducers/user.js
diff --git a/src/reducers/windows.js b/src/store/reducers/windows.js
similarity index 99%
rename from src/reducers/windows.js
rename to src/store/reducers/windows.js
index 5369007..dceee6b 100644
--- a/src/reducers/windows.js
+++ b/src/store/reducers/windows.js
@@ -2,7 +2,7 @@
* state for open windows and modal and its content
*/
-import { clamp } from '../core/utils';
+import { clamp } from '../../core/utils';
const SCREEN_MARGIN_S = 30;
const SCREEN_MARGIN_EW = 70;
diff --git a/src/ui/ChunkLoader2D.js b/src/ui/ChunkLoader2D.js
index 4fcc0ab..ce3ad5f 100644
--- a/src/ui/ChunkLoader2D.js
+++ b/src/ui/ChunkLoader2D.js
@@ -13,7 +13,7 @@ import {
receiveBigChunk,
receiveBigChunkFailure,
// preLoadedBigChunk,
-} from '../actions';
+} from '../store/actions';
import {
getMaxTiledZoom,
getCellInsideChunk,
diff --git a/src/ui/ChunkLoader3D.js b/src/ui/ChunkLoader3D.js
index 17901c9..d23686a 100644
--- a/src/ui/ChunkLoader3D.js
+++ b/src/ui/ChunkLoader3D.js
@@ -8,7 +8,7 @@ import {
requestBigChunk,
receiveBigChunk,
receiveBigChunkFailure,
-} from '../actions';
+} from '../store/actions';
import {
getChunkOfPixel,
getOffsetOfPixel,
diff --git a/src/ui/Renderer3D.js b/src/ui/Renderer3D.js
index fda141f..7b07895 100644
--- a/src/ui/Renderer3D.js
+++ b/src/ui/Renderer3D.js
@@ -19,7 +19,7 @@ import {
import {
setHover,
selectColor,
-} from '../actions';
+} from '../store/actions';
import { tryPlacePixel } from './placePixel';
diff --git a/src/ui/placePixel.js b/src/ui/placePixel.js
index 9ffcfbf..f5e5384 100644
--- a/src/ui/placePixel.js
+++ b/src/ui/placePixel.js
@@ -16,7 +16,7 @@ import {
placedPixels,
pixelWait,
updatePixel,
-} from '../actions';
+} from '../store/actions';
import SocketClient from '../socket/SocketClient';
let pixelTimeout = null;
diff --git a/src/ui/renderer.js b/src/ui/renderer.js
index a6c25cf..2bda7a3 100644
--- a/src/ui/renderer.js
+++ b/src/ui/renderer.js
@@ -9,7 +9,7 @@
import { t } from 'ttag';
import Renderer2D from './Renderer2D';
-import { sweetAlert } from '../actions';
+import { sweetAlert } from '../store/actions';
import { isWebGL2Available } from '../core/utils';
const dummyRenderer = {