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
35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
Assignment 4 - Components
===
Jack McEvoy

Due: October 4th, by 11:59 AM.
https://a4-linkd-aether.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.
## Instant Data Cruncher
This simple web tool allows users to find various measures of average of a group of numbers. Type a number of at most 10 digits into the text field, press enter or the "Add to List" button. The number will be added to the list below and the measures of average will be calculated automatically. To delete an entry in the list, click on the number.

[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)
This page uses CSS Flexbox and now uses React to dynamically display the measures of average and the number list!

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.
The measures of average are derived server-side from the input data.
105 changes: 105 additions & 0 deletions build/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React from "./_snowpack/pkg/react.js";
import NumTable from "./NumTable.js";
import "./style.css.proxy.js";
class App extends React.Component {
update() {
let trueThis = this;
fetch("/update", {
method: "GET"
}).then(function(response) {
return response.json();
}).then(function(data) {
trueThis.setState({appdata: data});
});
}
submit() {
let trueThis = this;
const num = document.getElementById("num").value;
document.getElementById("error").innerHTML = "";
if (String(num).replace(".", "").length > 10) {
document.getElementById("error").innerText = "Maximum # of digits is 10";
return;
}
if (num == "")
return;
const json = {
num
};
const body = JSON.stringify(json);
document.getElementById("num").value = "";
fetch("/add", {
method: "POST",
body,
headers: {"Content-Type": "application/json"}
}).then(function(response) {
const checkPromise = () => {
response.json().then((result) => {
trueThis.setState({appdata: result});
});
};
checkPromise();
});
return false;
}
remove(index) {
let trueThis = this;
const json = {
index
};
const body = JSON.stringify(json);
fetch("/remove", {
method: "POST",
body,
headers: {"Content-Type": "application/json"}
}).then(function(response) {
const checkPromise = () => {
response.json().then((result) => {
trueThis.setState({appdata: result});
});
};
checkPromise();
});
return false;
}
render() {
const {name} = this.props;
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("form", null, /* @__PURE__ */ React.createElement("ul", null, /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("label", {
for: "num"
}, "Number:"), /* @__PURE__ */ React.createElement("input", {
type: "number",
id: "num",
name: "num_input"
}), /* @__PURE__ */ React.createElement("span", {
id: "error"
})), /* @__PURE__ */ React.createElement("li", {
class: "button"
}, /* @__PURE__ */ React.createElement("button", {
type: "button",
id: "submit",
onClick: this.submit
}, "Add to List")))), /* @__PURE__ */ React.createElement("table", {
class: "stat-table"
}, /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("th", null, "Count"), /* @__PURE__ */ React.createElement("th", null, "Mean"), /* @__PURE__ */ React.createElement("th", null, "Median"), /* @__PURE__ */ React.createElement("th", null, "Mode")), /* @__PURE__ */ React.createElement("tr", {
id: "stat-list"
}, /* @__PURE__ */ React.createElement("th", null, this.state.appdata.stats.entries), /* @__PURE__ */ React.createElement("th", null, this.state.appdata.stats.mean), /* @__PURE__ */ React.createElement("th", null, this.state.appdata.stats.median), /* @__PURE__ */ React.createElement("th", null, this.state.appdata.stats.mode))), /* @__PURE__ */ React.createElement("hr", null), /* @__PURE__ */ React.createElement(NumTable, {
id: "num-list",
remove: this.remove,
data: this.state.appdata.data
}));
}
constructor(props) {
super(props);
this.state = {
appdata: {
stats: {entries: 0, mean: null, median: null, mode: []},
data: []
}
};
this.update = this.update.bind(this);
this.submit = this.submit.bind(this);
this.remove = this.remove.bind(this);
this.render = this.render.bind(this);
this.update();
}
}
export default App;
16 changes: 16 additions & 0 deletions build/NumTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "./_snowpack/pkg/react.js";
class NumTable extends React.Component {
render() {
const rows = [];
if (this.props.data != void 0)
this.props.data.map((element, index) => {
rows.push(/* @__PURE__ */ React.createElement("tr", {
onClick: () => this.props.remove(index)
}, /* @__PURE__ */ React.createElement("td", null, element)));
}, this);
return /* @__PURE__ */ React.createElement("table", {
class: "num-table"
}, " ", rows, " ");
}
}
export default NumTable;
87 changes: 87 additions & 0 deletions build/_snowpack/pkg/common/index-ef047052.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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');
}

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var l=Symbol.for("react.element"),n=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),t=Symbol.for("react.provider"),u=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),z=Symbol.iterator;function A(a){if(null===a||"object"!==typeof a)return null;a=z&&a[z]||a["@@iterator"];return "function"===typeof a?a:null}
var B={isMounted:function(){return !1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},C=Object.assign,D={};function E(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}E.prototype.isReactComponent={};
E.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,a,b,"setState");};E.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate");};function F(){}F.prototype=E.prototype;function G(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}var H=G.prototype=new F;
H.constructor=G;C(H,E.prototype);H.isPureReactComponent=!0;var I=Array.isArray,J=Object.prototype.hasOwnProperty,K={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};
function M(a,b,e){var d,c={},k=null,h=null;if(null!=b)for(d in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(k=""+b.key),b)J.call(b,d)&&!L.hasOwnProperty(d)&&(c[d]=b[d]);var g=arguments.length-2;if(1===g)c.children=e;else if(1<g){for(var f=Array(g),m=0;m<g;m++)f[m]=arguments[m+2];c.children=f;}if(a&&a.defaultProps)for(d in g=a.defaultProps,g)void 0===c[d]&&(c[d]=g[d]);return {$$typeof:l,type:a,key:k,ref:h,props:c,_owner:K.current}}
function N(a,b){return {$$typeof:l,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function O(a){return "object"===typeof a&&null!==a&&a.$$typeof===l}function escape(a){var b={"=":"=0",":":"=2"};return "$"+a.replace(/[=:]/g,function(a){return b[a]})}var P=/\/+/g;function Q(a,b){return "object"===typeof a&&null!==a&&null!=a.key?escape(""+a.key):b.toString(36)}
function R(a,b,e,d,c){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 l:case n:h=!0;}}if(h)return h=a,c=c(h),a=""===d?"."+Q(h,0):d,I(c)?(e="",null!=a&&(e=a.replace(P,"$&/")+"/"),R(c,b,e,"",function(a){return a})):null!=c&&(O(c)&&(c=N(c,e+(!c.key||h&&h.key===c.key?"":(""+c.key).replace(P,"$&/")+"/")+a)),b.push(c)),1;h=0;d=""===d?".":d+":";if(I(a))for(var g=0;g<a.length;g++){k=
a[g];var f=d+Q(k,g);h+=R(k,b,e,f,c);}else if(f=A(a),"function"===typeof f)for(a=f.call(a),g=0;!(k=a.next()).done;)k=k.value,f=d+Q(k,g++),h+=R(k,b,e,f,c);else if("object"===k)throw b=String(a),Error("Objects are not valid as a React child (found: "+("[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b)+"). If you meant to render a collection of children, use an array instead.");return h}
function S(a,b,e){if(null==a)return a;var d=[],c=0;R(a,d,"","",function(a){return b.call(e,a,c++)});return d}function T(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b;},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b;});-1===a._status&&(a._status=0,a._result=b);}if(1===a._status)return a._result.default;throw a._result;}
var U={current:null},V={transition:null},W={ReactCurrentDispatcher:U,ReactCurrentBatchConfig:V,ReactCurrentOwner:K};var Children={map:S,forEach:function(a,b,e){S(a,function(){b.apply(this,arguments);},e);},count:function(a){var b=0;S(a,function(){b++;});return b},toArray:function(a){return S(a,function(a){return a})||[]},only:function(a){if(!O(a))throw Error("React.Children.only expected to receive a single React element child.");return a}};var Component=E;var Fragment=p;
var Profiler=r;var PureComponent=G;var StrictMode=q;var Suspense=w;var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=W;
var cloneElement=function(a,b,e){if(null===a||void 0===a)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+a+".");var d=C({},a.props),c=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=K.current);void 0!==b.key&&(c=""+b.key);if(a.type&&a.type.defaultProps)var g=a.type.defaultProps;for(f in b)J.call(b,f)&&!L.hasOwnProperty(f)&&(d[f]=void 0===b[f]&&void 0!==g?g[f]:b[f]);}var f=arguments.length-2;if(1===f)d.children=e;else if(1<f){g=Array(f);
for(var m=0;m<f;m++)g[m]=arguments[m+2];d.children=g;}return {$$typeof:l,type:a.type,key:c,ref:k,props:d,_owner:h}};var createContext=function(a){a={$$typeof:u,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:t,_context:a};return a.Consumer=a};var createElement=M;var createFactory=function(a){var b=M.bind(null,a);b.type=a;return b};var createRef=function(){return {current:null}};
var forwardRef=function(a){return {$$typeof:v,render:a}};var isValidElement=O;var lazy=function(a){return {$$typeof:y,_payload:{_status:-1,_result:a},_init:T}};var memo=function(a,b){return {$$typeof:x,type:a,compare:void 0===b?null:b}};var startTransition=function(a){var b=V.transition;V.transition={};try{a();}finally{V.transition=b;}};var unstable_act=function(){throw Error("act(...) is not supported in production builds of React.");};
var useCallback=function(a,b){return U.current.useCallback(a,b)};var useContext=function(a){return U.current.useContext(a)};var useDebugValue=function(){};var useDeferredValue=function(a){return U.current.useDeferredValue(a)};var useEffect=function(a,b){return U.current.useEffect(a,b)};var useId=function(){return U.current.useId()};var useImperativeHandle=function(a,b,e){return U.current.useImperativeHandle(a,b,e)};
var useInsertionEffect=function(a,b){return U.current.useInsertionEffect(a,b)};var useLayoutEffect=function(a,b){return U.current.useLayoutEffect(a,b)};var useMemo=function(a,b){return U.current.useMemo(a,b)};var useReducer=function(a,b,e){return U.current.useReducer(a,b,e)};var useRef=function(a){return U.current.useRef(a)};var useState=function(a){return U.current.useState(a)};var useSyncExternalStore=function(a,b,e){return U.current.useSyncExternalStore(a,b,e)};
var useTransition=function(){return U.current.useTransition()};var version="18.2.0";

var react_production_min = {
Children: Children,
Component: Component,
Fragment: Fragment,
Profiler: Profiler,
PureComponent: PureComponent,
StrictMode: StrictMode,
Suspense: Suspense,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
cloneElement: cloneElement,
createContext: createContext,
createElement: createElement,
createFactory: createFactory,
createRef: createRef,
forwardRef: forwardRef,
isValidElement: isValidElement,
lazy: lazy,
memo: memo,
startTransition: startTransition,
unstable_act: unstable_act,
useCallback: useCallback,
useContext: useContext,
useDebugValue: useDebugValue,
useDeferredValue: useDeferredValue,
useEffect: useEffect,
useId: useId,
useImperativeHandle: useImperativeHandle,
useInsertionEffect: useInsertionEffect,
useLayoutEffect: useLayoutEffect,
useMemo: useMemo,
useReducer: useReducer,
useRef: useRef,
useState: useState,
useSyncExternalStore: useSyncExternalStore,
useTransition: useTransition,
version: version
};

var react = createCommonjsModule(function (module) {

{
module.exports = react_production_min;
}
});

export { createCommonjsModule as c, 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