From fb167337bb3d18d8c7b80dac767d22ed7ad49bc6 Mon Sep 17 00:00:00 2001 From: HF Date: Sun, 10 May 2020 10:43:43 +0200 Subject: [PATCH] split stylesheet from js, style selection and fix all lsint errors --- README.md | 6 +- deployment/post-receive | 46 +- package-lock.json | 17 + package.json | 1 + src/actions/index.js | 10 +- src/actions/types.js | 8 +- src/client.js | 14 +- src/components/App.jsx | 19 +- src/components/CanvasItem.jsx | 48 +- src/components/CanvasSelectModal.jsx | 15 +- src/components/CanvasSwitchButton.jsx | 9 +- src/components/ChangeMail.jsx | 33 +- src/components/ChangeName.jsx | 20 +- src/components/ChangePassword.jsx | 64 ++- src/components/ChatModal.jsx | 15 +- src/components/Converter.jsx | 64 +-- src/components/Creeper.svg | 2 +- src/components/DeleteAccount.jsx | 18 +- src/components/ExpandMenuButton.jsx | 10 +- src/components/ForgotPasswordModal.jsx | 14 +- src/components/Globe.jsx | 33 +- src/components/GlobeButton.jsx | 10 +- src/components/GridButton.jsx | 14 +- src/components/HelpButton.jsx | 8 +- src/components/HelpModal.jsx | 92 ++-- src/components/Html.jsx | 145 +++--- src/components/LogInButton.jsx | 8 +- src/components/Main.jsx | 51 +- src/components/MdToggleButton.jsx | 3 +- src/components/MinecraftButton.jsx | 11 +- src/components/MinecraftTPButton.jsx | 12 +- src/components/Mobile3DControls.jsx | 340 ++++++------ src/components/Modal.jsx | 22 +- src/components/ModalRoot.jsx | 4 +- src/components/NewPasswordForm.jsx | 14 +- src/components/Rankings.jsx | 43 +- src/components/ReCaptcha.jsx | 2 - src/components/RegisterModal.jsx | 32 +- src/components/SettingsButton.jsx | 10 +- src/components/SettingsModal.jsx | 84 +-- src/components/SignUpForm.jsx | 51 +- src/components/Tab.jsx | 8 +- src/components/Tabs.jsx | 8 +- src/components/UserArea.jsx | 137 +++-- src/components/UserAreaModal.jsx | 29 +- src/components/UserMessages.jsx | 117 +++-- src/controls/VoxelPainterControls.js | 4 +- src/core/Image.js | 3 + src/core/Tile.js | 19 +- src/core/isProxy.js | 54 +- src/core/minecraft.js | 21 +- src/core/voxExport.js | 4 +- src/reducers/gui.js | 10 + src/reducers/modal.js | 6 +- src/routes/api/auth/change_passwd.js | 2 +- src/routes/reset_password.js | 50 +- src/socket/APISocketServer.js | 8 +- src/socket/ProtocolClient.js | 9 +- src/store/configureStore.js | 6 +- src/store/styleHook.js | 22 + src/store/sweetAlert.js | 1 - src/styles/dark-round.css | 484 ++++++++++++++++++ src/styles/dark.css | 481 +++++++++++++++++ .../base.tcss => styles/default.css} | 261 ++++++---- src/{components => styles}/font.css | 0 .../globe.tcss => styles/globe.css} | 12 +- src/styles/light-round.css | 471 +++++++++++++++++ src/ui/Renderer2D.js | 36 +- src/ui/setStyle.js | 12 + src/ui/store.js | 7 +- tools/build.js | 2 + tools/bundle.js | 1 + tools/copy.js | 3 +- tools/minifyCss.js | 43 ++ tools/webpack.config.js | 243 +++++---- utils/websockettest.py | 4 +- 76 files changed, 2910 insertions(+), 1090 deletions(-) create mode 100644 src/store/styleHook.js create mode 100644 src/styles/dark-round.css create mode 100644 src/styles/dark.css rename src/{components/base.tcss => styles/default.css} (61%) rename src/{components => styles}/font.css (100%) rename src/{components/globe.tcss => styles/globe.css} (90%) create mode 100644 src/styles/light-round.css create mode 100644 src/ui/setStyle.js create mode 100644 tools/minifyCss.js diff --git a/README.md b/README.md index 8cc610a..722fd38 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,10 @@ If you want to add a new canvas, be sure that you additionally create `public/lo The default configuration values can be seen in `src/core/config.js` and for the canvases in `src/core/constats.js` +#### Styles + +To add more css styles, create a new css file in `src/styles` based on `src/styles/default.css` and add it to the FILES array in `tools/minifyCss.js` + ### Running 1. Make sure that mysql and redis are running @@ -206,7 +210,7 @@ After=network.target mysql.service redis.service ### Development Run `npm run lint:src` to check for code errors and warnings or `npm run lint -- ./your/file.js` to check a single file. -We have enough warnings already, just don't produce too many additional ones. +Please do not produce too many additional warnings. You can use `npm run babel-node ./your/script.js` to execute a script with local babel. diff --git a/deployment/post-receive b/deployment/post-receive index cf9aa01..93d8171 100755 --- a/deployment/post-receive +++ b/deployment/post-receive @@ -1,25 +1,22 @@ #!/bin/bash # This hook builds pixelplanet after a push, and deploys it # If it is the production branch, it will deploy it on the life system, and other branch will get deployed to the dev-canvas (a second canvas that is running on the server) +# canvases.json, proxies.json and ecosystem.yml are already in the terget directories # Update messages will get sent via the Webhooks to Discord # # To set up a server to use this, you have to go through the building steps manually first. -# This hook just builds the canvas, it does not install new yarn/npm packages if needed. So this has to be done manually first -# Also keep in mind that running a dev-canvas and a life canvas independently together on one server needs two redis installations. -# tl;dr: Don't just copy that script, try to know how that setup works first +# This hook just builds the canvas, it does not install new packages if needed. So this has to be done manually first # #discord webhook for dev canvas -WEBHOOK='https://discordapp.com/api/webhooks/' +WEBHOOK='https://discordapp.com/api/webhooks/5440815510.....' #discord webhook for production canvas -PWEBHOOK='https://discordapp.com/api/webhooks/' +PWEBHOOK='https://discordapp.com/api/webhooks/54413213......' #folder for building the canvas (the git repository will get checkout there and the canvas will get buil thtere) -BUILDDIR="pixelplanet-build" +BUILDDIR="/home/pixelpla/pixelplanet-build" #folder for dev canvas -DEVFOLDER="pixelplanet-dev" +DEVFOLDER="/home/pixelpla/pixelplanet-dev" #folder for production canvas -PFOLDER="pixelplanet" -#proxies.json path -PROXYFILE="/proxies.json" +PFOLDER="/home/pixelpla/pixelplanet" while read oldrev newrev refname do @@ -33,35 +30,40 @@ do COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'` echo "---BUILDING pixelplanet---" cd "$BUILDDIR" - cp "$PROXYFILE" ./src/ - yarn run build --release + npm run build echo "---RESTARTING CANVAS---" - cp -r build/* "${PFOLDER}/" + cp -r build/*.js "${PFOLDER}/" + cp -r build/public "${PFOLDER}/" + cp -r build/package.json "${PFOLDER}/" + cp -r build/assets.json "${PFOLDER}/" + cp -r build/styleassets.json "${PFOLDER}/" + mkdir -p "${PFOLDER}/log" #cp ecosystem-production.yml "${PFOLDER}/ecosystem.yml" cd "$PFOLDER" pm2 stop web pm2 start ecosystem.yml - #make backup - tar -cvJf /backup/pixelplanet-src/pixelplanet-src-`date +%Y%m%d`.tar.xz --exclude=node_modules --exclude=.git -C "${BUILDDIR}/.." "pixelplanet-build" - #send update message to discord curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "...Done", "embeds": [{"title": "New Commits", "url": "https://pixelplanet.fun", "description": "'"$COMMITS"'", "color": 15258703}] }' "$PWEBHOOK" else echo "---UPDATING REPO ON DEV SERVER---" pm2 stop web-dev GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard "origin/$branch" - curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "Restarting pixelplanet development canvas for update..." }' "$WEBHOOK" + #curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "Restarting pixelplanet development canvas for update..." }' "$WEBHOOK" COMMITS=`git log --pretty=format:'- %s%b' $newrev ^$oldrev` COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'` echo "---BUILDING pixelplanet---" cd "$BUILDDIR" - cp "$PROXYFILE" ./src/ - nice -n 19 yarn run build --release + nice -n 19 npm run build echo "---RESTARTING CANVAS---" - cp -r build/* "${DEVFOLDER}/" + cp -r build/*.js "${DEVFOLDER}/" + cp -r build/public "${DEVFOLDER}/" + cp -r build/package.json "${DEVFOLDER}/" + cp -r build/assets.json "${DEVFOLDER}/" + cp -r build/styleassets.json "${DEVFOLDER}/" + mkdir -p "${PFOLDER}/log" #cp ecosystem-dev.yml "${DEVFOLDER}/ecosystem.yml" cd "$DEVFOLDER" pm2 start ecosystem.yml - curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "...Done\nhttp://dev.pixelplanet.fun is now on branch '"$branch"'", "embeds": [{"title": "New Commits", "url": "https://pixelplanet.fun", "description": "'"$COMMITS"'", "color": 15258703}] }' "$WEBHOOK" + #curl -H "Content-Type: application/json" --data-binary '{ "username": "PixelPlanet Server", "avatar_url": "https://pixelplanet.fun/favicon.ico", "content": "...Done\nhttp://dev.pixelplanet.fun is now on branch '"$branch"'", "embeds": [{"title": "New Commits", "url": "https://pixelplanet.fun", "description": "'"$COMMITS"'", "color": 15258703}] }' "$WEBHOOK" fi -done + done diff --git a/package-lock.json b/package-lock.json index 02db042..f413523 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4210,6 +4210,23 @@ } } }, + "clean-css": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz", + "integrity": "sha512-VcMWDN54ZN/DS+g58HYL5/n4Zrqe8vHJpGA8KdgUXFU4fuP/aHNw8eld9SyEIyabIMJX/0RaY/fplOo5hYLSFA==", + "dev": true, + "requires": { + "source-map": "~0.6.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "cli-boxes": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-1.0.0.tgz", diff --git a/package.json b/package.json index b168fcd..ef5652c 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "@babel/preset-flow": "^7.9.0", "@babel/preset-react": "^7.9.4", "@babel/preset-typescript": "^7.9.0", + "clean-css": "^4.2.3", "assets-webpack-plugin": "^3.9.12", "babel-eslint": "^10.1.0", "babel-loader": "^8.1.0", diff --git a/src/actions/index.js b/src/actions/index.js index 1253846..fff3bd8 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -89,6 +89,13 @@ export function toggleOpenPalette(): Action { }; } +export function selectStyle(style: string): Action { + return { + type: 'SELECT_STYLE', + style, + }; +} + export function toggleOpenMenu(): Action { return { type: 'TOGGLE_OPEN_MENU', @@ -581,11 +588,10 @@ export function initTimer(): ThunkAction { }; } -export function showModal(modalType: string, modalProps: Object = {}): Action { +export function showModal(modalType: string): Action { return { type: 'SHOW_MODAL', modalType, - modalProps, }; } diff --git a/src/actions/types.js b/src/actions/types.js index 9975f45..b70700a 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -25,6 +25,7 @@ export type Action = | { type: 'TOGGLE_LIGHT_GRID' } | { type: 'TOGGLE_OPEN_MENU' } | { type: 'TOGGLE_HISTORICAL_VIEW' } + | { type: 'SELECT_STYLE', style: string } | { type: 'SET_NOTIFICATION', notification: string } | { type: 'UNSET_NOTIFICATION' } | { type: 'SET_PLACE_ALLOWED', placeAllowed: boolean } @@ -78,15 +79,10 @@ export type Action = | { type: 'SET_MINECRAFT_NAME', minecraftname: string } | { type: 'SET_MAILREG', mailreg: boolean } | { type: 'REM_FROM_MESSAGES', message: string } - | { type: 'SHOW_MODAL', modalType: string, modalProps: obj } + | { type: 'SHOW_MODAL', modalType: string } | { type: 'HIDE_MODAL' } | { type: 'RELOAD_URL' } | { type: 'SET_HISTORICAL_TIME', date: string, time: string } | { type: 'ON_VIEW_FINISH_CHANGE' }; export type PromiseAction = Promise; -export type Dispatch = (action: Action - | ThunkAction - | PromiseAction - | Array) => any; export type GetState = () => State; -export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any; diff --git a/src/client.js b/src/client.js index 60cb922..e83d9a2 100644 --- a/src/client.js +++ b/src/client.js @@ -1,11 +1,8 @@ /* @flow */ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; import fetch from 'isomorphic-fetch'; // TODO put in the beggining with webpack! -import './components/font.css'; +import './styles/font.css'; // import initAds, { requestAds } from './ui/ads'; import onKeyPress from './controls/keypress'; @@ -24,7 +21,7 @@ import { import store from './ui/store'; -import App from './components/App'; +import renderApp from './components/App'; import { initRenderer, getRenderer } from './ui/renderer'; import ProtocolClient from './socket/ProtocolClient'; @@ -97,12 +94,7 @@ function init() { init(); document.addEventListener('DOMContentLoaded', () => { - ReactDOM.render( - - - , - document.getElementById('app'), - ); + renderApp(document.getElementById('app')); document.addEventListener('keydown', onKeyPress, false); diff --git a/src/components/App.jsx b/src/components/App.jsx index c391f15..3e29359 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -4,8 +4,12 @@ */ import React from 'react'; +import { Provider } from 'react-redux'; +import ReactDOM from 'react-dom'; import { IconContext } from 'react-icons'; +import store from '../ui/store'; + import CoordinatesBox from './CoordinatesBox'; import CanvasSwitchButton from './CanvasSwitchButton'; import OnlineBox from './OnlineBox'; @@ -17,12 +21,8 @@ import ReCaptcha from './ReCaptcha'; import ExpandMenuButton from './ExpandMenuButton'; import ModalRoot from './ModalRoot'; -import baseCss from './base.tcss'; - const App = () => (
- {/* eslint-disable-next-line react/no-danger */} -