Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

.cache/
coverage/
dist/*
!dist/index.html
node_modules/
*.log

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
34 changes: 5 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
Assignment 4 - Components
===
# a4 - Duncan Soiffer

Due: October 4th, by 11:59 AM.
https://a4-duncan-soiffer.glitch.me

For this assignment you will re-implement the client side portion of *either* A2 or A3 using either React or Svelte components. If you choose A3 you only need to use components for the data display / updating; you can leave your login UI as is.
NOTE: THE PROF GAVE ME AN EXTENSION, HENCE WHY I AM SUBMITTING THIS LATE.

[Svelte Tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/using_svelte.md)
[React Tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/using_react.md)
## Brief Summary

This project can be implemented on any hosting service (Glitch, DigitalOcean, Heroku etc.), however, you must include all files in your GitHub repo so that the course staff can view them.

Deliverables
---

Do the following to complete this assignment:

1. Implement your project with the above requirements.
3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly.
4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it.
5. Fork this repository and modify the README to the specifications below. Be sure to add *all* project files.
6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`.

Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions)
---

## Your Web Application Title

your hosting link e.g. http://a4-charlieroberts.glitch.me

Include a very brief summary of your project here and what you changed / added to assignment #3. Briefly (3–4 sentences) answer the following question: did the new technology improve or hinder the development experience?

Unlike previous assignments, this assignment will be solely graded on whether or not you successfully complete it. Partial credit will be generously given.
I chose to do a4-components and port my a2 into React. I tried to preserve as much of the original website format and functionality as possible, which proved to be a bit annoying to do. Part of my trouble was because I had formatted a2 pretty clumsily, and part of it was because of some subtleties with how React works breaking my project. I probably also committed heinous crimes against React best practices due to not really knowing how to use React properly. It's hard to say if React helped or hindered my process; it certainly went smoother this time around but I think that is largely because I am far more familiar with web development now. I think if I continued to use React in the same way that I am now, it would end up hindering my development. It will take some time for me to learn it before it becomes actually useful.
120 changes: 120 additions & 0 deletions build/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React from "./_snowpack/pkg/react.js";
import "./styles.css.proxy.js";
class TableRow extends React.Component {
render() {
return /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("td", null, this.props.name), /* @__PURE__ */ React.createElement("td", null, this.props.val1), /* @__PURE__ */ React.createElement("td", null, this.props.val2), /* @__PURE__ */ React.createElement("td", null, this.props.op), /* @__PURE__ */ React.createElement("td", null, this.props.result));
}
}
class App extends React.Component {
constructor(props) {
super(props);
this.convert = this.convert.bind(this);
this.state = {comps: []};
this.load();
}
load() {
fetch("/read", {method: "get", "no-cors": true}).then((response) => response.json()).then((json) => {
this.setState({comps: json});
});
}
render() {
return /* @__PURE__ */ React.createElement("div", {
className: "App"
}, /* @__PURE__ */ React.createElement("div", {
class: "flex-container"
}, /* @__PURE__ */ React.createElement("div", {
id: "titles"
}, /* @__PURE__ */ React.createElement("h1", null, "The Lame Calculator"), /* @__PURE__ */ React.createElement("h2", null, "Somehow still a better deal than TI calculators™"), /* @__PURE__ */ React.createElement("h3", null, "Collaborative Computing, done wrong©")), /* @__PURE__ */ React.createElement("p", null, "Enter a valid number in the boxes along with an operator, then press compute to perform the designed operation on those numbers. Results are sorted with most recent appearing at the top for convenience. "), /* @__PURE__ */ React.createElement("p", {
id: "warning"
}, "WARNING: DO NOT ATTEMPT TO COMMUNICATE WITH CALCULATOR IN BINARY VIA COMPUTATION. IGNORE ALL SECRET RESPONSES."), /* @__PURE__ */ React.createElement("div", {
class: "flex-container",
id: "computeform"
}, /* @__PURE__ */ React.createElement("form", null, /* @__PURE__ */ React.createElement("input", {
type: "number",
class: "fvalue",
id: "value1"
}), /* @__PURE__ */ React.createElement("input", {
type: "text",
class: "foperator",
id: "operator"
}), /* @__PURE__ */ React.createElement("input", {
type: "number",
class: "fvalue",
id: "value2"
}), /* @__PURE__ */ React.createElement("button", {
id: "compute",
onClick: (e) => this.submit(e)
}, "compute"))), /* @__PURE__ */ React.createElement("div", {
id: "notesandconvert",
class: "flex-container"
}, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, "Notes:"), /* @__PURE__ */ React.createElement("ul", null, /* @__PURE__ */ React.createElement("li", null, "Supported operations are +, -, *, /, and ^."), /* @__PURE__ */ React.createElement("li", null, "Whitespace is supported within numbers, but NOT by the binary parser."), /* @__PURE__ */ React.createElement("li", null, "01110100 01110010 01111001 00100000 01110100 01100101 01110011 01110100"))), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, `The "convert" button converts text to the decimal equivalent of the text's binary representation. Use this to avoid accidentally communicating with the calculator by having your computation result be the decimal equivalent of some binary phrase.`), /* @__PURE__ */ React.createElement("input", {
type: "text",
id: "bintext"
}), /* @__PURE__ */ React.createElement("input", {
id: "bintextconv"
}), /* @__PURE__ */ React.createElement("button", {
id: "convert",
onClick: this.convert
}, "convert"), /* @__PURE__ */ React.createElement("p", {
id: "convertedtext"
}))), /* @__PURE__ */ React.createElement("div", {
class: "flex-container",
id: "tablecontainer"
}, /* @__PURE__ */ React.createElement("table", {
id: "table"
}, /* @__PURE__ */ React.createElement("colgroup", null, /* @__PURE__ */ React.createElement("col", {
span: "1",
style: {width: "30%"}
}), /* @__PURE__ */ React.createElement("col", {
span: "1",
style: {width: "20%"}
}), /* @__PURE__ */ React.createElement("col", {
span: "1",
style: {width: "20%"}
}), /* @__PURE__ */ React.createElement("col", {
span: "1",
style: {width: "5%"}
}), /* @__PURE__ */ React.createElement("col", {
span: "1",
style: {width: "25%"}
})), /* @__PURE__ */ React.createElement("tbody", null, /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("th", null, "Computation Number"), /* @__PURE__ */ React.createElement("th", null, "Var 1"), /* @__PURE__ */ React.createElement("th", null, "Var 2"), /* @__PURE__ */ React.createElement("th", null, "Op."), /* @__PURE__ */ React.createElement("th", null, "Result")), this.state.comps.map((comp, i) => /* @__PURE__ */ React.createElement(TableRow, {
val1: this.state.comps[this.state.comps.length - 1 - i].x,
val2: this.state.comps[this.state.comps.length - 1 - i].y,
op: this.state.comps[this.state.comps.length - 1 - i].o,
name: this.state.comps[this.state.comps.length - 1 - i].name,
result: this.state.comps[this.state.comps.length - 1 - i].result
})))))));
}
convert() {
let input = document.getElementById("bintext").value.toLowerCase();
let output = "";
for (var i = 0; i < input.length; i++) {
output += input[i].charCodeAt(0).toString(2) + " ";
}
document.getElementById("bintextconv").value = parseInt(output.split(" ").join(""), 2);
}
submit(e) {
e.preventDefault();
let val1 = document.getElementById("value1").value;
let val2 = document.getElementById("value2").value;
const op = document.getElementById("operator").value;
val1 = val1.replace(/\s+/g, "");
val2 = val2.replace(/\s+/g, "");
if (isNaN(val1) || isNaN(val2) || val1 === "" || val2 === "") {
alert("Must input numbers");
} else if (op.match(/^[-+/^*]/) === null) {
alert("Must input valid operator (+, -, *, /, ^)");
} else {
let json = {x: val1, y: val2, o: op};
let body = JSON.stringify(json);
fetch("/submit", {
method: "POST",
body,
headers: {"Content-Type": "application/json"}
}).then((response) => response.json()).then((json2) => {
this.setState({comps: json2});
});
}
}
}
export default App;
129 changes: 129 additions & 0 deletions build/_snowpack/pkg/common/index-ae389540.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
}
}, fn(module, module.exports), module.exports;
}

