final working state for NP tracker

This commit is contained in:
Nico Melone
2022-11-28 17:02:24 -06:00
parent 836c6ba29b
commit 918abeaa2e
35 changed files with 137 additions and 35 deletions

View File

@@ -1,33 +1,41 @@
const express = require("express");
const app = express();
const fs = require("fs");
const cors = require('cors');
const cors = require("cors");
//use cors to allow cross origin resource sharing
app.use(
cors({
origin: 'http://localhost:3000',
credentials: true,
})
);
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.urlencoded({ extended: false }));
app.get("/", (req, res) => {
res.send("Hello World!");
app.get("/", (req,res) => {
res.send("Hello World");
});
app.get("/userData", (req, res) => {
console.log(req.query);
user = req.query.user;
let rawdata = fs.readFileSync(`${user}.json`);
let userData = JSON.parse(rawdata);
res.send(JSON.stringify(userData));
});
app.post("/saveUserFile", (req, res) => {
//console.log("Connected to React");
//console.log(req.body);
req.body.visitedParks.sort();
let data = JSON.stringify(req.body);
fs.writeFileSync('../frontend/src/nico.json', data);
res.redirect("/");
});
//console.log("Connected to React");
//console.log(req.body);
req.body.visitedParks.sort();
let data = JSON.stringify(req.body);
fs.writeFileSync("./nico.json", data);
res.redirect("/");
});
const PORT = process.env.PORT || 8080;
const PORT = process.env.PORT || 5321;
app.listen(PORT, console.log(`Server started on port ${PORT}`));

1
backend/nico.json Normal file
View File

@@ -0,0 +1 @@
{"visitedParks":["Acadia","Arches","Big Bend","Carlsbad Caverns *","Crater Lake","Grand Teton","Guadalupe Mountains","Hot Springs","Redwood *","Yellowstone","Yosemite *","Zion"]}

View File

@@ -0,0 +1,15 @@
{
"files": {
"main.css": "/static/css/main.1bcf62e1.css",
"main.js": "/static/js/main.c084716e.js",
"static/js/787.6c417ab9.chunk.js": "/static/js/787.6c417ab9.chunk.js",
"index.html": "/index.html",
"main.1bcf62e1.css.map": "/static/css/main.1bcf62e1.css.map",
"main.c084716e.js.map": "/static/js/main.c084716e.js.map",
"787.6c417ab9.chunk.js.map": "/static/js/787.6c417ab9.chunk.js.map"
},
"entrypoints": [
"static/css/main.1bcf62e1.css",
"static/js/main.c084716e.js"
]
}

BIN
frontend/build/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.c084716e.js"></script><link href="/static/css/main.1bcf62e1.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

