diff --git a/package.json b/package.json
index 7b8b8d1..61eb6b9 100644
--- a/package.json
+++ b/package.json
@@ -13,8 +13,7 @@
"react-router-dom": "5.0.1",
"react-scripts": "3.1.1",
"redux": "4.0.4",
- "simple-svg-icons": "2.0.2",
- "simple-svg-tools": "1.1.12"
+ "svg-inline-react": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
diff --git a/src/App.js b/src/App.js
index 83b533e..f18e95c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -9,6 +9,8 @@ import NavBar from './components/NavBar/NavBar';
import ReduxDemo from './components/ReduxDemo/ReduxDemo';
import mainReducer from './store/mainReducer';
import SvgSettingOptions from './components/svgSetting/svgSettingOptions';
+import DisplayAllComponent from './components/displayAllComponent';
+import FinalSvgDisplay from './components/displaySvg/finalSvgDisplay';
import './App.scss';
class App extends Component {
render() {
@@ -23,6 +25,8 @@ class App extends Component {
+
+
diff --git a/src/App.scss b/src/App.scss
index b41d297..501d381 100644
--- a/src/App.scss
+++ b/src/App.scss
@@ -16,7 +16,7 @@
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
- color: white;
+ color: #FFFFFF;
}
.App-link {
diff --git a/src/components/NavBar/NavBar.js b/src/components/NavBar/NavBar.js
index 9815f01..28dfccb 100644
--- a/src/components/NavBar/NavBar.js
+++ b/src/components/NavBar/NavBar.js
@@ -1,28 +1,28 @@
-import React, { Component } from 'react';
-import { Link } from 'react-router-dom';
+import React, { Component } from "react";
+import { Link } from "react-router-dom";
-import './NavBar.scss';
+import "./NavBar.scss";
export default class NavBar extends Component {
- render() {
- return (
-
-
-
{'Home'}
-
-
{' | '}
-
-
{'Choose File'}
-
-
{' | '}
-
-
{'Display Svg'}
-
-
{' | '}
-
-
{'Redux Demo'}
-
-
- );
- }
+ render() {
+ return (
+
+
+
{"Home"}
+
+
{" | "}
+
+
{"Choose File"}
+
+
{" | "}
+
+
{"Display Svg"}
+
+
{" | "}
+
+
{"Redux Demo"}
+
+
+ );
+ }
}
diff --git a/src/components/NavBar/NavBar.scss b/src/components/NavBar/NavBar.scss
index 0fe6412..c4d6013 100644
--- a/src/components/NavBar/NavBar.scss
+++ b/src/components/NavBar/NavBar.scss
@@ -1,6 +1,6 @@
.navbar{
display: flex;
- height: 30px;
+ height: 105px;
background-color: #bcda12;
align-items: center;
@@ -12,4 +12,8 @@
a:hover{
background-color: #abc514;
}
+}
+
+.navbar-divider{
+ font-size: 59px;
}
\ No newline at end of file
diff --git a/src/components/ReduxDemo/ReduxDemo.js b/src/components/ReduxDemo/ReduxDemo.js
index 8e24800..5d965e6 100644
--- a/src/components/ReduxDemo/ReduxDemo.js
+++ b/src/components/ReduxDemo/ReduxDemo.js
@@ -50,4 +50,4 @@ const mapDispatchToProps = dispatch => {
};
};
-export default connect(mapStateToProps, mapDispatchToProps)(ReduxDemo);
\ No newline at end of file
+export default connect(mapStateToProps, mapDispatchToProps)(ReduxDemo);
diff --git a/src/components/checkBoxSelection/checkBoxSelection.js b/src/components/checkBoxSelection/checkBoxSelection.js
index 745e0a7..97ace28 100644
--- a/src/components/checkBoxSelection/checkBoxSelection.js
+++ b/src/components/checkBoxSelection/checkBoxSelection.js
@@ -1,47 +1,103 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import './checkBoxSelection.scss';
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import "./checkBoxSelection.scss";
+import { connect } from "react-redux";
+import {
+ ADD_VARIABLE,
+ UPDATE_VARIABLE,
+ DELETE_VARIABLE
+} from "../../store/actionTypes";
+
class CheckBoxSelection extends Component {
- constructor(props) {
- super(props);
- this.state = {
- isClicked: false
- };
+ constructor(props) {
+ super(props);
+ this.state = {
+ isClicked: this.props.isSelected
+ };
+ }
+
+ convertSvgToDataUrl = file => {
+ let reader = new FileReader();
+ const svgSettings = [...this.props.svgSettingList];
+ reader.onload = result => {
+
+ svgSettings.push({
+ name: file.name,
+ dataurl: result.target.result
+ });
+ this.props.updateStore("svgSettingList",svgSettings)
+
+ };
+ if (file) {
+ reader.readAsDataURL(file);
}
+ };
- componentWillMount() {
- this.setState({ isClicked: this.props.isSelected });
+ changeColourAndTick = () => {
+
+ this.setState({ isClicked: !this.state.isClicked });
+ let index = this.props.svgSettingList.findIndex(
+ setting => setting.name == this.props.file.name
+ );
+
+ if (index < 0) {
+ this.convertSvgToDataUrl(this.props.file);
+ } else {
+ this.props.svgSettingList.splice(index, 1);
}
+ };
- handleDivClick= () => {
- this.setState({
- isClicked: !this.state.isClicked
- });
- }
-
- render() {
-
- return (
-
-
-
-
-
- );
- }
+ render() {
+ return (
+ this.changeColourAndTick()}
+ >
+
+
+
+ );
+ }
}
CheckBoxSelection.propTypes = {
- filename: PropTypes.string,
- isSelected: PropTypes.bool
+ svgSettingList: PropTypes.array,
+ filename: PropTypes.string
};
-export default CheckBoxSelection;
+
+const mapStateToProps = state => {
+ const svgSettingList = state.svgSettingList;
+ return { svgSettingList };
+};
+
+const mapDispatchToProps = dispatch => {
+ return {
+ addToStore: (variableName, variableValue) =>
+ dispatch({
+ type: ADD_VARIABLE,
+ variableName: variableName,
+ variableValue: variableValue
+ }),
+ updateStore: (variableName, variableValue) =>
+ dispatch({
+ type: UPDATE_VARIABLE,
+ variableName: variableName,
+ variableValue: variableValue
+ }),
+ deleteFromStore: variableName =>
+ dispatch({ type: DELETE_VARIABLE, variableName: variableName })
+ };
+};
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(CheckBoxSelection);
diff --git a/src/components/checkBoxSelection/checkBoxSelection.scss b/src/components/checkBoxSelection/checkBoxSelection.scss
index 1c94dc9..98dfb66 100644
--- a/src/components/checkBoxSelection/checkBoxSelection.scss
+++ b/src/components/checkBoxSelection/checkBoxSelection.scss
@@ -1,25 +1,16 @@
.checkbox-container-clicked {
- background-color: yellow;
- width: 80%;
- height: 10%;
+ background-color: #b5cfe1;
}
.checkbox-container-unclicked {
- background-color: white;
- width: 80%;
- height: 10%;
- border: 1px solid black;
+ background-color: #FFFFFF;
+ border: 1px solid #000000;
}
-.checkbox-input,
-.checkbox-label {
- margin-top: 12%;
- margin-left: 12%;
-}
+
.checkbox-input-svg,
.checkbox-label-svg {
- margin-top: 2%;
- margin-left: 2%;
+ padding-left: 3%;
}
.main {
@@ -29,24 +20,50 @@
.file {
display: flex;
- margin-top: 20px;
+ padding: 2%;
}
.hide-file-list {
- margin-top: 20px;
display: none;
}
-
.card-settings {
- height: 600px;
+ height: 350px;
overflow-y: scroll;
+ background-color:#b5cfe1 ;
+ width: 600px;
+}
+
+.home-display {
+ display: flex;
+}
+.choose {
+ width: 50%;
+}
+.display {
+ width: 50%;
+}
+
+.optimize-button{
+ text-align: center;
+ display: inline-block;
+ justify-items: center;
+ width:100px;
+ height: 70px;
+ border-radius: 25px;
background-color: #b5cfe1;
- width: 350px;
- padding-left: 20px;
- box-shadow: 10px 10px 55px 0px black;
+ align-items: center;
+}
+
+.download-button {
+ height: 70px;
+ border-radius: 35px;
+ background-color: #b6e1b5;
+ position: fixed;
}
+.optimise-button-div{
+ display: flex;
+ justify-content: center;
-.slider {
- margin-top: 10px;
- margin-bottom: 10px;
}
+
+
diff --git a/src/components/chooseFolder/chooseFolder.js b/src/components/chooseFolder/chooseFolder.js
index 436026f..0956524 100644
--- a/src/components/chooseFolder/chooseFolder.js
+++ b/src/components/chooseFolder/chooseFolder.js
@@ -1,54 +1,60 @@
-import React, { Component } from 'react';
-import './../checkBoxSelection/checkBoxSelection.scss';
-import optimizeSvg from '../functions';
-import CheckBoxSelection from '../checkBoxSelection/checkBoxSelection';
+import React, { Component } from "react";
+import "./../checkBoxSelection/checkBoxSelection.scss";
+import { optimizeSvg } from "../functions";
+import CheckBoxSelection from "../checkBoxSelection/checkBoxSelection";
+
class ChooseFolder extends Component {
- constructor(props) {
- super(props);
- this.state = {
- path: [],
- displayMenu: false,
- originalDataUrl:'',
- optimizedDataUrl:''
- };
- }
+ constructor(props) {
+ super(props);
+ this.state = {
+ path: [],
+ displayMenu: false,
+ originalSvgDataUrl: "",
+ optimizedDataUrl: ""
+ };
+ }
onChangeHandler = event => {
- this.setState({path:event.target.files});
- }
+ this.setState({ path: event.target.files});
+ };
+
+ convertSvgToDataUrl = file => {
+ let reader = new FileReader();
+ reader.onload = result => {
+ this.setState({ originalSvgDataUrl: result.target.result });
+ };
+ if (file) {
+ reader.readAsDataURL(file);
+ }
+ };
+
+ optimizeSvgDataUrl = async dataUrl => {
+ this.setState({ optimizedDataUrl: await optimizeSvg(dataUrl) });
+ };
- convertSvgToDataUrl=(file)=>{
- let reader = new FileReader();
- reader.onload = (result)=>{
- this.setState({originalDataUrl:result.target.result});
- };
- if (file) {
- reader.readAsDataURL(file);
- }
- }
+ render() {
+ const listOfFileNames = [];
+ for (let key of this.state.path) {
+ listOfFileNames.push(
+
+ );
+ }
- optimizeSvgDataUrl= async (dataUrl) =>{
- this.setState({optimizedDataUrl:await optimizeSvg(dataUrl)});
- }
+ return (
+
+
+
+
- render() {
- const listOfFileNames = [];
- for(var key of this.state.path) {
- listOfFileNames.push(
);
- }
-
- return (
-
-
-
-
-
- {listOfFileNames}
-
-
- );
- }
+
{listOfFileNames}
+
+ );
+ }
}
-export default ChooseFolder;
\ No newline at end of file
+export default ChooseFolder;
diff --git a/src/components/displayAllComponent.js b/src/components/displayAllComponent.js
new file mode 100644
index 0000000..df66c00
--- /dev/null
+++ b/src/components/displayAllComponent.js
@@ -0,0 +1,82 @@
+import React, { Component } from "react";
+import ChooseFolder from "./chooseFolder/chooseFolder";
+import { Redirect } from "react-router-dom";
+import SvgSettingOptions from "./svgSetting/svgSettingOptions";
+import "../components/checkBoxSelection/checkBoxSelection.scss";
+import { changeObj, optimizeSvg } from "../../src/components/functions";
+import { connect } from "react-redux";
+import PropTypes from "prop-types";
+import { UPDATE_VARIABLE} from "../../src/store/actionTypes";
+
+class DisplayAllComponent extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ redirect: false
+ };
+ }
+ getOptimizeSvg = async () => {
+ let originalAndOptimised = {};
+ for (var option of this.props.svgOptions) {
+ changeObj(option, this.props.svgObject.plugins);
+ }
+ for (var setting of this.props.svgSettingList) {
+ let { displayOptimize=[] } = this.props;
+ let SvgPlugins = this.props.svgOptions.length > 0 ? this.props.svgObject.plugins : null;
+ originalAndOptimised = {
+ originalSvg: setting.dataurl,
+ name: setting.name,
+ optimisedSvg: await optimizeSvg(
+ setting.dataurl,
+ SvgPlugins
+ )
+ };
+ this.props.updateStore("displayOptimize",[...displayOptimize,originalAndOptimised]);
+ }
+ this.setState({ redirect: true });
+ };
+
+ render() {
+ return (
+
+ {this.state.redirect ?
: null}
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+DisplayAllComponent.propTypes = {
+ addToStore: PropTypes.func,
+ updateStore: PropTypes.func,
+ svgSettingList: PropTypes.array,
+ svgOptions: PropTypes.array,
+ svgObject: PropTypes.object,
+ displayOptimize: PropTypes.array
+};
+
+const mapStateToProps = state => {
+ const svgSettingList = state.svgSettingList;
+ const svgOptions = state.svgOptions;
+ const svgObject = state.svgObject;
+ const displayOptimize = state.displayOptimize;
+ return { svgSettingList, svgOptions, svgObject, displayOptimize };
+};
+
+const mapDispatchToProps = dispatch => {
+ return {
+ updateStore: (variableName, variableValue) => dispatch({ type: UPDATE_VARIABLE, variableName: variableName, variableValue: variableValue })
+ };
+};
+
+export default connect(mapStateToProps,mapDispatchToProps)(DisplayAllComponent);
diff --git a/src/components/displaySvg/displaySvg.js b/src/components/displaySvg/displaySvg.js
index 1db0ac8..d1fe8d0 100644
--- a/src/components/displaySvg/displaySvg.js
+++ b/src/components/displaySvg/displaySvg.js
@@ -1,48 +1,78 @@
-import React, { Component } from 'react';
-import base64 from 'base-64';
-import PropTypes from 'prop-types';
+import React, { Component } from "react";
+import base64 from "base-64";
+import "./finalSvgDisplay.scss";
+import PropTypes from "prop-types";
+import InlineSVG from "svg-inline-react";
class DisplaySvg extends Component {
- constructor(props) {
- super(props);
- this.state = {
- fileSize: 0
- };
- }
-
- componentWillMount = () => {
- if (this.props.dataUrl) {
- this.setState({
- fileSize: this.dataURLtoKilloBytes(this.props.dataUrl.split(',')[1])
- });
- }
+ constructor(props) {
+ super(props);
+ this.state = {
+ fileSizeNormal: 0,
+ fileSizeOptimised: 0,
+ isClicked: false
};
+ }
- dataURLtoKilloBytes = dataURI => {
- return base64.decode(dataURI).length / 1000;
- };
+ changeColourOnclickToMark = () => {
+ this.setState({ isClicked: !this.state.isClicked });
+ };
- render() {
- return (
-
+ componentWillMount = () => {
+ if (this.props.dataUrl) {
+ this.setState({
+ fileSizeNormal: this.dataURLtoKilloBytes(
+ this.props.dataUrl.split(",")[1]
+ ),
+ fileSizeOptimised: this.props.finalStringElementWrappedWithLink.length / 1000
+ });
+ }
+ };
+
+ dataURLtoKilloBytes = dataURI => {
+ return base64.decode(dataURI).length / 1000;
+ };
+
+ render() {
+ return (
+
+ { (this.props.dataUrl && this.props.finalStringElementWrappedWithLink) ?
+
+
+ -
-
- { 'File Size : '+this.state.fileSize +' KB'}
+
+
+ {"File Size : " + this.state.fileSizeNormal + " KB"}
+
-
- );
- }
+
+
+
+
+
+
+
+ {"File Size : " + this.state.fileSizeOptimised + " KB"}
+
+
+
+
+
+ : null}
+
+ );
+ }
}
DisplaySvg.propTypes = {
- dataUrl: PropTypes.string,
- width: PropTypes.string,
- height: PropTypes.string
+ dataUrl: PropTypes.string,
+ width: PropTypes.string,
+ height: PropTypes.string
};
export default DisplaySvg;
diff --git a/src/components/displaySvg/finalSvgDisplay.js b/src/components/displaySvg/finalSvgDisplay.js
new file mode 100644
index 0000000..04f47c0
--- /dev/null
+++ b/src/components/displaySvg/finalSvgDisplay.js
@@ -0,0 +1,158 @@
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import finalSvgDisplay from "./finalSvgDisplay.scss";
+import { connect } from "react-redux";
+import { SVG_TAG_NAMES } from "../../constants/constants";
+import {
+ ADD_VARIABLE,
+ UPDATE_VARIABLE,
+ DELETE_VARIABLE
+} from "../../store/actionTypes";
+import {
+ wrapElements,
+ updateSvgElements,
+ changeSvgColourById
+} from "../functions";
+
+class FinalSvgDisplay extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ wrappedPathsElement: [],
+ pathArrayState: null,
+ storePathsIds: [],
+ clickedSvgState: []
+ };
+ }
+
+ downloadOptimizedSvgs = () => {
+ let svgElementList = document.getElementsByTagName("svg");
+
+ //get svg source.
+ let serializer = new XMLSerializer();
+ for (let svgDataIndex in svgElementList) {
+ //get svg source.
+ let source = serializer.serializeToString(svgElementList[svgDataIndex]);
+ source = source
+ .replace('', "")
+ .replace("", "")
+ .replace('onclick="changeSvgColourById(this.id);"', "");
+
+ //add name spaces.
+ if (
+ !source.match(/^