function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}

/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;

function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}

return Object(val);
}

function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}

// Detect buggy property enumeration order in older V8 versions.

// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}

// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}

// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}

return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}

var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;

for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);

for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}

if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}

return to;
};

var react_production_min = createCommonjsModule(function (module, exports) {
var n=60103,p=60106;exports.Fragment=60107;exports.StrictMode=60108;exports.Profiler=60114;var q=60109,r=60110,t=60112;exports.Suspense=60113;var u=60115,v=60116;
if("function"===typeof Symbol&&Symbol.for){var w=Symbol.for;n=w("react.element");p=w("react.portal");exports.Fragment=w("react.fragment");exports.StrictMode=w("react.strict_mode");exports.Profiler=w("react.profiler");q=w("react.provider");r=w("react.context");t=w("react.forward_ref");exports.Suspense=w("react.suspense");u=w("react.memo");v=w("react.lazy");}var x="function"===typeof Symbol&&Symbol.iterator;
function y(a){if(null===a||"object"!==typeof a)return null;a=x&&a[x]||a["@@iterator"];return "function"===typeof a?a:null}function z(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return "Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var A={isMounted:function(){return !1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},B={};function C(a,b,c){this.props=a;this.context=b;this.refs=B;this.updater=c||A;}C.prototype.isReactComponent={};C.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error(z(85));this.updater.enqueueSetState(this,a,b,"setState");};C.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate");};
function D(){}D.prototype=C.prototype;function E(a,b,c){this.props=a;this.context=b;this.refs=B;this.updater=c||A;}var F=E.prototype=new D;F.constructor=E;objectAssign(F,C.prototype);F.isPureReactComponent=!0;var G={current:null},H=Object.prototype.hasOwnProperty,I={key:!0,ref:!0,__self:!0,__source:!0};
function J(a,b,c){var e,d={},k=null,h=null;if(null!=b)for(e in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(k=""+b.key),b)H.call(b,e)&&!I.hasOwnProperty(e)&&(d[e]=b[e]);var g=arguments.length-2;if(1===g)d.children=c;else if(1<g){for(var f=Array(g),m=0;m<g;m++)f[m]=arguments[m+2];d.children=f;}if(a&&a.defaultProps)for(e in g=a.defaultProps,g)void 0===d[e]&&(d[e]=g[e]);return {$$typeof:n,type:a,key:k,ref:h,props:d,_owner:G.current}}
function K(a,b){return {$$typeof:n,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function L(a){return "object"===typeof a&&null!==a&&a.$$typeof===n}function escape(a){var b={"=":"=0",":":"=2"};return "$"+a.replace(/[=:]/g,function(a){return b[a]})}var M=/\/+/g;function N(a,b){return "object"===typeof a&&null!==a&&null!=a.key?escape(""+a.key):b.toString(36)}
function O(a,b,c,e,d){var k=typeof a;if("undefined"===k||"boolean"===k)a=null;var h=!1;if(null===a)h=!0;else switch(k){case "string":case "number":h=!0;break;case "object":switch(a.$$typeof){case n:case p:h=!0;}}if(h)return h=a,d=d(h),a=""===e?"."+N(h,0):e,Array.isArray(d)?(c="",null!=a&&(c=a.replace(M,"$&/")+"/"),O(d,b,c,"",function(a){return a})):null!=d&&(L(d)&&(d=K(d,c+(!d.key||h&&h.key===d.key?"":(""+d.key).replace(M,"$&/")+"/")+a)),b.push(d)),1;h=0;e=""===e?".":e+":";if(Array.isArray(a))for(var g=
0;g<a.length;g++){k=a[g];var f=e+N(k,g);h+=O(k,b,c,f,d);}else if(f=y(a),"function"===typeof f)for(a=f.call(a),g=0;!(k=a.next()).done;)k=k.value,f=e+N(k,g++),h+=O(k,b,c,f,d);else if("object"===k)throw b=""+a,Error(z(31,"[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b));return h}function P(a,b,c){if(null==a)return a;var e=[],d=0;O(a,e,"","",function(a){return b.call(c,a,d++)});return e}
function Q(a){if(-1===a._status){var b=a._result;b=b();a._status=0;a._result=b;b.then(function(b){0===a._status&&(b=b.default,a._status=1,a._result=b);},function(b){0===a._status&&(a._status=2,a._result=b);});}if(1===a._status)return a._result;throw a._result;}var R={current:null};function S(){var a=R.current;if(null===a)throw Error(z(321));return a}var T={ReactCurrentDispatcher:R,ReactCurrentBatchConfig:{transition:0},ReactCurrentOwner:G,IsSomeRendererActing:{current:!1},assign:objectAssign};
exports.Children={map:P,forEach:function(a,b,c){P(a,function(){b.apply(this,arguments);},c);},count:function(a){var b=0;P(a,function(){b++;});return b},toArray:function(a){return P(a,function(a){return a})||[]},only:function(a){if(!L(a))throw Error(z(143));return a}};exports.Component=C;exports.PureComponent=E;exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=T;
exports.cloneElement=function(a,b,c){if(null===a||void 0===a)throw Error(z(267,a));var e=objectAssign({},a.props),d=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=G.current);void 0!==b.key&&(d=""+b.key);if(a.type&&a.type.defaultProps)var g=a.type.defaultProps;for(f in b)H.call(b,f)&&!I.hasOwnProperty(f)&&(e[f]=void 0===b[f]&&void 0!==g?g[f]:b[f]);}var f=arguments.length-2;if(1===f)e.children=c;else if(1<f){g=Array(f);for(var m=0;m<f;m++)g[m]=arguments[m+2];e.children=g;}return {$$typeof:n,type:a.type,
key:d,ref:k,props:e,_owner:h}};exports.createContext=function(a,b){void 0===b&&(b=null);a={$$typeof:r,_calculateChangedBits:b,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null};a.Provider={$$typeof:q,_context:a};return a.Consumer=a};exports.createElement=J;exports.createFactory=function(a){var b=J.bind(null,a);b.type=a;return b};exports.createRef=function(){return {current:null}};exports.forwardRef=function(a){return {$$typeof:t,render:a}};exports.isValidElement=L;
exports.lazy=function(a){return {$$typeof:v,_payload:{_status:-1,_result:a},_init:Q}};exports.memo=function(a,b){return {$$typeof:u,type:a,compare:void 0===b?null:b}};exports.useCallback=function(a,b){return S().useCallback(a,b)};exports.useContext=function(a,b){return S().useContext(a,b)};exports.useDebugValue=function(){};exports.useEffect=function(a,b){return S().useEffect(a,b)};exports.useImperativeHandle=function(a,b,c){return S().useImperativeHandle(a,b,c)};
exports.useLayoutEffect=function(a,b){return S().useLayoutEffect(a,b)};exports.useMemo=function(a,b){return S().useMemo(a,b)};exports.useReducer=function(a,b,c){return S().useReducer(a,b,c)};exports.useRef=function(a){return S().useRef(a)};exports.useState=function(a){return S().useState(a)};exports.version="17.0.2";
});

var react = createCommonjsModule(function (module) {

{
module.exports = react_production_min;
}
});

export { createCommonjsModule as c, objectAssign as o, react as r };
6 changes: 6 additions & 0 deletions build/_snowpack/pkg/import-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"react": "./react.js",
"react-dom": "./react-dom.js"
}
}
Loading