BIN
frontend/build/logo192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
frontend/build/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@@ -0,0 +1,2 @@
body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;margin:0}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.no{background-color:red}.yes{background-color:green}table,td,th{border:1px solid}table{border:1px solid;border-collapse:collapse;padding:1rem}tr:hover{background-color:#d3d3d3}.container{display:flex;flex-direction:row}.column{padding:.75rem}
/*# sourceMappingURL=main.1bcf62e1.css.map*/

View File

@@ -0,0 +1 @@
{"version":3,"file":"static/css/main.1bcf62e1.css","mappings":"AAAA,KAKE,kCAAmC,CACnC,iCAAkC,CAJlC,mIAEY,CAHZ,QAMF,CAEA,KACE,uEAEF,CCZA,IACI,oBACF,CAEA,KACE,sBACF,CAEA,YACE,gBACF,CAEA,MAEE,gBAAiB,CADjB,wBAAyB,CAEzB,YACF,CAEA,SAAU,wBAA4B,CAExC,WACI,YAAa,CACb,kBACJ,CAEA,QACI,cACJ","sources":["index.css","NP.css"],"sourcesContent":["body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n",".no{\n background-color: red;\n }\n \n .yes{\n background-color: green;\n }\n \n table, td, th {\n border: 1px solid;\n }\n \n table{\n border-collapse: collapse;\n border: 1px solid;\n padding: 1rem;\n }\n \n tr:hover {background-color: lightgray;}\n\n.container{\n display: flex;\n flex-direction: row;\n}\n\n.column{\n padding: 0.75rem;\n}"],"names":[],"sourceRoot":""}

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkpersonal_stat_tracker=self.webpackChunkpersonal_stat_tracker||[]).push([[787],{8:function(e,t,n){n.r(t),n.d(t,{getCLS:function(){return y},getFCP:function(){return g},getFID:function(){return F},getLCP:function(){return P},getTTFB:function(){return D}});var i,r,a,o,u=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},f=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},s=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},m=function(e,t,n){var i;return function(r){t.value>=0&&(r||n)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},v=-1,p=function(){return"hidden"===document.visibilityState?0:1/0},d=function(){f((function(e){var t=e.timeStamp;v=t}),!0)},l=function(){return v<0&&(v=p(),d(),s((function(){setTimeout((function(){v=p(),d()}),0)}))),{get firstHiddenTime(){return v}}},g=function(e,t){var n,i=l(),r=u("FCP"),a=function(e){"first-contentful-paint"===e.name&&(f&&f.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),n(!0)))},o=window.performance&&performance.getEntriesByName&&performance.getEntriesByName("first-contentful-paint")[0],f=o?null:c("paint",a);(o||f)&&(n=m(e,r,t),o&&a(o),s((function(i){r=u("FCP"),n=m(e,r,t),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,n(!0)}))}))})))},h=!1,T=-1,y=function(e,t){h||(g((function(e){T=e.value})),h=!0);var n,i=function(t){T>-1&&e(t)},r=u("CLS",0),a=0,o=[],v=function(e){if(!e.hadRecentInput){var t=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-t.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,n())}},p=c("layout-shift",v);p&&(n=m(i,r,t),f((function(){p.takeRecords().map(v),n(!0)})),s((function(){a=0,T=-1,r=u("CLS",0),n=m(i,r,t)})))},E={passive:!0,capture:!0},w=new Date,L=function(e,t){i||(i=t,r=e,a=new Date,k(removeEventListener),S())},S=function(){if(r>=0&&r<a-w){var e={entryType:"first-input",name:i.type,target:i.target,cancelable:i.cancelable,startTime:i.timeStamp,processingStart:i.timeStamp+r};o.forEach((function(t){t(e)})),o=[]}},b=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){L(e,t),r()},i=function(){r()},r=function(){removeEventListener("pointerup",n,E),removeEventListener("pointercancel",i,E)};addEventListener("pointerup",n,E),addEventListener("pointercancel",i,E)}(t,e):L(t,e)}},k=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,b,E)}))},F=function(e,t){var n,a=l(),v=u("FID"),p=function(e){e.startTime<a.firstHiddenTime&&(v.value=e.processingStart-e.startTime,v.entries.push(e),n(!0))},d=c("first-input",p);n=m(e,v,t),d&&f((function(){d.takeRecords().map(p),d.disconnect()}),!0),d&&s((function(){var a;v=u("FID"),n=m(e,v,t),o=[],r=-1,i=null,k(addEventListener),a=p,o.push(a),S()}))},C={},P=function(e,t){var n,i=l(),r=u("LCP"),a=function(e){var t=e.startTime;t<i.firstHiddenTime&&(r.value=t,r.entries.push(e),n())},o=c("largest-contentful-paint",a);if(o){n=m(e,r,t);var v=function(){C[r.id]||(o.takeRecords().map(a),o.disconnect(),C[r.id]=!0,n(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),f(v,!0),s((function(i){r=u("LCP"),n=m(e,r,t),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,C[r.id]=!0,n(!0)}))}))}))}},D=function(e){var t,n=u("TTFB");t=function(){try{var t=performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,t={entryType:"navigation",startTime:0};for(var n in e)"navigationStart"!==n&&"toJSON"!==n&&(t[n]=Math.max(e[n]-e.navigationStart,0));return t}();if(n.value=n.delta=t.responseStart,n.value<0||n.value>performance.now())return;n.entries=[t],e(n)}catch(e){}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)}))}}}]);
//# sourceMappingURL=787.6c417ab9.chunk.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,39 @@
/**
* @license React
* react-dom.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.
*/
/**
* @license React
* react-jsx-runtime.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.
*/
/**
* @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.
*/
/**
* @license React
* scheduler.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.
*/

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
[{"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/index.js":"1","/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/NP.js":"2","/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/reportWebVitals.js":"3"},{"size":564,"mtime":1668458963497,"results":"4","hashOfConfig":"5"},{"size":2864,"mtime":1669243558916,"results":"6","hashOfConfig":"5"},{"size":362,"mtime":1668113575395,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","suppressedMessages":"10","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"11"},"1mrwxdh",{"filePath":"12","messages":"13","suppressedMessages":"14","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"15","messages":"16","suppressedMessages":"17","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"11"},"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/index.js",[],[],[],"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/NP.js",[],[],"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/reportWebVitals.js",[],[]]
[{"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/index.js":"1","/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/NP.js":"2","/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/reportWebVitals.js":"3"},{"size":564,"mtime":1669653396527,"results":"4","hashOfConfig":"5"},{"size":3196,"mtime":1669657167390,"results":"6","hashOfConfig":"5"},{"size":362,"mtime":1668113575395,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","suppressedMessages":"10","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1mrwxdh",{"filePath":"11","messages":"12","suppressedMessages":"13","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"14","messages":"15","suppressedMessages":"16","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"17"},"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/index.js",[],[],"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/NP.js",[],[],"/Users/nico/Documents/GitHub/personal-stat-tracker/frontend/src/reportWebVitals.js",[],[],[]]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,16 +2,12 @@
"name": "personal-stat-tracker",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8080",
"proxy": "http://llamapi.local:5321",
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.2.0",
"express": "^4.18.2",
"fs": "^0.0.1-security",
"fs-extra": "^10.1.0",
"nodemon": "^2.0.20",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
@@ -42,6 +38,5 @@
]
},
"devDependencies": {
"@types/fs-extra": "^9.0.13"
}
}

