From 851d4646440b463a6bb72f856876b684bb37e8a0 Mon Sep 17 00:00:00 2001 From: jrwecler Date: Wed, 5 Oct 2022 20:48:52 -0400 Subject: [PATCH 1/5] initial --- server.improved.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server.improved.js b/server.improved.js index 26673fc..6903872 100644 --- a/server.improved.js +++ b/server.improved.js @@ -7,10 +7,17 @@ const http = require( 'http' ), port = 3000 const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} -] + {Name: "Jordan Wecler", + Pronouns: "He/Him", + Age: "19 years old", + Email: "name@gmail.com", + Phone: "123-456-7890", + Education: "WPI Class of 2024", + Major: "Computer Science Major", + Like: "Likes Photography", + Primary: "#0C376E", + Secondary: "#BFCDE0"}, +]; const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { From 07510c880d401caf33e15cbb76cc860a5235d422 Mon Sep 17 00:00:00 2001 From: jrwecler Date: Wed, 5 Oct 2022 20:49:27 -0400 Subject: [PATCH 2/5] initial --- package.json | 6 +- public/css/style.css | 156 +++++++++++++++++++++++++- public/index.html | 261 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 394 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 988f135..6061ac9 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "", - "version": "", + "name": "a2-jrwecler", + "version": "1.0", "description": "", - "author": "", + "author": "Jordan Wecler", "scripts": { "start": "node server.improved.js" }, diff --git a/public/css/style.css b/public/css/style.css index d5f842a..ddfc1bf 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1 +1,155 @@ -/*Style your own assignment! This is fun! */ \ No newline at end of file +@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@500&family=Libre+Franklin:wght@400;500;600;700;800&display=swap'); + +body { + background-color: #0C376E; +} + +h1 { + font-family: 'Barlow Condensed', sans-serif; + color: #FEFCFD; + font-size: 4.5em; + text-align: left; + margin-top: 2%; + margin-bottom: 0%; +} + +h2 { + font-family: 'Libre Franklin', sans-serif; + font-weight: 700; + color: #BFCDE0; + font-size: 1.26em; + text-align: left; + margin-top: 0%; + margin-bottom: 20px; +} + +h3 { + font-family: 'Libre Franklin', sans-serif; + font-weight: 700; + color: #0C376E; + font-size: 1.2em; + text-align: left; + + display: inline-block; + border: #BFCDE0 solid 1px; + border-top-left-radius: 10px; + border-top-right-radius: 10px; + background-color: #BFCDE0; + margin-bottom: 0px; + padding: 5px 10px 0px 10px; +} + +.prev { + font-family: 'Libre Franklin', sans-serif; + font-weight: 500; + color: #0C376E; + font-size: 1em; + text-align: left; + + margin-bottom: 5px; + padding: 1em; + background-color: #BFCDE0; + width: 300px; + height: 175px; + border: #BFCDE0 solid 0px; + border-radius: 0 10px 10px 10px; + + display: flex; + justify-content: flex-start; + align-content: flex-start; + flex-flow: row wrap; +} + +.icon { + width: 40px; + height: 40px; + border: #0C376E solid 10px; + border-radius: 10px; + margin: 0px; + padding: 0px; +} + +.head { + margin: 5px 5px 5px 12px; + height: 16px; + width: 16px; + background-color: #0C376E; + border-radius: 50%; +} + +.basicInfo { + height: 60px; + width: 220px; + + display: flex; + flex-flow: column wrap; + align-content: space-between; + justify-content: space-evenly; + margin-left: 10px; +} + +.prev p { + margin: 0px; + padding: 0px; +} + +.body { + margin: 0px 5px 5px 8px; + height: 24px; + width: 24px; + background-color: #0C376E; + border-radius: 25%; +} + +.aboutInfo { + height: 100px; + padding-top: 10px; + padding-left: 70px; + + display: flex; + flex-flow: column; + justify-content: space-between; +} + +.topText { + font-weight: 700; +} + +.createProf { + font-family: 'Libre Franklin', sans-serif; + font-weight: 500; + color: #0C376E; + font-size: 1em; + text-align: left; + + margin-bottom: 5px; + padding: 1em; + background-color: #BFCDE0; + width: 300px; + height: 350px; + border: #BFCDE0 solid 0px; + border-radius: 0 10px 10px 10px; + + display: flex; + justify-content: space-between; + align-content: space-between; + flex-flow: row wrap; +} + +.profInput { + width: 100%; + display: flex; + justify-content: space-between; + align-items: center; +} + +.profInputButton { + width: 100%; + display: flex; + justify-content: space-evenly; + padding-top: 5px; +} + +/* @media (min-width: 1200px) { + +} */ \ No newline at end of file diff --git a/public/index.html b/public/index.html index c56d620..c358a6e 100644 --- a/public/index.html +++ b/public/index.html @@ -1,41 +1,252 @@ - CS4241 Assignment 2 + Flex Book - CS4241 Assignment 2 + -
- - -
+

FlexBook

+

CS4241 Assignment #2

+

Preview

+ +

Create Profile

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+
From d6d26f68c4270773167e542ed272d4dc8ee69e66 Mon Sep 17 00:00:00 2001 From: jrwecler Date: Mon, 10 Oct 2022 12:18:54 -0400 Subject: [PATCH 3/5] Server code --- public/index.html | 156 ++----------------------------------------- public/js/scripts.js | 144 ++++++++++++++++++++++++++++++++++++++- server.improved.js | 120 +++++++++++++++++++++++++++++---- 3 files changed, 257 insertions(+), 163 deletions(-) diff --git a/public/index.html b/public/index.html index c358a6e..6013b35 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@

FlexBook

CS4241 Assignment #2

Preview

- - diff --git a/public/js/scripts.js b/public/js/scripts.js index de052ea..f15be0a 100644 --- a/public/js/scripts.js +++ b/public/js/scripts.js @@ -1,3 +1,145 @@ // Add some Javascript code here, to run on the front end. -console.log("Welcome to assignment 2!") \ No newline at end of file +refreshPreview(); +const preview = function(e) { + // prevent default form action from being carried out + e.preventDefault() + + const name = document.querySelector( '#name' ), + pronouns = document.querySelector( '#pronouns' ), + birthday = document.querySelector( '#birthday' ), + email = document.querySelector( '#email' ), + phone = document.querySelector( '#phone' ), + hometown = document.querySelector( '#hometown' ), + education = document.querySelector( '#education' ), + job = document.querySelector( '#job' ), + likes = document.querySelector( '#likes' ), + primary = document.querySelector( '#primary' ), + secondary = document.querySelector( '#secondary' ); + let json = { + Name: name.value, + Pronouns: pronouns.value, + Birthday: birthday.value, + Age: 0, + Email: email.value, + Phone: phone.value, + Hometown: hometown.value, + Education: education.value, + Job: job.value, + Likes: likes.value, + Primary: primary.value, + Secondary: secondary.value, + }, + body = JSON.stringify(json); + + if ( + name.value == "" || + pronouns.value == "" || + email.value == "" || + phone.value == "" || + hometown.value == "" || + education.value == "" || + job.value == "" || + likes.value == "" || + primary.value == "" || + secondary.value == "" + ) { + alert("Please fill out all fields"); + fetch( '/preview', { + method:'POST', + body, + }) + .then( async function ( response ) { + let newPreview = await response.json() + refreshPreview(newPreview) + console.log( response ) + }); + } + + return false +}; + +// const submit = function(e) { +// // prevent default form action from being carried out +// e.preventDefault() + +// const name = document.querySelector( '#name' ), +// pronouns = document.querySelector( '#pronouns' ), +// birthday = document.querySelector( '#birthday' ), +// email = document.querySelector( '#email' ), +// phone = document.querySelector( '#phone' ), +// hometown = document.querySelector( '#hometown' ), +// education = document.querySelector( '#education' ), +// job = document.querySelector( '#job' ), +// likes = document.querySelector( '#likes' ), +// primary = document.querySelector( '#primary' ), +// secondary = document.querySelector( '#secondary' ); +// let json = { +// Name: name.value, +// Pronouns: pronouns.value, +// Birthday: birthday.value, +// Email: email.value, +// Phone: phone.value, +// Hometown: hometown.value, +// Education: education.value, +// Job: job.value, +// Likes: likes.value, +// Primary: primary.value, +// Secondary: secondary.value, +// Age: 0, +// }, +// body = JSON.stringify(json); + +// if ( +// name.value == "" || +// pronouns.value == "" || +// email.value == "" || +// phone.value == "" || +// hometown.value == "" || +// education.value == "" || +// job.value == "" || +// likes.value == "" || +// primary.value == "" || +// secondary.value == "" +// ) { +// alert("Please fill out all fields"); +// fetch( '/submit', { +// method:'POST', +// body, +// }) +// .then(function(response ) { +// // DO something with the reponse +// console.log( response ) +// }); +// } + +// return false +// }; + +window.onload = function() { + const pButton = document.querySelector("previewButton") + const sButton = document.querySelector("submitButton") + const cButton = document.querySelector("clearButton") + pbutton.onclick = preview; + //sbutton.onclick = submit; + //cbutton.onclick = clear; +} + +function refreshPreview(newPreview) { + const preview = document.getElementsByClassName("prev"); + preview.innerHTML = '
'; + + newPreview.forEach((element, index) => { + preview.innerHTML += '

' + element.Name + + '

' + element.Pronouns + + '

' + element.Age + + '

Contact:

' + + element.Phone + '

' + element.Email + + '

About:

' + + element.Hometown + + '

' + element.Education + + '

' + element.Job + + '

' + element.Likes + '

'; + }) + preview.innerHTML += '
'; +} \ No newline at end of file diff --git a/server.improved.js b/server.improved.js index 6903872..565b806 100644 --- a/server.improved.js +++ b/server.improved.js @@ -7,16 +7,17 @@ const http = require( 'http' ), port = 3000 const appdata = [ - {Name: "Jordan Wecler", - Pronouns: "He/Him", - Age: "19 years old", - Email: "name@gmail.com", - Phone: "123-456-7890", - Education: "WPI Class of 2024", - Major: "Computer Science Major", - Like: "Likes Photography", - Primary: "#0C376E", - Secondary: "#BFCDE0"}, + {Name: "", + Pronouns: "", + Age: "", + Email: "", + Phone: "", + Hometown: "", + Education: "", + Job: "", + Like: "", + Primary: "", + Secondary: ""}, ]; const server = http.createServer( function( request,response ) { @@ -46,10 +47,31 @@ const handlePost = function( request, response ) { request.on( 'end', function() { console.log( JSON.parse( dataString ) ) - - // ... do something with the data here!!! - + let newEntry = JSON.parse( dataString ); + newEntry.Age = ageCalculator(newEntry.Birthday); + newEntry.Hometown += "From " + newEntry.Hometown; + newEntry.Job = "Works as a " + newEntry.Job; + newEntry.Like += "Likes " + newEntry.Like; + newEntry.Primary = primaryColorizer(newEntry.Primary); + newEntry.Secondary = secondaryColorizer(newEntry.Secondary); + if(request.url === "/preview") { + appdata.splice(0, 1, newEntry); + } else { + let newEmail = true; + for (let i = 0; i < appdata.length; i++) { + if (appdata[i].Email === newEntry.Email) { + appdata.splice(i, 1, newEntry); + newEmail = false; + break; + } + } + if (newEmail) { + appdata.push(newEntry); + } + } response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) + response.write( JSON.stringify( appdata ) ) + console.log(appdata) response.end() }) } @@ -77,3 +99,75 @@ const sendFile = function( response, filename ) { } server.listen( process.env.PORT || port ) + +function ageCalculator(bday) { + let today = new Date(); + let dd = String(today.getDate()).padStart(2, '0'); + let mm = String(today.getMonth() + 1).padStart(2, '0'); + let yyyy = today.getFullYear(); + + let bdayDD = bday.substring(8,10); + let bdayMM = bday.substring(5,7); + let bdayYYYY = bday.substring(0,4); + + let age = yyyy - bdayYYYY; + if(bdayMM > mm || (bdayMM == mm && bdayDD > dd)) { + age--; + } + + if(age < 0) { + return "Born sometime in the future?"; + } + + age = age + " years old"; + + return age; +} + +function primaryColorizer(prim) { + let color = ""; + if (prim.toLowerCase() === "red") { + color = "#6E0C0C"; + } else if (prim.toLowerCase() === "orange") { + color = "#6E300C"; //22 + } else if (prim.toLowerCase() === "yellow") { + color = "#6E570C"; //46 + } else if (prim.toLowerCase() === "green") { + color = "#0C6E0C"; //120 + } else if (prim.toLowerCase() === "cyan") { + color = "#0C6E6E"; //180 + } else if (prim.toLowerCase() === "blue") { + color = "#0C376E"; //214 + } else if (prim.toLowerCase() === "purple") { + color = "#330C6E"; //264 + } else if (prim.toLowerCase() === "black") { + color = "#000000"; + } else { + color = "#2B2B2B"; + } + return color; +} + +function secondaryColorizer(sec) { + let color = ""; + if (prim.toLowerCase() === "red") { + color = "#E0BFBF"; + } else if (prim.toLowerCase() === "orange") { + color = "#E0CBBF"; + } else if (prim.toLowerCase() === "yellow") { + color = "#E0D9BF"; + } else if (prim.toLowerCase() === "green") { + color = "#BFE0BF"; + } else if (prim.toLowerCase() === "cyan") { + color = "#BFE0E0"; + } else if (prim.toLowerCase() === "blue") { + color = "#BFCDE0"; + } else if (prim.toLowerCase() === "purple") { + color = "#CCBFE0"; + } else if (prim.toLowerCase() === "white") { + color = "#FFFFFF"; + } else { + color = "#CCCCCC"; + } + return color; +} From 0eebfbb8aaa8f7939f75990428f01eddd6d71098 Mon Sep 17 00:00:00 2001 From: jrwecler Date: Mon, 24 Oct 2022 00:54:50 -0400 Subject: [PATCH 4/5] Final --- README.md | 98 ++----------------------------- public/css/style.css | 6 +- public/index.html | 108 ++++++++++------------------------- public/js/scripts.js | 133 +++++++++++++++++++++++-------------------- 4 files changed, 106 insertions(+), 239 deletions(-) diff --git a/README.md b/README.md index f229958..3c6a5c5 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,8 @@ -Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js +Assignment 2 - FlexBook: === -Due: September 8th, by 11:59 AM. +FlexBook is a basic "social media" site where a profile can be created using the input fields by either previewing how the profile may look, or submitting it to the larger group of submitted profiles. -This assignment aims to introduce you to creating a prototype two-tiered web application. -Your application will include the use of HTML, CSS, JavaScript, and Node.js functionality, with active communication between the client and the server over the life of a user session. +The CSS positioning technique used was flexbox usage for the most part, however I ran into issues when trying to format the submitted profiles with varying length of inputs, which made the profile sizes inconsistent. -Baseline Requirements ---- - -There is a large range of application areas and possibilities that meet these baseline requirements. -Try to make your application do something useful! A todo list, storing / retrieving high scores for a very simple game... have a little fun with it. - -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete (complete at least two) data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset -- the `Derived field` for a new row of data must be computed based on fields already existing in the row. -For example, a `todo` dataset with `task`, `priority`, and `creation_date` may generate a new field `deadline` by looking at `creation_date` and `priority` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application -- A results page displaying all data currently available on the server. You will most likely use a `` tag for this, but `
    ` or `
      ` could also work and might be simpler to work with. Alternatively, you can create a single-page app (see Technical Acheivements) but this is not a requirement. -- All pages should [validate](https://validator.w3.org) -- If your app contains multple pages, they should all be accessible from the homepage (index.html) - -CSS: -- CSS styling of the primary visual elements in the application -- Various CSS Selector functionality must be demonstrated: - - Element selectors - - ID selectors - - Class selectors -- CSS positioning and styling of the primary visual elements in the application: - - Use of either a CSS grid or flexbox for layout - - Rules defining fonts for all text used; no default fonts! Be sure to use a web safe font or a font from a web service like [Google Fonts](http://fonts.google.com/) - -- CSS defined in a maintainable, readable form, in external stylesheets - -JavaScript: -- At minimum, a small amount of front-end JavaScript to get / fetch data from the server; a sample is provided in this repository. - -Node.js: -- An HTTP Server that delivers all necessary files and data for the application, and also creates the required `Derived Fields` in your data. -A starting point is provided in this repository. - -Deliverables ---- - -Do the following to complete this assignment and acheive a base grade of 85%: - -1. Fork the starting project code (make sure to fork the 2022 repo!). This repo contains some starter code that may be used or discarded as needed. -2. Implement your project with the above requirements. -3. Test your project to make sure that when someone goes to your main page, it displays correctly. -4. Deploy your project to Glitch, and fill in the appropriate fields in your package.json file. -5. Ensure that your project has the proper naming scheme `a2-yourGithubUsername` so we can find it. -6. Modify the README to the specifications below, and delete all of the instructions originally found in this README. -7. Create and submit a Pull Request to the original repo. Label the pull request as follows: a2-gitusername-firstname-lastname - -Acheivements ---- - -Below are suggested technical and design achievements. You can use these to help boost your grade up to an A and customize the assignment to your personal interests. These are recommended acheivements, but feel free to create/implement your own... just make sure you thoroughly describe what you did in your README and why it was challenging. ALL ACHIEVEMENTS MUST BE DESCRIBED IN YOUR README IN ORDER TO GET CREDIT FOR THEM. - -*Technical* -- (10 points) Create a single-page app that both provides a form for users to submit data and always shows the current state of the server-side data. To put it another way, when the user submits data, the server should respond sending back the updated data (including the derived field calculated on the server) and the client should then update its data display. - -*Design/UX* -- (5 points per person, with a max of 10 points) Test your user interface with other students in the class. Define a specific task for them to complete (ideally something short that takes <10 minutes), and then use the [think-aloud protocol](https://en.wikipedia.org/wiki/Think_aloud_protocol) to obtain feedback on your design (talk-aloud is also find). Important considerations when designing your study: - -1. Make sure you start the study by clearly stating the task that you expect your user to accomplish. -2. You shouldn't provide any verbal instructions on how to use your interface / accomplish the task you give them. Make sure that your interface is clear enough that users can figure it out without any instruction, or provide text instructions from within the interface itself. -3. If users get stuck to the point where they give up, you can then provde instruction so that the study can continue, but make sure to discuss this in your README. You won't lose any points for this... all feedback is good feedback! - -You'll need to use sometype of collaborative software that will enable you both to see the test subject's screen and listen to their voice as they describe their thoughts. After completing each study, briefly (one to two sentences for each question) address the following in your README: - -1. Provide the last name of each student you conduct the evaluation with. -2. What problems did the user have with your design? -3. What comments did they make that surprised you? -4. What would you change about the interface based on their feedback? - -*You do not need to actually make changes based on their feedback*. This acheivement is designed to help gain experience testing user interfaces. If you run two user studies, you should answer two sets of questions. - -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 -Include a very brief summary of your project here. Be sure to include the CSS positioning technique you used, and any required instructions to use your application. - -## Technical Achievements -- **Tech Achievement 1**: Using a combination of... - -### Design/Evaluation Achievements -- **Design Achievement 1**: +The preview would be displayed seperately from the submitted profiles, and can be changed with new inputs just by clicking preview, whereas the submit button will make a new profile for each submission. To clear the input fields quickly, the clear button can be used. \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index ddfc1bf..0c68826 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -115,7 +115,7 @@ h3 { font-weight: 700; } -.createProf { +#createProfile { font-family: 'Libre Franklin', sans-serif; font-weight: 500; color: #0C376E; @@ -125,7 +125,7 @@ h3 { margin-bottom: 5px; padding: 1em; background-color: #BFCDE0; - width: 300px; + width: ; height: 350px; border: #BFCDE0 solid 0px; border-radius: 0 10px 10px 10px; @@ -136,7 +136,7 @@ h3 { flex-flow: row wrap; } -.profInput { +form { width: 100%; display: flex; justify-content: space-between; diff --git a/public/index.html b/public/index.html index 6013b35..2ad183f 100644 --- a/public/index.html +++ b/public/index.html @@ -8,84 +8,35 @@

      FlexBook

      CS4241 Assignment #2

      -

      Preview

      -

      Create Profile

      -
      -
      +
      +
      + + + +
      + + + +
      -
      -
      - + +
      + -
      -
      - + +
      + -
      -
      - - -
      -
      - - -
      -
      - - -
      -
      - - -
      -
      - - -
      -
      - - -
      -
      - - -
      -
      - - + +
      + + -
      +
      - - - + + +
      diff --git a/public/js/scripts.js b/public/js/scripts.js index f15be0a..3fb6590 100644 --- a/public/js/scripts.js +++ b/public/js/scripts.js @@ -1,34 +1,34 @@ // Add some Javascript code here, to run on the front end. refreshPreview(); -const preview = function(e) { +const preview = function (e) { // prevent default form action from being carried out - e.preventDefault() + e.preventDefault(); - const name = document.querySelector( '#name' ), - pronouns = document.querySelector( '#pronouns' ), - birthday = document.querySelector( '#birthday' ), - email = document.querySelector( '#email' ), - phone = document.querySelector( '#phone' ), - hometown = document.querySelector( '#hometown' ), - education = document.querySelector( '#education' ), - job = document.querySelector( '#job' ), - likes = document.querySelector( '#likes' ), - primary = document.querySelector( '#primary' ), - secondary = document.querySelector( '#secondary' ); - let json = { - Name: name.value, - Pronouns: pronouns.value, - Birthday: birthday.value, - Age: 0, - Email: email.value, - Phone: phone.value, - Hometown: hometown.value, - Education: education.value, - Job: job.value, - Likes: likes.value, - Primary: primary.value, - Secondary: secondary.value, + const name = document.querySelector("#name"), + pronouns = document.querySelector("#pronouns"), + birthday = document.querySelector("#birthday"), + email = document.querySelector("#email"), + phone = document.querySelector("#phone"), + hometown = document.querySelector("#hometown"), + education = document.querySelector("#education"), + job = document.querySelector("#job"), + likes = document.querySelector("#likes"), + primary = document.querySelector("#primary"), + secondary = document.querySelector("#secondary"); + let json = { + Name: name.value, + Pronouns: pronouns.value, + Birthday: birthday.value, + Age: 0, + Email: email.value, + Phone: phone.value, + Hometown: hometown.value, + Education: education.value, + Job: job.value, + Likes: likes.value, + Primary: primary.value, + Secondary: secondary.value, }, body = JSON.stringify(json); @@ -45,19 +45,18 @@ const preview = function(e) { secondary.value == "" ) { alert("Please fill out all fields"); - fetch( '/preview', { - method:'POST', - body, - }) - .then( async function ( response ) { - let newPreview = await response.json() - refreshPreview(newPreview) - console.log( response ) + fetch("/preview", { + method: "POST", + body, + }).then(async function (response) { + let newPreview = await response.json(); + refreshPreview(newPreview); + console.log(response); }); } - return false -}; + return false; +} // const submit = function(e) { // // prevent default form action from being carried out @@ -74,7 +73,7 @@ const preview = function(e) { // likes = document.querySelector( '#likes' ), // primary = document.querySelector( '#primary' ), // secondary = document.querySelector( '#secondary' ); -// let json = { +// let json = { // Name: name.value, // Pronouns: pronouns.value, // Birthday: birthday.value, @@ -105,10 +104,10 @@ const preview = function(e) { // alert("Please fill out all fields"); // fetch( '/submit', { // method:'POST', -// body, +// body, // }) // .then(function(response ) { -// // DO something with the reponse +// // DO something with the reponse // console.log( response ) // }); // } @@ -116,30 +115,38 @@ const preview = function(e) { // return false // }; -window.onload = function() { - const pButton = document.querySelector("previewButton") - const sButton = document.querySelector("submitButton") - const cButton = document.querySelector("clearButton") - pbutton.onclick = preview; +function refreshPreview(newPreview) { + const preview = document.getElementsByClassName("prev"); + preview.innerHTML = '
      '; + preview.innerHTML += + '

      ' + + newPreview[0].Age + + "

      " + + newPreview[0].Pronouns + + "

      " + + newPreview[0].Age + + '

      Contact:

      ' + + newPreview[0].Phone + + "

      " + + newPreview[0].Email + + '

      About:

      ' + + newPreview[0].Hometown + + "

      " + + newPreview[0].Education + + "

      " + + newPreview[0].Job + + "

      " + + newPreview[0].Likes + + "

      "; + preview.innerHTML += "
      "; +} + +window.onload = function () { + const pButton = document.getElementsById("previewButton"); + //const sButton = document.querySelector("submitButton"); + //const cButton = document.querySelector("clearButton"); + pButton.onclick = console.log("Hello"); + pButton.onclick = preview; //sbutton.onclick = submit; //cbutton.onclick = clear; } - -function refreshPreview(newPreview) { - const preview = document.getElementsByClassName("prev"); - preview.innerHTML = '
      '; - - newPreview.forEach((element, index) => { - preview.innerHTML += '

      ' + element.Name + - '

      ' + element.Pronouns + - '

      ' + element.Age + - '

      Contact:

      ' + - element.Phone + '

      ' + element.Email + - '

      About:

      ' + - element.Hometown + - '

      ' + element.Education + - '

      ' + element.Job + - '

      ' + element.Likes + '

      '; - }) - preview.innerHTML += '
      '; -} \ No newline at end of file From b382823cd8a12149961d142e505e34b05735a45b Mon Sep 17 00:00:00 2001 From: jrwecler Date: Mon, 24 Oct 2022 00:56:21 -0400 Subject: [PATCH 5/5] URL --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3c6a5c5..0d74ac2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Assignment 2 - FlexBook: === +https://a2-jrwecler.glitch.me/ + FlexBook is a basic "social media" site where a profile can be created using the input fields by either previewing how the profile may look, or submitting it to the larger group of submitted profiles. The CSS positioning technique used was flexbox usage for the most part, however I ran into issues when trying to format the submitted profiles with varying length of inputs, which made the profile sizes inconsistent.