View File

@@ -1,33 +1,38 @@
import React from "react";
import "./NP.css";
import np from "./national_parks.json";
import user from "./nico.json";
//import user from "./nico.json";//TODO: move this to server-side
import axios from 'axios';
class NP extends React.Component {
constructor(props) {
super(props);
this.nptemplate = np;
this.userVisited = user;
this.state = { step: 0 };
//this.userVisited = {userVisited : {visitedParks: []}};//user; //TODO: get this from server
this.state = { visitedParks: [] };
}
componentDidMount(){
axios.get('http://llamapi.local:5321/userData', {params: {"user":"nico"}}).then( (json) => {console.log(json);this.setState({visitedParks : json.data.visitedParks})}).catch((err) => {console.log(err)});
}
handleVisitedClick(i, ind) {
let temp = this.state.visitedParks;
if (i === "no") {
i = "yes";
this.nptemplate[ind].visited = "yes";
this.userVisited.visitedParks.push(this.nptemplate[ind].name);
temp.push(this.nptemplate[ind].name);
//console.log(this.nptemplate);
} else {
i = "no";
this.nptemplate[ind].visited = "no";
const removeInd = this.userVisited.visitedParks.indexOf(this.nptemplate[ind].name);
const removeInd = temp.indexOf(this.nptemplate[ind].name);
if (removeInd > -1) {
this.userVisited.visitedParks.splice(removeInd, 1);
temp.splice(removeInd, 1);
}
//console.log(this.nptemplate);
}
axios.post('http://localhost:8080/saveUserFile', this.userVisited).then(() => console.log('Updated user data')).catch(err => { console.error(err);});
this.setState({ step: 1 });
axios.post('http://llamapi.local:5321/saveUserFile', {visitedParks:temp}).then(() => console.log('Updated user data')).catch(err => { console.error(err);});
this.setState({ visitedParks: temp });
}
toLimitedDecimals(val, places = -1) {
@@ -42,7 +47,7 @@ class NP extends React.Component {
return (
<tr key={index}>
<td>{park.name}</td>
<Visited park={park} ind={index} nptemplate={this.nptemplate} user={this.userVisited} onClick={(i) => this.handleVisitedClick(park.visited, index)} />
<Visited park={park} ind={index} nptemplate={this.nptemplate} user={this.state.visitedParks} onClick={(i) => this.handleVisitedClick(park.visited, index)} />
</tr>
);
});
@@ -50,7 +55,7 @@ class NP extends React.Component {
let numVisited = 0;
let percentVisted = (numVisited / totalParks) * 100;
this.nptemplate.forEach((park) => {
if (this.userVisited.visitedParks.includes(park.name)) {
if (this.state.visitedParks.includes(park.name)) {
park.visited = "yes";
}
if (park.visited === "yes") {

View File

@@ -1 +1 @@
{"visitedParks":["Acadia","Arches","Big Bend","Carlsbad Caverns *","Crater Lake","Grand Teton","Guadalupe Mountains","Hot Springs","Redwood *","Yellowstone","Yosemite *","Zion"]}
{"visitedParks":["Acadia","Arches","Big Bend","Black Canyon of the Gunnison","Carlsbad Caverns *","Crater Lake","Grand Teton","Guadalupe Mountains","Hot Springs","Redwood *","Yellowstone","Yosemite *","Zion"]}